GNU Prolog for Java

gnu.prolog.database
Class Predicate

java.lang.Object
  extended by gnu.prolog.database.Predicate

public class Predicate
extends Object

Predicate in database

Author:
Contantine A Plotnikov

Nested Class Summary
static class Predicate.TYPE
          The possible types of Predicate
 
Field Summary
protected  List<Term> clauses
          list of clauses for this predicate
protected  boolean dynamicFlag
          dynamic property of predicate
protected  Set<String> files
          set files where this predicate is defined
protected  String javaClassName
          class name for external predicate
protected  Module module
          current module
protected  boolean propertiesLocked
          flag which indicate that clauses was added for this predicate
protected  CompoundTermTag tag
          a tag of predicate head
protected  Predicate.TYPE type
          type of predicate.
 
Constructor Summary
Predicate(Module module, CompoundTermTag tag)
          constructor of predicate
 
Method Summary
 void addClauseFirst(Term clause)
          Add clause for predicate at the beginning.
 void addClauseLast(Term clause)
          Add clause for predicate at the end.
 boolean arePropertiesLocked()
          Check if properties of predicate could be changed at this moment
 int getArity()
          get arity of predicate
 List<Term> getClauses()
          get clauses of predicate You must synchronize on this class when iterating through this list as although it is a synchronized list you are getting a unmodifiable view of that list.
 AtomTerm getFunctor()
          get functor of predicate
 String getJavaClassName()
          Get name of Java class that defines this predicate.
 CompoundTermTag getTag()
          get tag of predicate
 Predicate.TYPE getType()
          get type of predicate
 boolean isDynamic()
          Check if predicate is dynamic.
static Term prepareBody(Term body)
           
static Term prepareClause(Term clause)
           
static Term prepareHead(Term head)
           
 void removeClause(Term clause)
          Remove clause for predicate.
 void setDynamic()
          set "dynamic" property of predicate to true.
 void setJavaClassName(String javaClassName)
          set java class name of the predicate.
 void setType(Predicate.TYPE type)
          set type of predicate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

type

protected Predicate.TYPE type
type of predicate. It should be either UNDEFINED, CONTROL ,BUILD_IN, USER_DEFINED or EXTERNAL


tag

protected CompoundTermTag tag
a tag of predicate head


clauses

protected List<Term> clauses
list of clauses for this predicate


propertiesLocked

protected boolean propertiesLocked
flag which indicate that clauses was added for this predicate


dynamicFlag

protected boolean dynamicFlag
dynamic property of predicate


javaClassName

protected String javaClassName
class name for external predicate


files

protected Set<String> files
set files where this predicate is defined


module

protected Module module
current module

Constructor Detail

Predicate

public Predicate(Module module,
                 CompoundTermTag tag)
constructor of predicate

Parameters:
module -
tag -
Method Detail

getClauses

public List<Term> getClauses()
get clauses of predicate You must synchronize on this class when iterating through this list as although it is a synchronized list you are getting a unmodifiable view of that list.

Returns:
an unmodifiable list of the clauses of the Predicate

getType

public Predicate.TYPE getType()
get type of predicate

Returns:
type of predicate

setType

public void setType(Predicate.TYPE type)
set type of predicate

Parameters:
type - type of predicate
Throws:
IllegalStateException - if predicate type is already set

getJavaClassName

public String getJavaClassName()
Get name of Java class that defines this predicate.

Returns:
true if predicate is external, false otherwise.

setJavaClassName

public void setJavaClassName(String javaClassName)
set java class name of the predicate.

Parameters:
javaClassName - the class name to set

getFunctor

public AtomTerm getFunctor()
get functor of predicate

Returns:
the functor for the predicate. e.g. in foo(X,Y) the functor is 'foo'

getArity

public int getArity()
get arity of predicate

Returns:
the arity of the Predicate

getTag

public CompoundTermTag getTag()
get tag of predicate

Returns:
the tag of the predicate

addClauseLast

public void addClauseLast(Term clause)
Add clause for predicate at the end. This method simply add clause to predicate. No modification to term is done. It even is not copied.

Parameters:
clause - a clause to add

addClauseFirst

public void addClauseFirst(Term clause)
Add clause for predicate at the beginning. This method simply add clause to predicate. No modification to term is done. It even is not copied.

Parameters:
clause - a clause to add

removeClause

public void removeClause(Term clause)
Remove clause for predicate. This method remove first clause which is identical to clause.

Parameters:
clause - a clause to remove

arePropertiesLocked

public boolean arePropertiesLocked()
Check if properties of predicate could be changed at this moment

Returns:
true if properties of predicate could be changed at this moment

isDynamic

public boolean isDynamic()
Check if predicate is dynamic.

Returns:
true if predicate is dynamic, false otherwise.

setDynamic

public void setDynamic()
set "dynamic" property of predicate to true. This method should be called first time before any clause was added.

Throws:
IllegalStateException - if there were clauses added to predicate and dynamic flag was not set before. See 7.4.2.1 clause of ISO Prolog.

prepareClause

public static Term prepareClause(Term clause)

prepareHead

public static Term prepareHead(Term head)

prepareBody

public static Term prepareBody(Term body)

GNU Prolog for Java