Class TermUtils

java.lang.Object
org.projog.core.term.TermUtils

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

    • 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.

  • Method Details

    • 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:
    • castToNumeric

      public static Numeric castToNumeric(Term t)
      Return the Numeric represented by the specified Term.
      Parameters:
      t - the term representing a Numeric
      Returns:
      the Numeric represented by the specified Term
      Throws:
      ProjogException - if the specified Term does not represent a Numeric
    • 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 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)