Class TermComparator

java.lang.Object
org.projog.core.term.TermComparator
All Implemented Interfaces:
Comparator<Term>

public final class TermComparator extends Object implements Comparator<Term>
An implementation of Comparator for comparing instances of Term.
See Also:
  • Field Details

    • TERM_COMPARATOR

      public static final TermComparator TERM_COMPARATOR
      Singleton instance
  • Method Details

    • 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 String values they represent using String.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:
      compare in interface Comparator<Term>
      Parameters:
      t1 - the first term to be compared
      t2 - 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