DLV
Class Predicate.Literal

java.lang.Object
  extended byDLV.Predicate.Literal
Enclosing class:
Predicate

public class Predicate.Literal
extends java.lang.Object

This class represents Literals. A Literal in a logic database is like a tuple in a relational database.

Version:
3
Author:
Francesco Ricca

Constructor Summary
Predicate.Literal()
          Constructs a (positive) Literal of arity 0.
Predicate.Literal(boolean positive)
          Constructs a Literal of arity 0.
Predicate.Literal(java.lang.String[] term)
          Constructs a (positive) Literal from an array of terms.
Predicate.Literal(java.lang.String[] term, boolean positive)
          Constructs a Literal from an array of terms.
 
Method Summary
 void appendTo(java.io.PrintWriter out)
          This method allows to save this Literal in the file handled by "out" in datalog format.
 int arity()
          Returns the arity of the Predicate which contains this Literal.
 boolean equals(java.lang.Object o)
          If this Literal is the same of f returns true, otherwise false.
 Predicate.Literal getContrary()
          Gets the contrary Literal.
 Predicate getPredicate()
          This function returns the Predicate object which contains this Literal.
 java.lang.String getTermAt(int i)
          This function returns the i-th term of this Literal.
 void invert()
          If this Literal is positive this method make it negative and vice versa.
 boolean isContrary(Predicate.Literal f)
          If this Literal is the contrary of f returns true, otherwise false.
 boolean isPositive()
          Returns true if this Literal is positive.
 java.lang.String name()
          Returns the name of the Predicate which contains this Literal.
 void setTermAt(int i, java.lang.String t)
          This function sets the i-th term of this Literal.
 void setTermAt(java.lang.String t, int i)
          Deprecated. use setTermAt(int i, String t) instead.
 java.lang.String toString()
           
 void update()
          Commits changes made in this object updating the underlying literal implementation stored in the Predicate object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Predicate.Literal

public Predicate.Literal()
Constructs a (positive) Literal of arity 0. This is an abbreviation for Literal(new String[]{})

Throws:
BadArityException - if Literal arity differs from the arity of this Predicate.

Predicate.Literal

public Predicate.Literal(boolean positive)
Constructs a Literal of arity 0. The Literal built will be a positive Literal if "positive" is true, negative otherwise. This is an abbreviation for Literal(new String[]{},positive) This constructor is useful when true negation is used.

Parameters:
positive - A boolean variable which indicate that the Literal is positive or negative.
Throws:
BadArityException - if Literal arity differs from the arity of this Predicate.

Predicate.Literal

public Predicate.Literal(java.lang.String[] term)
Constructs a (positive) Literal from an array of terms.

Parameters:
term - Is an array of String objects which contains terms.
Throws:
BadArityException - if Literal arity differs from the arity of this Predicate.

Predicate.Literal

public Predicate.Literal(java.lang.String[] term,
                         boolean positive)
Constructs a Literal from an array of terms. The Literal built will be a positive Literal if "positive" is true, negative otherwise. This constructor is useful when true negation is used.

Parameters:
term - Is an array of String objects which contains terms.
positive - A boolean variable which indicate that the Literal is positive or negative.
Throws:
BadArityException - if Literal arity differs from the arity of this Predicate.
Method Detail

getPredicate

public Predicate getPredicate()
This function returns the Predicate object which contains this Literal. (From a relational point of view this function returns the table which contains this tuple).

Returns:
The Predicate object which contains this Literal.

name

public java.lang.String name()
Returns the name of the Predicate which contains this Literal.

Returns:
name of the Predicate which contains this Literal.

arity

public int arity()
Returns the arity of the Predicate which contains this Literal.

Returns:
The arity of the Predicate which contains this Literal.

getTermAt

public java.lang.String getTermAt(int i)
This function returns the i-th term of this Literal. (From a relational point of view this function returns the value conatined in the i-th position of this tuple).

Returns:
The i-th term of this Literal.
Throws:
NoSuchTermException - if you try to get a term which doesn't exist.

setTermAt

public void setTermAt(java.lang.String t,
                      int i)
Deprecated. use setTermAt(int i, String t) instead.


setTermAt

public void setTermAt(int i,
                      java.lang.String t)
This function sets the i-th term of this Literal. (From a relational point of view this function sets the value conatined in the i-th position of this tuple).

Throws:
NoSuchTermException - if you try to modify a term which doesn't exist.
java.lang.NullPointerException - if t is null.

isPositive

public boolean isPositive()
Returns true if this Literal is positive. This method is useful if the logic program uses true negation.

Returns:
Returns true if this Literal is positive.

invert

public void invert()
If this Literal is positive this method make it negative and vice versa. This method modify the current Literal and also the Predicate object P which contains it. If a contrary Literal object is contained in P yet, it will be removed. Be cautious using this method you may cause inconsistencies in logic programs! Be cautious using this method you may cause inconsistencies in multithread programs!


getContrary

public Predicate.Literal getContrary()
Gets the contrary Literal. It creates and returns a new Literal object which is the Contrary of this. The new object isn't inserted in the predicate.


isContrary

public boolean isContrary(Predicate.Literal f)
If this Literal is the contrary of f returns true, otherwise false.

Parameters:
f - a Literal object.
Returns:
true if this Literal is the contrary of f, otherwise false.
Throws:
java.lang.NullPointerException - if f is null.

toString

public java.lang.String toString()

appendTo

public void appendTo(java.io.PrintWriter out)
This method allows to save this Literal in the file handled by "out" in datalog format.
Be sure that "out" is open before call this method. This method does not close "out"


equals

public boolean equals(java.lang.Object o)
If this Literal is the same of f returns true, otherwise false. Two Literal are equals if they are:
- the same object
or
- part of the same Predicate, both positive (or negative) and they have the same terms.

Returns:
true if this Literal is the same of f, otherwise false.
Throws:
java.lang.NullPointerException - if f is null.

update

public void update()
Commits changes made in this object updating the underlying literal implementation stored in the Predicate object.

Throws:
LiteralStaledException - if this Literal is not more contained in the corresponding Predicate object.
TrueNegationNotSupportedException - if you try to invert this Literal and the implementation of the current Predicate does not support true negation.
MalformedTermException - if the literal contains malformed terms.