1 package be
.nikiroo
.fanfix
.searchable
;
3 import java
.util
.ArrayList
;
7 * This class represents a tag that can be searched on a supported website.
11 public class SearchableTag
{
14 private boolean complete
;
17 private SearchableTag parent
;
18 private List
<SearchableTag
> children
;
21 * The number of stories result pages this tag can get.
23 * We keep more information than what the getter/setter returns/accepts.
25 * <li>-2: this tag does not support stories results (not a leaf tag)</li>
26 * <li>-1: the number is not yet known, but will be known after a
27 * {@link BasicSearchable#fillTag(SearchableTag)} operation</li>
28 * <li>X: the number of pages</li>
34 * Create a new {@link SearchableTag}.
36 * Note that tags are complete by default.
39 * the ID (usually a way to find the linked stories later on)
41 * the tag name, which can be displayed to the user
43 * the tag is a leaf tag, that is, it will not return subtags
44 * with {@link BasicSearchable#fillTag(SearchableTag)} but will
46 * {@link BasicSearchable#search(SearchableTag)}
48 public SearchableTag(String id
, String name
, boolean leaf
) {
49 this(id
, name
, leaf
, true);
53 * Create a new {@link SearchableTag}.
56 * the ID (usually a way to find the linked stories later on)
58 * the tag name, which can be displayed to the user
60 * the tag is a leaf tag, that is, it will not return subtags
61 * with {@link BasicSearchable#fillTag(SearchableTag)} but will
63 * {@link BasicSearchable#search(SearchableTag)}
65 * the tag {@link SearchableTag#isComplete()} or not
67 public SearchableTag(String id
, String name
, boolean leaf
, boolean complete
) {
70 this.complete
= complete
;
74 children
= new ArrayList
<SearchableTag
>();
78 * The ID (usually a way to find the linked stories later on).
82 public String
getId() {
87 * The tag name, which can be displayed to the user.
91 public String
getName() {
96 * Non-complete, non-leaf tags can still be completed via a
97 * {@link BasicSearchable#fillTag(SearchableTag)} operation from a
98 * {@link BasicSearchable}, in order to gain (more?) subtag children.
100 * This method does not make sense for leaf tags.
102 * @return TRUE if it is complete
104 public boolean isComplete() {
109 * Non-complete, non-leaf tags can still be completed via a
110 * {@link BasicSearchable#fillTag(SearchableTag)} operation from a
111 * {@link BasicSearchable}, in order to gain (more?) subtag children.
113 * This method does not make sense for leaf tags.
116 * TRUE if it is complete
118 public void setComplete(boolean complete
) {
119 this.complete
= complete
;
123 * The number of items that can be found with this tag if it is searched.
125 * Will report the number of subtags by default.
127 * @return the number of items
129 public long getCount() {
130 long count
= this.count
;
132 count
= children
.size();
139 * The number of items that can be found with this tag if it is searched.
144 public void setCount(long count
) {
149 * The number of stories result pages this tag contains, only make sense if
150 * {@link SearchableTag#isLeaf()} returns TRUE.
152 * Will return -1 if the number is not yet known.
154 * @return the number of pages, or -1
156 public int getPages() {
157 return Math
.max(-1, pages
);
161 * The number of stories result pages this tag contains, only make sense if
162 * {@link SearchableTag#isLeaf()} returns TRUE.
165 * the (positive or 0) number of pages
167 public void setPages(int pages
) {
168 this.pages
= Math
.max(-1, pages
);
172 * This tag is a leaf tag, that is, it will not return other subtags with
173 * {@link BasicSearchable#fillTag(SearchableTag)} but will return stories
174 * with {@link BasicSearchable#search(SearchableTag)}.
176 * @return TRUE if it is
178 public boolean isLeaf() {
183 * This tag is a leaf tag, that is, it will not return other subtags with
184 * {@link BasicSearchable#fillTag(SearchableTag)} but will return stories
185 * with {@link BasicSearchable#search(SearchableTag)}.
187 * Will reset the number of pages to -1.
192 public void setLeaf(boolean leaf
) {
193 pages
= leaf ?
-1 : -2;
197 * The subtag children of this {@link SearchableTag}.
201 * Note that if {@link SearchableTag#isComplete()} returns false, you can
202 * still fill (more?) subtag children with a {@link BasicSearchable}.
204 * @return the subtag children, never NULL
206 public List
<SearchableTag
> getChildren() {
211 * Add the given {@link SearchableTag} as a subtag child.
216 public void add(SearchableTag tag
) {
222 * This {@link SearchableTag} parent tag, or NULL if none.
224 * @return the parent or NULL
226 public SearchableTag
getParent() {
231 * Display a DEBUG {@link String} representation of this object.
234 public String
toString() {
235 String rep
= name
+ " [" + id
+ "]";
240 if (getCount() > 0) {
241 rep
+= " (" + getCount() + ")";
244 if (!children
.isEmpty()) {
247 for (SearchableTag tag
: children
) {
248 if (!tags
.isEmpty()) {