Package org.projog.core.term
Class TermComparator
- java.lang.Object
-
- org.projog.core.term.TermComparator
-
-
Field Summary
Fields Modifier and Type Field Description static TermComparatorTERM_COMPARATORSingleton instance
-
Constructor Summary
Constructors Modifier Constructor Description privateTermComparator()Private constructor to force use ofTERM_COMPARATOR
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompare(Term t1, Term t2)Compares the two arguments for order.private intcompareStructures(Term t1, Term t2)
-
-
-
Field Detail
-
TERM_COMPARATOR
public static final TermComparator TERM_COMPARATOR
Singleton instance
-
-
Constructor Detail
-
TermComparator
private TermComparator()
Private constructor to force use ofTERM_COMPARATOR
-
-
Method Detail
-
compare
public int compare(Term t1, Term t2)
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 interfacejava.util.Comparator<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
-
-