|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlp.struct.LpAbstractStructureUnit
lp.struct.LpFunction
public class LpFunction
Represents a function (symbol) in logic programming. Each function has a
name and an arity, i.e. a positive integer that specifies the number of
terms (see LpTerm
) that it takes as arguments. LpFunction
s
are immutable.
LpTerm
,
LpCompoundTerm
Field Summary | |
---|---|
private int |
arity
This function's arity. |
private String |
name
This function's name. |
private static Map<String,LpFunction> |
pool
A pool of instances of this immutable class. |
Fields inherited from class lp.struct.LpAbstractStructureUnit |
---|
TO_STRING_BUFFER |
Constructor Summary | |
---|---|
protected |
LpFunction(String name,
int arity)
Creates a new instance with the given name and arity. |
Method Summary | |
---|---|
void |
accept(LpStructureUnitVisitor visitor)
Accepts LpStructureUnitVisitor instance, i.e. calls
visitor.visit(this) . |
boolean |
equals(Object obj)
Returns true if and only if
obj is a LpFunction instance,
its name is equal to this function's name as defined by
String.equals(Object) ,
its arity is equal to this function's arity
|
int |
getArity()
Returns this function's arity, the same that was given to the constructor. |
static LpFunction |
getInstance(String name,
int arity)
Returns an instance of LpFunction with the given name and arity. |
static LpFunction |
getInstance(String name,
List<LpTerm> arguments)
Returns an instance of LpFunction with the given name and arity
implied by the size of the given argument list. |
String |
getName()
Returns this function's name, the same that was given to the constructor. |
int |
hashCode()
Overriden in order to maintain the general contract of Object.hashCode() . |
String |
toString()
Overrides the behaviour of LpAbstractStructureUnit.toString() . |
Methods inherited from class lp.struct.LpAbstractStructureUnit |
---|
toUnmodifiableList, toUnmodifiableSet |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static final Map<String,LpFunction> pool
getInstance(String, int)
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 final String name
private final int arity
Constructor Detail |
---|
protected LpFunction(String name, int arity)
name
is
required to be a non-empty string and arity
must be positive.
Functions of arity 0 are actually constants, so LpConstant
is
to be used instead.
name
- the name of the functionarity
- the function's arity
IllegalArgumentException
- if name
is null
or
name
is an empty string or arity
is not positiveMethod Detail |
---|
public static LpFunction getInstance(String name, int arity)
LpFunction
with the given name and arity.
name
is required to be a non-empty string and arity
must
be positive. Functions of arity 0 are actually constants, so
LpConstant
is to be used instead.
name
- the name of the requested functionarity
- the requested function's arity
IllegalArgumentException
- if name
is null
or
name
is an empty string or arity
is not positivepublic static LpFunction getInstance(String name, List<LpTerm> arguments)
LpFunction
with the given name and arity
implied by the size of the given argument list. name
is required
to be a non-empty string and arguments
must have at least one
member. Functions of arity 0 are actually constants, so
LpConstant
is to be used instead.
name
- the name of the requested functionarguments
- the sample argument list, its size is the function's
arity
IllegalArgumentException
- if name
is null
or
name
is an empty string or arguments
is null
or
arguments
is emptypublic String getName()
public int getArity()
public void accept(LpStructureUnitVisitor visitor)
LpStructureUnitVisitor
instance, i.e. calls
visitor.visit(this)
.
visitor
- the visitor to acceptpublic boolean equals(Object obj)
true
if and only if
obj
is a LpFunction
instance,String.equals(Object)
,
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
otherwiseString.equals(Object)
public int hashCode()
Object.hashCode()
.
hashCode
in class Object
String.hashCode()
public String toString()
LpAbstractStructureUnit.toString()
.
Returns the normal form (i.e. the function's name) followed by a "/" and
arity.
toString
in class LpAbstractStructureUnit
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |