lp.struct
Class LpLiteral

java.lang.Object
  extended by lp.struct.LpAbstractStructureUnit
      extended by lp.struct.LpLiteral
All Implemented Interfaces:
LpStructureUnit

public class LpLiteral
extends LpAbstractStructureUnit

This class represents a literal in logic programming. Such a literal can be positive or negative (default) and relates to exactly one atom represented by a instance.

Version:
1.0.0
Author:
Martin Slota
See Also:
LpAtom, LpRule

Field Summary
private  LpAtom atom
          The atom part of this literal.
private  boolean positive
          The polarity of this literal.
 
Fields inherited from class lp.struct.LpAbstractStructureUnit
TO_STRING_BUFFER
 
Constructor Summary
LpLiteral(boolean positive, LpAtom atom)
          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 LpLiteral instance, it has the same polarity as this literal, its underlying LpAtom instance is equal to this literal's underlying LpAtom instance
 List<LpTerm> getArguments()
          Returns the list of arguments of this literal.
 LpAtom getAtom()
          Returns the atom used to create this literal, the same that was given to the constructor.
 LpPredicate getPredicate()
          Returns the predicate symbol of this literal.
 int hashCode()
          Overriden in order to maintain the general contract of Object.hashCode().
 boolean isPositive()
          Returns true if this literal is positive and false otherwise.
 
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

positive

private final boolean positive
The polarity of this literal. true if this is a positive literal, false if this is a default literal.


atom

private final LpAtom atom
The atom part of this literal.

Constructor Detail

LpLiteral

LpLiteral(boolean positive,
          LpAtom atom)
Creates a new instance with the given values as members. Should only be directly used by methods of LpAtom.

Parameters:
positive - true if it's supposed to be a positive literal, false if it's supposed to be a default literal
atom - the atom part of this literal
Throws:
IllegalArgumentException - if atom is null
Method Detail

isPositive

public boolean isPositive()
Returns true if this literal is positive and false otherwise.

Returns:
true iff this literal is positive

getAtom

public LpAtom getAtom()
Returns the atom used to create this literal, the same that was given to the constructor.

Returns:
the LpAtom instance given in the constructor

getPredicate

public LpPredicate getPredicate()
Returns the predicate symbol of this literal.

Returns:
the LpPredicate instance representing the predicate symbol used in this literal
See Also:
LpAtom.getPredicate()

getArguments

public List<LpTerm> getArguments()
Returns the list of arguments of this literal.

Returns:
an unmodifiable view of the argument list of this literal
See Also:
LpAtom.getArguments()

accept

public void accept(LpStructureUnitVisitor visitor)
Accepts LpStructureUnitVisitor instance, i.e. calls its visitor.visit(this).

Parameters:
visitor - the visitor to accept

equals

public boolean equals(Object obj)
Returns true if and only if
  1. obj is a LpLiteral instance,
  2. it has the same polarity as this literal,
  3. its underlying LpAtom instance is equal to this literal's underlying LpAtom instance

Overrides:
equals in class Object
Parameters:
obj - the object to compare with
Returns:
true if this object is equal to obj according to the description above, and false otherwise
See Also:
LpAtom.equals(Object)

hashCode

public int hashCode()
Overriden in order to maintain the general contract of Object.hashCode().

Overrides:
hashCode in class Object
Returns:
the hash of this object
See Also:
LpAtom.hashCode()