Class TermComparator

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(Term t1, Term t2)
      Compares the two arguments for order.
      private int compareStructures​(Term t1, Term t2)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Field Detail

      • TERM_COMPARATOR

        public static final TermComparator TERM_COMPARATOR
        Singleton instance
    • Constructor Detail

      • TermComparator

        private TermComparator()
        Private constructor to force use of TERM_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 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 java.util.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
      • compareStructures

        private int compareStructures​(Term t1,
                                      Term t2)