/** * Returns the taxonomy hierarchy of this taxon entry in the form: most specific; less specific; * ...; least specific. It follows the chain up the tree as far as it can, and will stop at the * first one it comes to that returns null for getParentNCBITaxID(). If this taxon entry has no * scientific name, you will get the string ".". * * @return the display name as described above. */ public String getNameHierarchy() { StringBuffer sb = new StringBuffer(); boolean first = true; Integer parent = this.getParentNCBITaxID(); while (parent != null) { NCBITaxon t = (NCBITaxon) RichObjectFactory.getObject(SimpleNCBITaxon.class, new Object[] {parent}); Set sciNames = t.getNames(NCBITaxon.SCIENTIFIC); // System.out.println("SimpleNCBITaxon2.getNameHierarchy-t:"+t+", t.isTaxonHidden? // "+t.isTaxonHidden()+", isRoot? "+isRoot(t)+", sciNames:"+sciNames); if (sciNames.size() > 0) { if (!t.isTaxonHidden() && !isRoot(t)) { // root is NOT hidden - but also not displayed if (!first) sb.insert(0, "; "); else first = false; sb.insert(0, (String) sciNames.iterator().next()); } // Don't get into endless loop if child's parent is itself. if (t.getParentNCBITaxID().equals(new Integer(t.getNCBITaxID()))) parent = null; else parent = t.getParentNCBITaxID(); } // Also don't go up past a parent that doesn't have a name. else parent = null; } sb.append("."); return sb.toString(); }
/** {@inheritDoc} NCBITaxon objects are equal if their NCBITaxID fields match. */ public boolean equals(Object obj) { if (this == obj) return true; if (obj == null || !(obj instanceof NCBITaxon)) return false; NCBITaxon them = (NCBITaxon) obj; return this.NCBITaxID == them.getNCBITaxID(); }
/** {@inheritDoc} NCBITaxon objects are compared only by their NCBITaxID fields. */ public int compareTo(Object o) { if (o == this) return 0; NCBITaxon them = (NCBITaxon) o; return this.NCBITaxID - them.getNCBITaxID(); }
private static final boolean isRoot(final NCBITaxon theTaxon) { return isRoot(theTaxon.getNCBITaxID()); }