3aa167f99e16e44ce8fd36d51362bfbf3269a029
1 package be
.nikiroo
.fanfix
.library
;
3 import java
.util
.ArrayList
;
4 import java
.util
.Collections
;
7 import be
.nikiroo
.fanfix
.data
.MetaData
;
9 public class MetaResultList
{
10 private List
<MetaData
> metas
;
13 // TODO: sync-protect them?
14 private List
<String
> sources
;
15 private List
<String
> authors
;
16 private List
<String
> tags
;
18 // can be null (will consider it empty)
19 public MetaResultList(List
<MetaData
> metas
) {
21 metas
= new ArrayList
<MetaData
>();
24 Collections
.sort(metas
);
30 public List
<MetaData
> getMetas() {
34 public List
<String
> getSources() {
35 if (sources
== null) {
36 sources
= new ArrayList
<String
>();
37 for (MetaData meta
: metas
) {
38 if (!sources
.contains(meta
.getSource()))
39 sources
.add(meta
.getSource());
46 // A -> (A), A/ -> (A, A/*) if we can find something for "*"
47 public List
<String
> getSources(String source
) {
48 List
<String
> linked
= new ArrayList
<String
>();
49 if (source
!= null && !source
.isEmpty()) {
50 if (!source
.endsWith("/")) {
53 linked
.add(source
.substring(0, source
.length() - 1));
54 for (String src
: getSources()) {
55 if (src
.startsWith(source
)) {
65 public List
<String
> getAuthors() {
66 if (authors
== null) {
67 authors
= new ArrayList
<String
>();
68 for (MetaData meta
: metas
) {
69 if (!authors
.contains(meta
.getAuthor()))
70 authors
.add(meta
.getAuthor());
77 public List
<String
> getTags() {
79 tags
= new ArrayList
<String
>();
80 for (MetaData meta
: metas
) {
81 for (String tag
: meta
.getTags()) {
82 if (!tags
.contains(tag
))
91 // null or empty -> no check, rest = must be included
92 // source: a source ending in "/" means "this or any source starting with this",
93 // i;e., to enable source hierarchy
95 public List
<MetaData
> filter(List
<String
> sources
, List
<String
> authors
, List
<String
> tags
) {
96 if (sources
!= null && sources
.isEmpty())
98 if (authors
!= null && authors
.isEmpty())
100 if (tags
!= null && tags
.isEmpty())
104 if (sources
== null && authors
== null && tags
== null) {
108 // allow "sources/" hierarchy
109 if (sources
!= null) {
110 List
<String
> folders
= new ArrayList
<String
>();
111 List
<String
> leaves
= new ArrayList
<String
>();
112 for (String source
: sources
) {
113 if (source
.endsWith("/")) {
114 if (!folders
.contains(source
))
117 if (!leaves
.contains(source
))
123 for (String folder
: folders
) {
124 for (String otherLeaf
: getSources(folder
)) {
125 if (!sources
.contains(otherLeaf
)) {
126 sources
.add(otherLeaf
);
132 List
<MetaData
> result
= new ArrayList
<MetaData
>();
133 for (MetaData meta
: metas
) {
134 if (sources
!= null && !sources
.contains(meta
.getSource())) {
137 if (authors
!= null && !authors
.contains(meta
.getAuthor())) {
142 boolean keep
= false;
143 for (String thisTag
: meta
.getTags()) {
144 if (tags
.contains(thisTag
))
155 Collections
.sort(result
);