From: Niki Roo Date: Wed, 17 Apr 2019 16:39:43 +0000 (+0200) Subject: search: .equals X-Git-Tag: fanfix-swing-0.0.1~12^2~127 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=a03372696edad30d121ea7fb333640470364a9e1;p=fanfix-swing.git search: .equals --- diff --git a/src/be/nikiroo/fanfix/searchable/SearchableTag.java b/src/be/nikiroo/fanfix/searchable/SearchableTag.java index 338f84da..de867983 100644 --- a/src/be/nikiroo/fanfix/searchable/SearchableTag.java +++ b/src/be/nikiroo/fanfix/searchable/SearchableTag.java @@ -104,7 +104,7 @@ public class SearchableTag { return parent.getFqName() + " / " + name; } - return name; + return "" + name; } /** @@ -232,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; } @@ -281,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; + } }