|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.jdmf.data.output.AbstractRuleElementEvaluable
net.sf.jdmf.data.output.Rule
public class Rule
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 );
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 |
---|
public Rule()
Method Detail |
---|
public boolean evaluate(Instance instance)
Evaluable.evaluate(net.sf.jdmf.data.input.attribute.Instance)
public RuleElement defineIf()
RuleElement
public RuleElement defineThen()
RuleElement
public RuleElement getLastCondition()
public RuleElement getLastConsequence()
public void merge(Rule rule)
public void addCondition(RuleElement condition)
public void addConsequence(RuleElement consequence)
public java.lang.String toString()
toString
in class java.lang.Object
public java.util.List<RuleElement> getConditions()
public java.util.List<RuleElement> getConsequences()
public void setConditions(java.util.List<RuleElement> conditions)
public void setConsequences(java.util.List<RuleElement> consequences)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |