|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlp.struct.LpAbstractStructureUnit
lp.struct.LpPredicate
public class LpPredicate
Represents a predicate (symbol) in logic programming. Each predicate has a
name and an arity, i.e. a non-negative integer that specifies the number of
terms (see LpTerm
) that it takes as arguments. LpPredicate
s
are immutable.
LpTerm
,
LpLiteral
Field Summary | |
---|---|
private int |
arity
This predicate's arity. |
private String |
name
This predicate's name. |
private static Map<String,LpPredicate> |
pool
A pool of instances of this immutable class. |
Fields inherited from class lp.struct.LpAbstractStructureUnit |
---|
TO_STRING_BUFFER |
Constructor Summary | |
---|---|
protected |
LpPredicate(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 its
visitor.visit(this) . |
boolean |
equals(Object obj)
Returns true if and only if
obj is a LpPredicate instance,
its name is equal to this predicate's name as defined by
String.equals(Object) ,
its arity is equal to this predicate's arity
|
int |
getArity()
Returns this predicate's arity. |
static LpPredicate |
getInstance(String name,
int arity)
Returns and instance of LpPredicate with the given name and
arity. |
static LpPredicate |
getInstance(String name,
List<LpTerm> arguments)
Returns and instance of LpPredicate with the given name and arity
implied by the size of the given argument list. |
String |
getName()
Returns this predicate'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,LpPredicate> 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 LpPredicate(String name, int arity)
name
is
required to be a non-empty string and arity
must be non-negative.
name
- the name of the predicatearity
- the predicate's arity
IllegalArgumentException
- if name
is null
or
name
is an empty string or arity
is negativeMethod Detail |
---|
public static LpPredicate getInstance(String name, int arity)
LpPredicate
with the given name and
arity. name
is required to be a non-empty string and
arity
must be non-negative.
name
- the name of the requested predicatearity
- the requested predicate's arity
IllegalArgumentException
- if name
is null
or
name
is an empty string or arity
is negativepublic static LpPredicate getInstance(String name, List<LpTerm> arguments)
LpPredicate
with the given name and arity
implied by the size of the given argument list. name
is required
to be a non-empty string.
name
- the name of the requested predicatearguments
- the sample argument list, its size is the predicate's
arity (it can also be null
, in that case a predicate with arity 0
is returned)
IllegalArgumentException
- if name
is null
or
name
is an empty stringpublic String getName()
public int getArity()
public void accept(LpStructureUnitVisitor visitor)
LpStructureUnitVisitor
instance, i.e. calls its
visitor.visit(this)
.
visitor
- the visitor to acceptpublic boolean equals(Object obj)
true
if and only if
obj
is a LpPredicate
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 predicate'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 |