af1ce0f1a50c1571a4a2841c9733ad32998445e6
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
;
16 private List
<SearchableTag
> children
;
19 * The number of stories result pages this tag can get.
21 * We keep more information than what the getter/setter returns/accepts.
23 * <li>-2: this tag does not support stories results (not a leaf tag)</li>
24 * <li>-1: the number is not yet known, but will be known after a
25 * {@link BasicSearchable#fillTag(SearchableTag)} operation</li>
26 * <li>X: the number of pages</li>
32 * Create a new {@link SearchableTag}.
34 * Note that tags are complete by default.
37 * the ID (usually a way to find the linked stories later on)
39 * the tag name, which can be displayed to the user
41 * the tag is a leaf tag, that is, it will not return subtags
42 * with {@link BasicSearchable#fillTag(SearchableTag)} but will
44 * {@link BasicSearchable#search(SearchableTag)}
46 public SearchableTag(String id
, String name
, boolean leaf
) {
47 this(id
, name
, leaf
, true);
51 * Create a new {@link SearchableTag}.
54 * the ID (usually a way to find the linked stories later on)
56 * the tag name, which can be displayed to the user
58 * the tag is a leaf tag, that is, it will not return subtags
59 * with {@link BasicSearchable#fillTag(SearchableTag)} but will
61 * {@link BasicSearchable#search(SearchableTag)}
63 * the tag {@link SearchableTag#isComplete()} or not
65 public SearchableTag(String id
, String name
, boolean leaf
, boolean complete
) {
68 this.complete
= complete
;
72 children
= new ArrayList
<SearchableTag
>();
76 * The ID (usually a way to find the linked stories later on).
80 public String
getId() {
85 * The tag name, which can be displayed to the user.
89 public String
getName() {
94 * Non-complete, non-leaf tags can still be completed via a
95 * {@link BasicSearchable#fillTag(SearchableTag)} operation from a
96 * {@link BasicSearchable}, in order to gain (more?) subtag children.
98 * This method does not make sense for leaf tags.
100 * @return TRUE if it is complete
102 public boolean isComplete() {
107 * Non-complete, non-leaf tags can still be completed via a
108 * {@link BasicSearchable#fillTag(SearchableTag)} operation from a
109 * {@link BasicSearchable}, in order to gain (more?) subtag children.
111 * This method does not make sense for leaf tags.
114 * TRUE if it is complete
116 public void setComplete(boolean complete
) {
117 this.complete
= complete
;
121 * The number of items that can be found with this tag if it is searched.
123 * Will report the number of subtags by default.
125 * @return the number of items
127 public long getCount() {
128 long count
= this.count
;
130 count
= children
.size();
137 * The number of items that can be found with this tag if it is searched,
138 * displayable format.
140 * Will report the number of subtags by default.
142 * @return the number of items
144 public String
getCountDisplay() {
145 long count
= this.count
;
147 count
= children
.size();
150 if (count
> 999999) {
151 return count
/ 1000000 + "M";
155 return count
/ 1000 + "k";
158 return Long
.toString(count
);
162 * The number of items that can be found with this tag if it is searched.
167 public void setCount(long count
) {
172 * The number of stories result pages this tag contains, only make sense if
173 * {@link SearchableTag#isLeaf()} returns TRUE.
175 * Will return -1 if the number is not yet known.
177 * @return the number of pages, or -1
179 public int getPages() {
180 return Math
.max(-1, pages
);
184 * The number of stories result pages this tag contains, only make sense if
185 * {@link SearchableTag#isLeaf()} returns TRUE.
188 * the (positive or 0) number of pages
190 public void setPages(int pages
) {
191 this.pages
= Math
.max(-1, pages
);
195 * This tag is a leaf tag, that is, it will not return other subtags with
196 * {@link BasicSearchable#fillTag(SearchableTag)} but will return stories
197 * with {@link BasicSearchable#search(SearchableTag)}.
199 * @return TRUE if it is
201 public boolean isLeaf() {
206 * This tag is a leaf tag, that is, it will not return other subtags with
207 * {@link BasicSearchable#fillTag(SearchableTag)} but will return stories
208 * with {@link BasicSearchable#search(SearchableTag)}.
210 * Will reset the number of pages to -1.
215 public void setLeaf(boolean leaf
) {
216 pages
= leaf ?
-1 : -2;
220 * The subtag children of this {@link SearchableTag}.
224 * Note that if {@link SearchableTag#isComplete()} returns false, you can
225 * still fill (more?) subtag children with a {@link BasicSearchable}.
227 * @return the subtag children, never NULL
229 public List
<SearchableTag
> getChildren() {
234 * Add the given {@link SearchableTag} as a subtag child.
239 public void add(SearchableTag tag
) {
244 * Display a DEBUG {@link String} representation of this object.
247 public String
toString() {
248 String rep
= name
+ " [" + id
+ "]";
253 if (getCount() > 0) {
254 rep
+= " (" + getCountDisplay() + ")";
257 if (!children
.isEmpty()) {
260 for (SearchableTag tag
: children
) {
261 if (!tags
.isEmpty()) {