public final class IntegerNumber extends Object implements Numeric
long
as a Term
.
IntegerNumbers are constant; their values cannot be changed after they are created. IntegerNumbers have no arguments.
Constructor and Description |
---|
IntegerNumber(long value) |
Modifier and Type | Method and Description |
---|---|
void |
backtrack()
Reverts this term back to its original state prior to any unifications.
|
IntegerNumber |
calculate(Term[] args)
Returns the result of the calculation using the specified arguments.
|
IntegerNumber |
copy(Map<Variable,Variable> sharedVariables)
Returns a copy of this term.
|
boolean |
equals(Object o) |
Term[] |
getArgs()
Returns an array of this terms's arguments.
|
Term |
getArgument(int index)
Returns the term at the specified position in this term's arguments.
|
double |
getDouble()
Returns the value of this numeric as a
double . |
long |
getLong()
Returns the value of this numeric as a
long . |
String |
getName()
Returns a
String representation of the long this term represents. |
int |
getNumberOfArguments()
Returns the number of arguments in this term.
|
IntegerNumber |
getTerm()
Returns the current instantiated state of this term.
|
TermType |
getType()
Returns
TermType.INTEGER . |
int |
hashCode() |
boolean |
isImmutable()
Returns
true is this term is immutable. |
String |
toString() |
boolean |
unify(Term t)
Attempts to unify this term to the specified term.
|
public IntegerNumber(long value)
value
- the value this term representspublic String getName()
String
representation of the long
this term represents.public Term[] getArgs()
Term
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.
getArgs
in interface Term
Term.getArgument(int)
public int getNumberOfArguments()
Term
getNumberOfArguments
in interface Term
public Term getArgument(int index)
Term
getArgument
in interface Term
index
- index of the argument to returnArrayIndexOutOfBoundsException
- as this implementation of Term
has no argumentspublic TermType getType()
TermType.INTEGER
.getType
in interface Term
TermType.INTEGER
public boolean isImmutable()
Term
true
is this term is immutable.
A term is considered immutable if its value will never change as a result of executing its Term.unify(Term)
or
Term.backtrack()
methods. A term will not be considered immutable if it is a Variable
or any of its
arguments are not immutable.
isImmutable
in interface Term
true
is this term is immutablepublic IntegerNumber getTerm()
Term
Returns a representation of this term with all instantiated Variable
s replaced with the terms they are
instantiated with.
public IntegerNumber copy(Map<Variable,Variable> sharedVariables)
Term
public boolean unify(Term t)
Term
The rules for deciding if two terms are unifiable are as follows:
Variable
will unify with any term. As a result the Variable
will become
instantiated to the other term. The instantiaton will be undone when Term.backtrack()
is next called on the
Variable
TermType
and 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.unify
in interface Term
t
- the term to unify this term againsttrue
if the attempt to unify this term to the given term was successfulTerm.backtrack()
public void backtrack()
Term
Makes all Variable
s that this term consists of uninstantiated.
backtrack
in interface Term
Term.unify(Term)
public long getLong()
Numeric
long
.public double getDouble()
Numeric
double
.public IntegerNumber calculate(Term[] args)
ArithmeticOperator
calculate
in interface ArithmeticOperator
args
- the arguments to use in the calculationCopyright © 2024. All rights reserved.