Class TermComparator
java.lang.Object
org.projog.core.term.TermComparator
- All Implemented Interfaces:
Comparator<Term>
An implementation of
Comparator for comparing instances of Term.- See Also:
-
Field Summary
Fields -
Method Summary
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
TERM_COMPARATOR
Singleton instance
-
-
Method Details
-
compare
Compares the two arguments for order.Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
The criteria for deciding the order of terms is as follows:
- All uninstantiated variables are less than all floating point numbers, which are less than all integers, which are less than all atoms, which are less than all structures (including lists).
- Comparison of two integer or two floating point numbers is done using
NumericTermComparator. - Comparison of two atoms is done by comparing the
Stringvalues they represent usingString.compareTo(String). - One structure is less than another if it has a lower arity (number of arguments). If two structures have the
same arity then they are ordered by comparing their functors (names) (determined by
String.compareTo(String)). If two structures have the same arity and functor then they are ordered by comparing their arguments in order. The first corresponding arguments that differ determines the order of the two structures.
- Specified by:
comparein interfaceComparator<Term>- Parameters:
t1- the first term to be comparedt2- the second term to be compared- Returns:
- a negative integer, zero, or a positive integer as the first term is less than, equal to, or greater than the second
-