prolog.implementation
Class Relation

java.lang.Object
  |
  +--prolog.implementation.Relation
All Implemented Interfaces:
java.lang.Cloneable, IRelation

public class Relation
extends java.lang.Object
implements IRelation, java.lang.Cloneable

The base class of a relation between some atoms, like a row in a database. This interface is used to store and get facts but also to store and get parameters e.g. in a statement

prolog: myFact(joe,dan).

in this example, the relation would contain the atoms "joe" and "dan"


Field Summary
protected  java.util.List values
          the list where all atoms of the relation are stored
 
Constructor Summary
Relation()
          costructor
Relation(IRelation r)
          copy constructor
 
Method Summary
 void add(java.lang.Object value)
          adds a atom to this relation
 java.util.Map buildMap()
          builds a indexmap. a indexmap contains the atom as key and the index as integer. this function is only used for parameter matching.
 boolean equals(java.lang.Object o)
           
 void genXml(java.io.Writer out, ISymbolTable table)
          generates xml describing this relation
 IAtom get(int index)
          returns the atom at the specified index
 int getValueCount()
          returns the number of atoms contained in this relation
 java.util.Iterator getValues()
          returns an iterator over all atoms contained in this relation
 java.lang.String toString()
           
 java.lang.String toString(int[] parameterNames, ISymbolTable table)
          returns a string representation of this object with decoded symbols in prolog syntax used for query results e.g.
 java.lang.String toString(ISymbolTable table)
          returns a string representation of this object with decoded symbols
 
Methods inherited from class java.lang.Object
, clone, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

values

protected java.util.List values
the list where all atoms of the relation are stored
Constructor Detail

Relation

public Relation()
costructor

Relation

public Relation(IRelation r)
copy constructor
Parameters:
r - - relation to copy
Method Detail

add

public void add(java.lang.Object value)
adds a atom to this relation
Parameters:
value - - the atom to be added

getValueCount

public int getValueCount()
returns the number of atoms contained in this relation
Specified by:
getValueCount in interface IRelation
Returns:
number of atoms

buildMap

public java.util.Map buildMap()
builds a indexmap. a indexmap contains the atom as key and the index as integer. this function is only used for parameter matching.
Specified by:
buildMap in interface IRelation
Returns:
the created indexmap

get

public IAtom get(int index)
returns the atom at the specified index
Specified by:
get in interface IRelation
Parameters:
index - of the atom to be returned
Returns:
atom at the specified index

getValues

public java.util.Iterator getValues()
returns an iterator over all atoms contained in this relation
Specified by:
getValues in interface IRelation
Returns:
iterator over the values in this relation

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
a string representation of this object

toString

public java.lang.String toString(ISymbolTable table)
returns a string representation of this object with decoded symbols
Specified by:
toString in interface IRelation
Parameters:
table - - the symboltable used to decode
Returns:
the string representation

toString

public java.lang.String toString(int[] parameterNames,
                                 ISymbolTable table)
returns a string representation of this object with decoded symbols in prolog syntax used for query results e.g. X=a, Y=b
Specified by:
toString in interface IRelation
Parameters:
table - - the symboltable used to decode
parameterNames - - the names of the parameters in this relation
Returns:
the string representation

genXml

public void genXml(java.io.Writer out,
                   ISymbolTable table)
            throws java.io.IOException
generates xml describing this relation
Specified by:
genXml in interface IRelation
Parameters:
out - the writer where o append the xml
table - the symboltable if the xml should be decoded
Throws:
java.io.IOException - if writing xml fails