/** * Compares two terms in <em>Prolog standard order of terms</em>.<br> * It is noted that <code>t1.compareTo(t2) == 0</code> has the same <code>boolean</code> value as * <code>t1.equals(t2)</code>. * * @param anotherTerm the term to compared with. It must be dereferenced. * @return the value <code>0</code> if two terms are identical; a value less than <code>0</code> * if this term is <em>before</em> the <code>anotherTerm</code>; and a value greater than * <code>0</code> if this term is <em>after</em> the <code>anotherTerm</code>. */ public int compareTo(Term anotherTerm) { // anotherTerm must be dereferenced. if (anotherTerm.isVariable() || anotherTerm.isNumber()) return AFTER; if (!anotherTerm.isSymbol()) return BEFORE; if (this == anotherTerm) return EQUAL; int x = name.compareTo(((SymbolTerm) anotherTerm).name()); if (x != 0) return x; int y = this.arity - ((SymbolTerm) anotherTerm).arity(); if (y != 0) return y; throw new InternalException("SymbolTerm is not unique"); }