|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlp.struct.LpAbstractStructureUnit
lp.struct.LpAtom
public class LpAtom
This class represents an atom in logic programming. Such an atom is composed
of a predicate symbol (represented by a LpPredicate
instance) and its
arguments—terms represented by LpTerm
instances.
The number of arguments must match the predicate's arity (returned by
LpPredicate.getArity()
). This class is immutable as long as the
argument list used to create it is not changed later.
LpPredicate
,
LpTerm
,
LpLiteral
Field Summary | |
---|---|
private List<LpTerm> |
arguments
The predicate's arguments. |
private static LpBuffer |
keyBuilder
Used to create construct keys in pool . |
private LpLiteral |
negLit
A negative literal bound to this atom. |
private static Map<String,LpAtom> |
pool
A pool of instances of this immutable class. |
private LpLiteral |
posLit
A positive literal bound to this atom. |
private LpPredicate |
predicate
The predicate symbol that is used in this atom. |
Fields inherited from class lp.struct.LpAbstractStructureUnit |
---|
TO_STRING_BUFFER |
Constructor Summary | |
---|---|
private |
LpAtom(LpPredicate predicate,
List<LpTerm> arguments)
Creates a new instance of LpAtom with the given predicate symbol
and argument list. |
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 LpAtom instance,
its predicate is equal to this atom's predicate as defined by
LpPredicate.equals(Object) ,
its argument list are equal to this atom's argument list. |
List<LpTerm> |
getArguments()
Returns the list of arguments of this atom. |
static LpAtom |
getInstance(LpPredicate predicate,
List<LpTerm> arguments)
Returns an instance of LpAtom with the given predicate symbol and
argument list. |
LpLiteral |
getLiteral(boolean positive)
Returns a literal for this atom represented by a LpLiteral
instance. |
LpLiteral |
getNegativeLiteral()
Returns a negative literal for this atom represented by a LpLiteral instance. |
LpLiteral |
getPositiveLiteral()
Returns a positive literal for this atom represented by a LpLiteral instance. |
LpPredicate |
getPredicate()
Returns the predicate symbol of this atom, the same that was given to the constructor. |
int |
hashCode()
Overriden in order to maintain the general contract of Object.hashCode() . |
private static void |
checkArity(LpPredicate predicate,
List<LpTerm> arguments)
Checks whether predicate.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,LpAtom> pool
getInstance(LpPredicate, 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 LpPredicate predicate
private final List<LpTerm> arguments
private LpLiteral posLit
private LpLiteral negLit
Constructor Detail |
---|
private LpAtom(LpPredicate predicate, List<LpTerm> arguments)
LpAtom
with the given predicate symbol
and argument list.
predicate
- the requested atom's predicate symbolarguments
- the argument list of the requested LpAtom
instance
IllegalArgumentException
- if predicate
is null
or the number of arguments doesn't match the predicate's arity, i.e. this
condition doesn't hold:
(arguments == null && predicate.getArity() == 0) || arguments.size() == predicate.getArity()
Method Detail |
---|
public static LpAtom getInstance(LpPredicate predicate, List<LpTerm> arguments)
LpAtom
with the given predicate symbol and
argument list.
predicate
- the requested atom's predicate symbolarguments
- the argument list of the requested LpAtom
instance
IllegalArgumentException
- if predicate
is null
or the number of arguments doesn't match the predicate's arity, i.e. this
condition doesn't hold:
(arguments == null && predicate.getArity() == 0) || arguments.size() == predicate.getArity()
private static void checkArity(LpPredicate predicate, List<LpTerm> arguments)
predicate.getArity()
equals
arguments.size()
. If it doesn't, throws an
IllegalArgumentException
.
predicate
- a predicate, its arity must match the length of the
argument listarguments
- an argument list, its length must match the predicate's
arity
IllegalArgumentException
- if predicate.getArity()
is not
the same as arguments.size()
public LpPredicate getPredicate()
LpPredicate
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 LpLiteral getPositiveLiteral()
LpLiteral
instance.
public LpLiteral getNegativeLiteral()
LpLiteral
instance.
public LpLiteral getLiteral(boolean positive)
LpLiteral
instance. The parameter constrols if the literal will be positive or
negative.
positive
- if true
, the resulting literal will be positive,
otherwise it will be negative
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 LpAtom
instance,LpPredicate.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
otherwiseLpPredicate.equals(Object)
,
LpTerm.equals(Object)
,
List.equals(Object)
public int hashCode()
Object.hashCode()
.
hashCode
in class Object
LpPredicate.hashCode()
,
List.hashCode()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |