jeops
Class AbstractRuleBase

java.lang.Object
  |
  +--jeops.AbstractRuleBase

public abstract class AbstractRuleBase
extends java.lang.Object
implements java.lang.Cloneable

A generic rule base of Jeops. Objects of this class represent rule bases that can be treated generically by any knowledge base.

Version:
2.1 07.04.2000 Method for checking all conditions of a rule that depend on only one of the declared objects - checkConditionsOnlyOf.
Author:
Carlos Figueira Filho (csff@cin.ufpe.br)

Field Summary
private  AbstractKnowledgeBase knowledgeBase
          The knowledge base that contains this rule base.
private  int ruleIndex
          The index of the rule that has the focus.
 
Constructor Summary
AbstractRuleBase(AbstractKnowledgeBase knowledgeBase)
          Class constructor.
 
Method Summary
 void assert(java.lang.Object obj)
          Adds an object into this rule base.
abstract  boolean checkCondForDeclaration(int ruleIndex, int declIndex)
          Checks whether all the conditions of a rule which reference only the elements declared up to the given index are true.
abstract  boolean checkCondition(int ruleIndex, int condIndex)
          Checks whether a condition of some rule in this rule base is satisfied.
abstract  boolean checkConditionsOnlyOf(int ruleIndex, int declIndex)
          Checks whether all conditions of some rule that depend only on the given object are satisfied, not counting the local declarations.
 java.lang.Object clone()
          Creates a copy of this object.
 boolean equals(java.lang.Object obj)
           
 void fireRule(int ruleIndex)
          Fires one of the rules in this rule base.
 void flush()
          Removes all the objects from this rule base.
abstract  java.lang.Class getDeclaredClass(int ruleIndex, int declarationIndex)
          Returns the class of an object declared in a rule.
abstract  java.lang.String getDeclaredClassName(int ruleIndex, int declarationIndex)
          Returns the class name of an object declared in a rule.
abstract  java.lang.String[] getDeclaredIdentifiers(int ruleIndex)
          Returns the identifiers declared in a given rule.
abstract  int[] getNumberOfConditions()
          Returns the number of conditions of the rules in this rule base.
abstract  int[] getNumberOfDeclarations()
          Returns the number of declarations of the rules in this rule base.
abstract  int getNumberOfRules()
          Returns the number of rules in this base.
abstract  java.lang.Object getObject(int ruleIndex, int declarationIndex)
          Returns an object that represents a declaration of some rule.
abstract  java.lang.Object[] getObjects(int ruleIndex)
          Returns all variables bound to the declarations of some rule.
 int getRuleIndex()
          Returns the index of the rule that has the focus.
abstract  java.lang.String[] getRuleNames()
          Returns the name of the rules in this rule base.
 int hashCode()
           
protected abstract  void internalFireRule(int ruleIndex)
          Fires one of the rules in this rule base.
 void modified(java.lang.Object obj)
          Tells this base that an object was modified, so that the rules can be retested against the object.
 void retract(java.lang.Object obj)
          Removes an object from this rule base.
abstract  void setObject(int ruleIndex, int declarationIndex, java.lang.Object value)
          Sets an object that represents a declaration of some rule.
abstract  void setObjects(int ruleIndex, java.lang.Object[] objects)
          Defines all variables bound to the declarations of some rule.
 void setRuleIndex(int value)
          Defines the index of the rule that has the focus.
 
Methods inherited from class java.lang.Object
, finalize, getClass, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

knowledgeBase

private AbstractKnowledgeBase knowledgeBase
The knowledge base that contains this rule base.

ruleIndex

private int ruleIndex
The index of the rule that has the focus. A rule is said to have focus when it's ready to be fired, i.e., the variables are filled such as the rule's conditions are satisfied.
Constructor Detail

AbstractRuleBase

public AbstractRuleBase(AbstractKnowledgeBase knowledgeBase)
Class constructor.
Parameters:
knowledgeBase - the knowledge base that contains this rule base.
Method Detail

assert

public void assert(java.lang.Object obj)
Adds an object into this rule base.
Parameters:
obj - the object to be inserted into this base.

checkConditionsOnlyOf

public abstract boolean checkConditionsOnlyOf(int ruleIndex,
                                              int declIndex)
Checks whether all conditions of some rule that depend only on the given object are satisfied, not counting the local declarations.
Parameters:
ruleIndex - the index of the rule to be checked
declIndex - the index of the declaration to be checked
Returns:
true if all corresponding conditions for the given rule are satisfied; false otherwise.

checkCondForDeclaration

public abstract boolean checkCondForDeclaration(int ruleIndex,
                                                int declIndex)
