Class IntegerNumber
- java.lang.Object
-
- org.projog.core.term.IntegerNumber
-
- All Implemented Interfaces:
ArithmeticOperator,Numeric,Term
public final class IntegerNumber extends java.lang.Object implements Numeric
Represents a value of the primitive typelongas aTerm.IntegerNumbers are constant; their values cannot be changed after they are created. IntegerNumbers have no arguments.
-
-
Field Summary
Fields Modifier and Type Field Description private longvalue
-
Constructor Summary
Constructors Constructor Description IntegerNumber(long value)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbacktrack()Reverts this term back to its original state prior to any unifications.IntegerNumbercalculate(Term[] args)Returns the result of the calculation using the specified arguments.IntegerNumbercopy(java.util.Map<Variable,Variable> sharedVariables)Returns a copy of this term.booleanequals(java.lang.Object o)Term[]getArgs()Returns an array of this terms's arguments.TermgetArgument(int index)Returns the term at the specified position in this term's arguments.doublegetDouble()Returns the value of this numeric as adouble.longgetLong()Returns the value of this numeric as along.java.lang.StringgetName()Returns aStringrepresentation of thelongthis term represents.intgetNumberOfArguments()Returns the number of arguments in this term.IntegerNumbergetTerm()Returns the current instantiated state of this term.TermTypegetType()ReturnsTermType.INTEGER.inthashCode()booleanisImmutable()Returnstrueis this term is immutable.java.lang.StringtoString()booleanunify(Term t)Attempts to unify this term to the specified term.
-
-
-
Method Detail
-
getName
public java.lang.String getName()
Returns aStringrepresentation of thelongthis term represents.
-
getArgs
public Term[] getArgs()
Description copied from interface:TermReturns an array of this terms's arguments.Note: for performance reasons the array returned is the same array used internally be the term instance so be careful not to alter the array returned as changes will be reflected in the original term.
- Specified by:
getArgsin interfaceTerm- Returns:
- array of this terms's arguments
- See Also:
Term.getArgument(int)
-
getNumberOfArguments
public int getNumberOfArguments()
Description copied from interface:TermReturns the number of arguments in this term.- Specified by:
getNumberOfArgumentsin interfaceTerm- Returns:
- number of arguments in this term
-
getArgument
public Term getArgument(int index)
Description copied from interface:TermReturns the term at the specified position in this term's arguments.- Specified by:
getArgumentin interfaceTerm- Parameters:
index- index of the argument to return- Returns:
- the term at the specified position in this term's arguments
- Throws:
java.lang.ArrayIndexOutOfBoundsException- as this implementation ofTermhas no arguments
-
getType
public TermType getType()
ReturnsTermType.INTEGER.- Specified by:
getTypein interfaceTerm- Returns:
TermType.INTEGER
-
isImmutable
public boolean isImmutable()
Description copied from interface:TermReturnstrueis this term is immutable.A term is considered immutable if its value will never change as a result of executing its
Term.unify(Term)orTerm.backtrack()methods. A term will not be considered immutable if it is aVariableor any of its arguments are not immutable.- Specified by:
isImmutablein interfaceTerm- Returns:
trueis this term is immutable
-
getTerm
public IntegerNumber getTerm()
Description copied from interface:TermReturns the current instantiated state of this term.Returns a representation of this term with all instantiated
Variables replaced with the terms they are instantiated with.
-
copy
public IntegerNumber copy(java.util.Map<Variable,Variable> sharedVariables)
Description copied from interface:Term
-
unify
public boolean unify(Term t)
Description copied from interface:TermAttempts to unify this term to the specified term.The rules for deciding if two terms are unifiable are as follows:
- An uninstantiated
Variablewill unify with any term. As a result theVariablewill become instantiated to the other term. The instantiaton will be undone whenTerm.backtrack()is next called on theVariable - Non-variable terms will unify with other terms that are of the same
TermTypeand have the same value. The exact meaning of "having the same value" will vary between term types but will include that the two terms being unified have the same number of arguments and that all of their corresponding arguments unify.
- Specified by:
unifyin interfaceTerm- Parameters:
t- the term to unify this term against- Returns:
trueif the attempt to unify this term to the given term was successful- See Also:
Term.backtrack()
- An uninstantiated
-
backtrack
public void backtrack()
Description copied from interface:TermReverts this term back to its original state prior to any unifications.Makes all
Variables that this term consists of uninstantiated.- Specified by:
backtrackin interfaceTerm- See Also:
Term.unify(Term)
-
getLong
public long getLong()
Description copied from interface:NumericReturns the value of this numeric as along.
-
getDouble
public double getDouble()
Description copied from interface:NumericReturns the value of this numeric as adouble.
-
calculate
public IntegerNumber calculate(Term[] args)
Description copied from interface:ArithmeticOperatorReturns the result of the calculation using the specified arguments.- Specified by:
calculatein interfaceArithmeticOperator- Parameters:
args- the arguments to use in the calculation- Returns:
- the result of the calculation using the specified arguments
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- Returns:
- a
Stringrepresentation of thelongthis term represents
-
-