net.sf.jdmf.data.output
Class Rule

java.lang.Object
  extended by net.sf.jdmf.data.output.AbstractRuleElementEvaluable
      extended by net.sf.jdmf.data.output.Rule
All Implemented Interfaces:
Evaluable

public class Rule
extends AbstractRuleElementEvaluable

Defines a rule as a set of conditions and consequences. Example:

 IF (first_colour = 'red') AND (second_colour = 'blue')
     THEN (mixed_colour = 'magenta') OR (colour_count > 256)
 
Conditions appear between IF and THEN, consequences - after THEN. The expressions between logical operators are called rule elements. Defining rules is quite simple. Classes: Rule and RuleElement offer a few helpful methods allowing developers to define rules like sentences. The above example could be defined like this:
 Rule magentaRule = new Rule();
 magentaRule.defineIf().attribute( "first_colour" ).equals( "red" )
     .and( magentaRule ).attribute( "second_colour" ).equals( "blue" );
 magentaRule.defineThen().attribute( "mixed_colour" ).equals( "magenta" )
     .or( magentaRule ).attribute( "colour_count" ).isGreaterThan( 256 );
 

Author:
quorthon
See Also:
RuleElement

Constructor Summary
Rule()
           
 
Method Summary
 void addCondition(RuleElement condition)
           
 void addConsequence(RuleElement consequence)
           
 RuleElement defineIf()
          Allows to define conditions.
 RuleElement defineThen()
          Allows to define consequences.
 boolean evaluate(Instance instance)
           
 java.util.List<RuleElement> getConditions()
           
 java.util.List<RuleElement> getConsequences()
           
 RuleElement getLastCondition()
           
 RuleElement getLastConsequence()
           
 void merge(Rule rule)
          Merges the given rule into this rule (appends the conditions and consequences of the given rule to this rule's conditions and consequences).
 void setConditions(java.util.List<RuleElement> conditions)
           
 void setConsequences(java.util.List<RuleElement> consequences)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Rule

public Rule()
Method Detail

evaluate

public boolean evaluate(Instance instance)
See Also:
Evaluable.evaluate(net.sf.jdmf.data.input.attribute.Instance)

defineIf

public RuleElement defineIf()
Allows to define conditions. REMOVES all previous conditions. Appending conditions can be achieved only by retrieving the last condition and using methods like and(), or(), xor().

See Also:
RuleElement

defineThen

public RuleElement defineThen()
Allows to define consequences. REMOVES all previous consequences. Appending consequences can be achieved only by retrieving the last consequence and using methods like and(), or(), xor().

See Also:
RuleElement

getLastCondition

public RuleElement getLastCondition()

getLastConsequence

public RuleElement getLastConsequence()

merge

public void merge(Rule rule)
Merges the given rule into this rule (appends the conditions and consequences of the given rule to this rule's conditions and consequences).


addCondition

public void addCondition(RuleElement condition)

addConsequence

public void addConsequence(RuleElement consequence)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getConditions

public java.util.List<RuleElement> getConditions()

getConsequences

public java.util.List<RuleElement> getConsequences()

setConditions

public void setConditions(java.util.List<RuleElement> conditions)

setConsequences

public void setConsequences(java.util.List<RuleElement> consequences)