Package org.projog.core.term
Class TermUtils
- java.lang.Object
-
- org.projog.core.term.TermUtils
-
public final class TermUtils extends java.lang.ObjectHelper methods for performing common tasks onTerminstances.
-
-
Field Summary
Fields Modifier and Type Field Description static Term[]EMPTY_ARRAYATermarray of length 0.
-
Constructor Summary
Constructors Modifier Constructor Description privateTermUtils()Private constructor as all methods are static.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidassertType(Term t, TermType type)static voidbacktrack(Term[] terms)Backtracks allTerms in the specified array.static NumericcastToNumeric(Term t)static Term[]copy(Term... input)Returns copies of the specified {link Term}sstatic java.util.Set<Variable>getAllVariablesInTerm(Term argument)Returns allVariables contained in the specified term.private static voidgetAllVariablesInTerm(Term argument, java.util.Set<Variable> variables)static java.lang.StringgetAtomName(Term t)static booleantermsEqual(Term a, Term b)static inttoInt(Term t)static longtoLong(ArithmeticOperators operators, Term t)Return the long value represented by the specified term.static booleanunify(Term[] queryArgs, Term[] consequentArgs)Attempts to unify all correspondingTerms in the specified arrays.
-
-
-
Field Detail
-
EMPTY_ARRAY
public static final Term[] EMPTY_ARRAY
-
-
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 allTerms 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 correspondingTerms in the specified arrays.Note: If the attempt to unify the corresponding terms is unsuccessful only the terms in
queryArgswill get backtracked.- Parameters:
queryArgs- terms to unify withconsequentArgsconsequentArgs- terms to unify withqueryArgs- Returns:
trueif the attempt to unify all corresponding terms was successful
-
getAllVariablesInTerm
public static java.util.Set<Variable> getAllVariablesInTerm(Term argument)
Returns allVariables 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)
- Parameters:
t- the term representing aNumeric- Returns:
- the
intvalue represented byt - Throws:
ProjogException- if the specifiedTermcannot be represented as anint.
-
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
longvalue represented byt - Throws:
ProjogException- if the specifiedTermdoes not represent a term of typeTermType.INTEGER
-
getAtomName
public static java.lang.String getAtomName(Term t)
-
-