|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlp.struct.LpAbstractStructureUnit
lp.struct.LpCompoundTerm
public class LpCompoundTerm
This class represents a compound term in logic programming. Such a
term is composed of a function symbol (represented by a LpFunction
instance) and its arguments—terms represented by LpTerm
instances. The number of arguments must match the function's arity
(returned by LpFunction.getArity()
). This class is immutable as long
as the argument list used to create it is not changed later.
LpFunction
,
LpTerm
Field Summary | |
---|---|
private List<LpTerm> |
arguments
The function's arguments. |
private LpFunction |
function
The top-most function symbol that is used in this compound term. |
private static LpBuffer |
keyBuilder
Used to create construct keys in pool . |
private static Map<String,LpCompoundTerm> |
pool
A pool of instances of this immutable class. |
Fields inherited from class lp.struct.LpAbstractStructureUnit |
---|
TO_STRING_BUFFER |
Constructor Summary | |
---|---|
private |
LpCompoundTerm(LpFunction function,
List<LpTerm> arguments)
Creates a new instance with the given values as members. |
Method Summary | |
---|---|
void |
accept(LpStructureUnitVisitor visitor)
Accepts LpStructureUnitVisitor instance, i.e. calls its
visitor.visit(this) . |
boolean |
equals(Object obj)
Returns true if and only if
obj is a LpCompoundTerm instance,
its function symbol is equal to this term's function symbol as
defined by LpFunction.equals(Object) ,
its argument list is equal to this term's argument list
|
List<LpTerm> |
getArguments()
Returns the list of arguments of this compound term. |
LpFunction |
getFunction()
Returns the function symbol of this compound term, the same that was given to the constructor. |
static LpCompoundTerm |
getInstance(LpFunction function,
List<LpTerm> arguments)
Returns an instance of LpCompoundTerm with the given function
symbol and argument list. |
int |
hashCode()
Overriden in order to maintain the general contract of Object.hashCode() . |
private static void |
checkArity(LpFunction function,
List<LpTerm> arguments)
Checks whether function.getArity() equals
arguments.size() . |
Methods inherited from class lp.struct.LpAbstractStructureUnit |
---|
toString, toUnmodifiableList, toUnmodifiableSet |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static final Map<String,LpCompoundTerm> pool
getInstance(LpFunction, List)
method first looks here for the
requested instances and if it is forced to create a new one, it is added
to this pool.
private static final LpBuffer keyBuilder
pool
.
private final LpFunction function
private final List<LpTerm> arguments
Constructor Detail |
---|
private LpCompoundTerm(LpFunction function, List<LpTerm> arguments)
arguments
List
).
function
- the top-most function symbol used in this compound termarguments
- terms that will become arguments of the function
IllegalArgumentException
- if function
is null
or
the number of arguments doesn't match the function's arity, i.e. if this
condition doesn't hold:
(arguments == null && function.getArity() == 0) || arguments.size() == function.getArity()
Method Detail |
---|
public static LpCompoundTerm getInstance(LpFunction function, List<LpTerm> arguments)
LpCompoundTerm
with the given function
symbol and argument list.
function
- the requested term's function symbolarguments
- the argument list of the requested
LpCompoundTerm
instance
IllegalArgumentException
- if function
is null
or the number of args doesn't match the function's arity, i.e. this
condition doesn't hold:
(args == null && function.getArity() == 0) || args.size() == function.getArity()
private static void checkArity(LpFunction function, List<LpTerm> arguments)
function.getArity()
equals
arguments.size()
. If it doesn't, throws an
IllegalArgumentException
.
function
- a function, its arity must match the length of the
argument listarguments
- an argument list, its length must match the function's
arity
IllegalArgumentException
- if function.getArity()
is not
the same as arguments.size()
public LpFunction getFunction()
LpFunction
instance given in the constructorpublic List<LpTerm> getArguments()
null
, even if it was given to the constructor of this instance
(in that case an empty list is returned).
public void accept(LpStructureUnitVisitor visitor)
LpStructureUnitVisitor
instance, i.e. calls its
visitor.visit(this)
.
accept
in interface LpStructureUnit
visitor
- the visitor to acceptpublic boolean equals(Object obj)
true
if and only if
obj
is a LpCompoundTerm
instance,LpFunction.equals(Object)
,
equals
in interface LpTerm
equals
in class Object
obj
- the object to compare with
true
if this object is equal to obj
according to
the description above, and false
otherwiseLpFunction.equals(Object)
,
List.equals(Object)
,
LpTerm.equals(Object)
public int hashCode()
Object.hashCode()
.
hashCode
in interface LpTerm
hashCode
in class Object
LpFunction.hashCode()
,
List.hashCode()
,
LpTerm.equals(Object)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |