Class Structure
java.lang.Object
org.projog.core.term.Structure
- All Implemented Interfaces:
Term
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor to force use ofcreateStructure(String, Term[]) -
Method Summary
Modifier and TypeMethodDescriptionvoidReverts this term back to its original state prior to any unifications.Returns a copy of this term.static TermcreateStructure(String functor, Term[] args) Factory method for creatingStructureinstances.booleanTerm[]getArgs()Returns an array of this terms's arguments.getArgument(int index) Returns the term at the specified position in this term's arguments.getName()Returns the functor of this structure.intReturns the number of arguments in this term.getTerm()Returns the current instantiated state of this term.getType()ReturnsTermType.STRUCTURE.inthashCode()booleanReturnstrueis this term is immutable.private static booleanisImmutable(Term[] args) toString()Returns aStringrepresentation of this term.booleanAttempts to unify this term to the specified term.
-
Field Details
-
functor
-
args
-
immutable
private final boolean immutable -
hashCode
private final int hashCode
-
-
Constructor Details
-
Structure
Private constructor to force use ofcreateStructure(String, Term[])- Parameters:
immutable- is this structure immutable (i.e. are all its arguments known to be immutable)?
-
-
Method Details
-
createStructure
Factory method for creatingStructureinstances.The reason that
Structures have to be created via a factory method, rather than a constructor, is to enforce:- structures with the functor
.and two arguments are created as instances ofList - no structures can be created without any arguments
- structures with the functor
-
isImmutable
-
getName
-
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.
-
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
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
-
getType
ReturnsTermType.STRUCTURE.- Specified by:
getTypein interfaceTerm- Returns:
TermType.STRUCTURE
-
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
-
copy
Description copied from interface:Term -
unify
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.
- An uninstantiated
-
backtrack
-
equals
-
hashCode
-
toString
-