de.unidu.is.pdatalog.ds
Class Literal

java.lang.Object
  extended byde.unidu.is.pdatalog.ds.Literal

public class Literal
extends java.lang.Object

The representation of an datalog literal. An literal is a string [!]p(t1,...,tn) where is p is a predicate name, the tis are the arguments (variable names or constants, where constants are conclosed on '') and n is the arity of the predicate. It is also called the arity of the literal. A literal can be positive (missing !) or negative (with starting !).

This class is used by Rule for storing the head literal.

Since:
2002-12-02 (predecessor 2000-07-27)
Version:
$Revision: 1.6 $, $Date: 2005/03/14 17:33:14 $
Author:
Henrik Nottelmann

Field Summary
protected  Expression[] arguments
          The arguments.
protected  boolean positive
          Being true iff this Literal is positive.
protected  java.lang.String predicateName
          The name of the predicate.
 
Constructor Summary
Literal(Literal literal)
          Creates a new literal.
Literal(java.lang.String predicateName, Expression[] arguments, boolean positive)
          Creates a new literal.
Literal(java.lang.String predicateName, java.util.List arguments, boolean positive)
          Creates a new literal.
 
Method Summary
 Literal createLiteral()
          Creates a positive copy of this literal.
 Literal createLiteral(boolean positive)
          Creates a copy of this literal.
 boolean equals(java.lang.Object o)
          Compares the specified Object with this literal for equality.
 java.util.Set getAllArguments()
          Returns a set containing all arguments (variables and constants).
 Expression getArgument(int index)
          Returns the argument at the specified index.
 java.lang.String getArguments()
          Returns the arguments as a comma separated string.
 int getArity()
          Returns the arity of this literal.
 java.util.Set getConstants()
          Returns a set containing all constants (no variables).
 java.lang.String getPredicateName()
          Returns the predicate name.
 java.util.Set getVariables()
          Returns a set containing all variables (no constants).
 int hashCode()
          Returns the hash code value for this literal.
 boolean isPositive()
          Returns if this literal is positive.
 boolean isVariable(int index)
          Returns whether the argument at the specified index is a variable name or a constant.
 void negate()
          Negates this literal.
 void putAllArguments(java.util.Set set)
          Puts all arguments (variables and constants) into the specified set.
 void putConstants(java.util.Set set)
          Puts all constants (no variables) into the specified set.
 void putVariables(java.util.Set set)
          Puts all variables (no constants) into the specified set.
 void setArgument(int index, Expression value)
          Sets the argument at the specified index.
 void setNegative()
          Makes this literal negative.
 void setPositive()
          Makes this literal positive.
 void setPositive(boolean positive)
          Sets if this literal is positive.
 void setPredicateName(java.lang.String predicateName)
          Sets the predicate name.
protected  java.lang.String toHashCodeString()
          Returns a string representation of this literal, used for equals(Object) and hashCode().
 java.lang.String toString()
          Returns a datalog representation of this literal.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

predicateName

protected java.lang.String predicateName
The name of the predicate.


arguments

protected Expression[] arguments
The arguments.


positive

protected boolean positive
Being true iff this Literal is positive.

Constructor Detail

Literal

public Literal(java.lang.String predicateName,
               Expression[] arguments,
               boolean positive)
Creates a new literal.

Parameters:
predicateName - predicate name
arguments - arguments (variable names or constants)
positive - true iff this literal is positive

Literal

public Literal(java.lang.String predicateName,
               java.util.List arguments,
               boolean positive)
Creates a new literal.

Parameters:
predicateName - predicate name
arguments - list of arguments (variable names or constants)
positive - true iff this literal is positive

Literal

public Literal(Literal literal)
Creates a new literal.

Parameters:
literal - to be copied
Method Detail

getPredicateName

public java.lang.String getPredicateName()
Returns the predicate name.

Returns:
predicate name

setPredicateName

public void setPredicateName(java.lang.String predicateName)
Sets the predicate name.

Parameters:
predicateName - predicate name

getArity

public int getArity()
Returns the arity of this literal.

Returns:
arity

getArguments

public java.lang.String getArguments()
Returns the arguments as a comma separated string.

Returns:
arguments

getArgument

public Expression getArgument(int index)
Returns the argument at the specified index.

Parameters:
index - index
Returns:
argument at the specified index

isVariable

public boolean isVariable(int index)
Returns whether the argument at the specified index is a variable name or a constant.

Parameters:
index - index
Returns:
flag indicating whether the argument at the specified index is a variable name or a constant

setArgument

public void setArgument(int index,
                        Expression value)
Sets the argument at the specified index.

Parameters:
index - specified index
value - new argument at the specified index

putVariables

public void putVariables(java.util.Set set)
Puts all variables (no constants) into the specified set.

Parameters:
set - destination set for all variables

putConstants

public void putConstants(java.util.Set set)
Puts all constants (no variables) into the specified set.

Parameters:
set - destination set for all constants

putAllArguments

public void putAllArguments(java.util.Set set)
Puts all arguments (variables and constants) into the specified set.

Parameters:
set - destination set for all arguments

getVariables

public java.util.Set getVariables()
Returns a set containing all variables (no constants).

Returns:
set containing all variables (no constants)

getConstants

public java.util.Set getConstants()
Returns a set containing all constants (no variables).

Returns:
set containing all constants (no variables)

getAllArguments

public java.util.Set getAllArguments()
Returns a set containing all arguments (variables and constants).

Returns:
set containing all arguments

isPositive

public boolean isPositive()
Returns if this literal is positive.

Returns:
true if this literal is positve

setPositive

public void setPositive(boolean positive)
Sets if this literal is positive.

Parameters:
positive - flag indicating if this literal is positive or negative

setPositive

public void setPositive()
Makes this literal positive. This is equivalent to setPositive(true).


setNegative

public void setNegative()
Makes this literal negative. This is equivalent to setPositive(false).


negate

public void negate()
Negates this literal.


createLiteral

public Literal createLiteral()
Creates a positive copy of this literal.

Returns:
positive copy of this literal

createLiteral

public Literal createLiteral(boolean positive)
Creates a copy of this literal.

Parameters:
positive - indicating whether the copy is positive or negative
Returns:
positive copy of this literal

toString

public java.lang.String toString()
Returns a datalog representation of this literal.

Returns:
a datalog representation of this literal

toHashCodeString

protected java.lang.String toHashCodeString()
Returns a string representation of this literal, used for equals(Object) and hashCode().

Returns:
a string representation of this literal

hashCode

public int hashCode()
Returns the hash code value for this literal. The hash code is calculated based on toHashCodeString().

Returns:
the hash code value for this literal

equals

public boolean equals(java.lang.Object o)
Compares the specified Object with this literal for equality. The comparasion is performed based on the equality of toHashCodeString().

Parameters:
o - the Object to be compared for equality with this literal
Returns:
true if the specified Object is equal to this literal