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,
140 * displayable format.
142 * Will report the number of subtags by default.
144 * @return the number of items
146 public String
getCountDisplay() {
147 long count
= this.count
;
149 count
= children
.size();
152 if (count
> 999999) {
153 return count
/ 1000000 + "M";
157 return count
/ 1000 + "k";
160 return Long
.toString(count
);
164 * The number of items that can be found with this tag if it is searched.
169 public void setCount(long count
) {
174 * The number of stories result pages this tag contains, only make sense if
175 * {@link SearchableTag#isLeaf()} returns TRUE.
177 * Will return -1 if the number is not yet known.
179 * @return the number of pages, or -1
181 public int getPages() {
182 return Math
.max(-1, pages
);
186 * The number of stories result pages this tag contains, only make sense if
187 * {@link SearchableTag#isLeaf()} returns TRUE.
190 * the (positive or 0) number of pages
192 public void setPages(int pages
) {
193 this.pages
= Math
.max(-1, pages
);
197 * This tag is a leaf tag, that is, it will not return other subtags with
198 * {@link BasicSearchable#fillTag(SearchableTag)} but will return stories
199 * with {@link BasicSearchable#search(SearchableTag)}.
201 * @return TRUE if it is
203 public boolean isLeaf() {
208 * This tag is a leaf tag, that is, it will not return other subtags with
209 * {@link BasicSearchable#fillTag(SearchableTag)} but will return stories
210 * with {@link BasicSearchable#search(SearchableTag)}.
212 * Will reset the number of pages to -1.
217 public void setLeaf(boolean leaf
) {
218 pages
= leaf ?
-1 : -2;
222 * The subtag children of this {@link SearchableTag}.
226 * Note that if {@link SearchableTag#isComplete()} returns false, you can
227 * still fill (more?) subtag children with a {@link BasicSearchable}.
229 * @return the subtag children, never NULL
231 public List
<SearchableTag
> getChildren() {
236 * Add the given {@link SearchableTag} as a subtag child.
241 public void add(SearchableTag tag
) {
247 * This {@link SearchableTag} parent tag, or NULL if none.
249 * @return the parent or NULL
251 public SearchableTag
getParent() {
256 * Display a DEBUG {@link String} representation of this object.
259 public String
toString() {
260 String rep
= name
+ " [" + id
+ "]";
265 if (getCount() > 0) {
266 rep
+= " (" + getCountDisplay() + ")";
269 if (!children
.isEmpty()) {
272 for (SearchableTag tag
: children
) {
273 if (!tags
.isEmpty()) {