net.sf.jdmf.data.output
Class RuleElement

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

public class RuleElement
extends AbstractRuleElementEvaluable

A single rule element that consists of an item, a logical operator that links this element to other elements within a rule; alternatively, a rule element may contain a list of subelements. The simplest rule element consists of a single item:

 (first_colour = 'red')
 
Rule elements define how items and logical operators are grouped within a rule and evaluated. Example:
 (first_colour = 'red') AND (second_colour = 'blue' OR second_colour = 'cyan')
 
There are two rule elements here: the first defines a single item (first_colour = 'red') and has no logical operator. The second rule element does not define an item, but has a logical operator (AND) and a list of two subelements. The first subelement defines a single item (second_colour = 'blue') and has no logical operator, while the second subelement also defines a single item (second_colour = 'cyan') and a logical operator (OR). Grouping is quite important if we are not satisfied with the default evaluation mode (from left to right; all logical operators are equally important here). Classes: Rule and RuleElement offer a few helpful methods allowing developers to define rules like sentences. As long as those methods are used to define rules, there is no need to worry about implementation details (and when it comes to the details - it is worth mentioning that the logical operator is always defined in the same element as the right operand of the operator). Subelements need to be defined separately and added to the parent rule element explicitly.

Author:
quorthon
See Also:
Rule, AbstractRuleElementEvaluable, Item

Constructor Summary
RuleElement()
           
RuleElement(Item item)
           
RuleElement(Item item, LogicalOperator logicalOperator)
           
 
Method Summary
 void addSubElement(RuleElement subElement)
           
 RuleElement and(Rule parentRule)
          Appends a new rule element using the AND operator.
 RuleElement attribute(java.lang.String attributeName)
          Defines the attribute name of an item.
 RuleElement doesNotEqual(java.lang.Comparable attributeValue)
          Defines the relation between the attribute name and value within an item.
 RuleElement equals(java.lang.Comparable attributeValue)
          Defines the relation between the attribute name and value within an item.
 boolean equals(java.lang.Object obj)
           
 boolean evaluate(Instance instance)
           
 Item getItem()
           
 LogicalOperator getLogicalOperator()
           
 RuleElement isGreaterThan(java.lang.Comparable attributeValue)
          Defines the relation between the attribute name and value within an item.
 RuleElement isGreaterThanOrEqualTo(java.lang.Comparable attributeValue)
          Defines the relation between the attribute name and value within an item.
 RuleElement isLowerThan(java.lang.Comparable attributeValue)
          Defines the relation between the attribute name and value within an item.
 RuleElement isLowerThanOrEqualTo(java.lang.Comparable attributeValue)
          Defines the relation between the attribute name and value within an item.
 RuleElement or(Rule parentRule)
          Appends a new rule element using the OR operator.
 void setItem(Item item)
           
 void setLogicalOperator(LogicalOperator logicalOperator)
           
 java.util.Iterator<RuleElement> subElementsIterator()
           
 java.lang.String toString()
           
 RuleElement xor(Rule parentRule)
          Appends a new rule element using the XOR operator.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RuleElement

public RuleElement()

RuleElement

public RuleElement(Item item)

RuleElement

public RuleElement(Item item,
                   LogicalOperator logicalOperator)
Method Detail

evaluate

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

attribute

public RuleElement attribute(java.lang.String attributeName)
Defines the attribute name of an item.


equals

public RuleElement equals(java.lang.Comparable attributeValue)
Defines the relation between the attribute name and value within an item.


doesNotEqual

public RuleElement doesNotEqual(java.lang.Comparable attributeValue)
Defines the relation between the attribute name and value within an item.


isGreaterThan

public RuleElement isGreaterThan(java.lang.Comparable attributeValue)
Defines the relation between the attribute name and value within an item.


isGreaterThanOrEqualTo

public RuleElement isGreaterThanOrEqualTo(java.lang.Comparable attributeValue)
Defines the relation between the attribute name and value within an item.


isLowerThan

public RuleElement isLowerThan(java.lang.Comparable attributeValue)
Defines the relation between the attribute name and value within an item.


isLowerThanOrEqualTo

public RuleElement isLowerThanOrEqualTo(java.lang.Comparable attributeValue)
Defines the relation between the attribute name and value within an item.


and

public RuleElement and(Rule parentRule)
Appends a new rule element using the AND operator.


or

public RuleElement or(Rule parentRule)
Appends a new rule element using the OR operator.


xor

public RuleElement xor(Rule parentRule)
Appends a new rule element using the XOR operator.


equals

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

toString

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

addSubElement

public void addSubElement(RuleElement subElement)

subElementsIterator

public java.util.Iterator<RuleElement> subElementsIterator()

getItem

public Item getItem()

setItem

public void setItem(Item item)

getLogicalOperator

public LogicalOperator getLogicalOperator()

setLogicalOperator

public void setLogicalOperator(LogicalOperator logicalOperator)