Class TermUtils


  • public final class TermUtils
    extends java.lang.Object
    Helper methods for performing common tasks on Term instances.
    • Field Detail

      • EMPTY_ARRAY

        public static final Term[] EMPTY_ARRAY
        A Term array of length 0.

        Should be used wherever a zero-length Term array is required in order to minimise object creation.

    • Constructor Detail

      • TermUtils

        private TermUtils()
        Private constructor as all methods are static.
    • Method Detail

      • copy

        public static Term[] copy​(Term... input)
        Returns copies of the specified {link Term}s
        Parameters:
        input - Terms to copy
        Returns:
        copies of the specified {link Term}s
      • backtrack

        public static void backtrack​(Term[] terms)
        Backtracks all Terms in the specified array.
        Parameters:
        terms - Terms to backtrack
        See Also:
        Term.backtrack()
      • unify

        public static boolean unify​(Term[] queryArgs,
                                    Term[] consequentArgs)
        Attempts to unify all corresponding Terms in the specified arrays.

        Note: If the attempt to unify the corresponding terms is unsuccessful only the terms in queryArgs will get backtracked.

        Parameters:
        queryArgs - terms to unify with consequentArgs
        consequentArgs - terms to unify with queryArgs
        Returns:
        true if the attempt to unify all corresponding terms was successful
      • getAllVariablesInTerm

        public static java.util.Set<Variable> getAllVariablesInTerm​(Term argument)
        Returns all Variables contained in the specified term.
        Parameters:
        argument - the term to find variables for
        Returns:
        all Variables contained in the specified term.
      • getAllVariablesInTerm

        private static void getAllVariablesInTerm​(Term argument,
                                                  java.util.Set<Variable> variables)
      • toInt

        public static int toInt​(Term t)
        Returns the integer value of the Numeric represented by the specified Term.
        Parameters:
        t - the term representing a Numeric
        Returns:
        the int value represented by t
        Throws:
        ProjogException - if the specified Term cannot be represented as an int.
      • toLong

        public static long toLong​(ArithmeticOperators operators,
                                  Term t)
        Return the long value represented by the specified term.
        Parameters:
        t - the term representing a long value
        Returns:
        the long value represented by t
        Throws:
        ProjogException - if the specified Term does not represent a term of type TermType.INTEGER
      • getAtomName

        public static java.lang.String getAtomName​(Term t)
        Return the name of the Atom represented by the specified Atom.
        Parameters:
        t - the term representing an Atom
        Returns:
        the name of Atom represented by the specified Term
        Throws:
        ProjogException - if the specified Term does not represent an Atom
      • assertType

        public static void assertType​(Term t,
                                      TermType type)
      • termsEqual

        public static boolean termsEqual​(Term a,
                                         Term b)