X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsearchable%2FSearchableTag.java;h=de8679834f5fa20a72826fd6deb89cf405613de9;hb=HEAD;hp=c12b3c68eeeb5b0d3c2135b521bf5bbd354dbfa3;hpb=3172c8cf7cdb9f9bf90c4515b8494ae84e9527ff;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/searchable/SearchableTag.java b/src/be/nikiroo/fanfix/searchable/SearchableTag.java index c12b3c6..de86798 100644 --- a/src/be/nikiroo/fanfix/searchable/SearchableTag.java +++ b/src/be/nikiroo/fanfix/searchable/SearchableTag.java @@ -43,7 +43,7 @@ public class SearchableTag { * the tag is a leaf tag, that is, it will not return subtags * with {@link BasicSearchable#fillTag(SearchableTag)} but will * return stories with - * {@link BasicSearchable#search(SearchableTag)} + * {@link BasicSearchable#search(SearchableTag, int)} */ public SearchableTag(String id, String name, boolean leaf) { this(id, name, leaf, true); @@ -60,14 +60,14 @@ public class SearchableTag { * the tag is a leaf tag, that is, it will not return subtags * with {@link BasicSearchable#fillTag(SearchableTag)} but will * return stories with - * {@link BasicSearchable#search(SearchableTag)} + * {@link BasicSearchable#search(SearchableTag, int)} * @param complete * the tag {@link SearchableTag#isComplete()} or not */ public SearchableTag(String id, String name, boolean leaf, boolean complete) { this.id = id; this.name = name; - this.complete = complete; + this.complete = leaf || complete; setLeaf(leaf); @@ -92,12 +92,27 @@ public class SearchableTag { return name; } + /** + * The fully qualified tag name, which can be displayed to the user. + *

+ * It will display all the tags that lead to this one as well as this one. + * + * @return the fully qualified name + */ + public String getFqName() { + if (parent != null) { + return parent.getFqName() + " / " + name; + } + + return "" + name; + } + /** * Non-complete, non-leaf tags can still be completed via a * {@link BasicSearchable#fillTag(SearchableTag)} operation from a * {@link BasicSearchable}, in order to gain (more?) subtag children. *

- * This method does not make sense for leaf tags. + * Leaf tags are always considered complete. * * @return TRUE if it is complete */ @@ -110,13 +125,13 @@ public class SearchableTag { * {@link BasicSearchable#fillTag(SearchableTag)} operation from a * {@link BasicSearchable}, in order to gain (more?) subtag children. *

- * This method does not make sense for leaf tags. + * Leaf tags are always considered complete. * * @param complete * TRUE if it is complete */ public void setComplete(boolean complete) { - this.complete = complete; + this.complete = isLeaf() || complete; } /** @@ -171,7 +186,7 @@ public class SearchableTag { /** * This tag is a leaf tag, that is, it will not return other subtags with * {@link BasicSearchable#fillTag(SearchableTag)} but will return stories - * with {@link BasicSearchable#search(SearchableTag)}. + * with {@link BasicSearchable#search(SearchableTag, int)}. * * @return TRUE if it is */ @@ -182,7 +197,7 @@ public class SearchableTag { /** * This tag is a leaf tag, that is, it will not return other subtags with * {@link BasicSearchable#fillTag(SearchableTag)} but will return stories - * with {@link BasicSearchable#search(SearchableTag)}. + * with {@link BasicSearchable#search(SearchableTag, int)}. *

* Will reset the number of pages to -1. * @@ -191,6 +206,9 @@ public class SearchableTag { */ public void setLeaf(boolean leaf) { pages = leaf ? -1 : -2; + if (leaf) { + complete = true; + } } /** @@ -214,6 +232,23 @@ public class SearchableTag { * the tag to add */ public void add(SearchableTag tag) { + if (tag == null) { + throw new NullPointerException("tag"); + } + + for (SearchableTag p = this; p != null; p = p.parent) { + if (p.equals(tag)) { + throw new IllegalArgumentException( + "Tags do not allow recursion"); + } + } + for (SearchableTag p = tag; p != null; p = p.parent) { + if (p.equals(this)) { + throw new IllegalArgumentException( + "Tags do not allow recursion"); + } + } + children.add(tag); tag.parent = this; } @@ -263,4 +298,27 @@ public class SearchableTag { return rep; } + + @Override + public int hashCode() { + return getFqName().hashCode(); + } + + @Override + public boolean equals(Object otherObj) { + if (otherObj instanceof SearchableTag) { + SearchableTag other = (SearchableTag) otherObj; + if ((id == null && other.id == null) + || (id != null && id.equals(other.id))) { + if (getFqName().equals(other.getFqName())) { + if ((parent == null && other.parent == null) + || (parent != null && parent.equals(other.parent))) { + return true; + } + } + } + } + + return false; + } }