Checks whether all the conditions of a rule which reference only the elements declared up to the given index are true.
Parameters:
ruleIndex - the index of the rule to be checked
declIndex - the index of the declaration to be checked
Returns:
true if all the conditions of a rule which reference only the elements declared up to the given index are satisfied; false otherwise.

checkCondition

public abstract boolean checkCondition(int ruleIndex,
                                       int condIndex)
Checks whether a condition of some rule in this rule base is satisfied.
Parameters:
ruleIndex - the index of the rule to be checked
condIndex - the index of the condition to be checked
Returns:
true if the corresponding condition for the given rule is satisfied. false otherwise.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Creates a copy of this object.
Overrides:
clone in class java.lang.Object
Returns:
a clone of this object.
Throws:
java.lang.CloneNotSupportedException - if the class Object doesn't support cloning; it should not happen.

equals

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

fireRule

public void fireRule(int ruleIndex)
Fires one of the rules in this rule base.
Parameters:
ruleIndex - the index of the rule to be fired.

flush

public void flush()
Removes all the objects from this rule base.

getDeclaredClass

public abstract java.lang.Class getDeclaredClass(int ruleIndex,
                                                 int declarationIndex)
Returns the class of an object declared in a rule.
Parameters:
ruleIndex - the index of the rule
declarationIndex - the index of the declaration.
Returns:
the class of the declared object.

getDeclaredClassName

public abstract java.lang.String getDeclaredClassName(int ruleIndex,
                                                      int declarationIndex)
Returns the class name of an object declared in a rule.
Parameters:
ruleIndex - the index of the rule
declarationIndex - the index of the declaration.
Returns:
the class name of the declared object.

getDeclaredIdentifiers

public abstract java.lang.String[] getDeclaredIdentifiers(int ruleIndex)
Returns the identifiers declared in a given rule.
Parameters:
ruleIndex - the index of the rule.
Returns:
an array with the identifiers of the rule declarations.

getNumberOfDeclarations

public abstract int[] getNumberOfDeclarations()
Returns the number of declarations of the rules in this rule base.
Returns:
the number of declarations of the rules in this rule base.

getNumberOfConditions

public abstract int[] getNumberOfConditions()
Returns the number of conditions of the rules in this rule base.
Returns:
the number of conditions of the rules in this rule base.

getNumberOfRules

public abstract int getNumberOfRules()
Returns the number of rules in this base.
Returns:
the number of rules in this base.

getObject

public abstract java.lang.Object getObject(int ruleIndex,
                                           int declarationIndex)
Returns an object that represents a declaration of some rule.
Parameters:
ruleIndex - the index of the rule
declarationIndex - the index of the declaration in the rule
Returns:
the value of the corresponding object.

getObjects

public abstract java.lang.Object[] getObjects(int ruleIndex)
Returns all variables bound to the declarations of some rule.
Parameters:
ruleIndex - the index of the rule
Returns:
an object array of the variables bound to the declarations of some rule.

getRuleIndex

public int getRuleIndex()
Returns the index of the rule that has the focus. A rule is said to have focus when it's ready to be fired, i.e., the variables are filled such as the rule's conditions are satisfied.
Returns:
the index of the rule that has the focus.

getRuleNames

public abstract java.lang.String[] getRuleNames()
Returns the name of the rules in this rule base.
Returns:
the name of the rules in this rule base.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

internalFireRule

protected abstract void internalFireRule(int ruleIndex)
Fires one of the rules in this rule base.
Parameters:
ruleIndex - the index of the rule to be fired.

modified

public void modified(java.lang.Object obj)
Tells this base that an object was modified, so that the rules can be retested against the object.
Parameters:
obj - the object that was modified.

retract

public void retract(java.lang.Object obj)
Removes an object from this rule base.
Parameters:
obj - the object to be removed from this base.

setObject

public abstract void setObject(int ruleIndex,
                               int declarationIndex,
                               java.lang.Object value)
Sets an object that represents a declaration of some rule.
Parameters:
ruleIndex - the index of the rule
declarationIndex - the index of the declaration in the rule
value - the value of the object being set.

setObjects

public abstract void setObjects(int ruleIndex,
                                java.lang.Object[] objects)
Defines all variables bound to the declarations of some rule.
Parameters:
ruleIndex - the index of the rule
objects - an an object array of the variables bound to the declarations of some rule.

setRuleIndex

public void setRuleIndex(int value)
Defines the index of the rule that has the focus. A rule is said to have focus when it's ready to be fired, i.e., the variables are filled such as the rule's conditions are satisfied.
Parameters:
value - the index of the rule that has the focus.