Menu

How to use DecisionRuleVector

/
* Make example.
*
* @return the vector
/
private static Vector<decisionrule> makeExample() {
// Originally first c1 then c2, start building a decision table
Vector<decisionrule> rules = new Vector<decisionrule>();
// column 1
DecisionRule rule = new DecisionRule();
rule.addCondition(new ConditionPair("C1", "Y"));
rule.addCondition(new ConditionPair("C2", "N"));
rule.addAction(new ActionPair("A1", "</decisionrule></decisionrule></decisionrule>
"));
rule.addAction(new ActionPair("A2", "/"));
rules.add(rule);

    // column 2
    rule = new DecisionRule();
    rule.addCondition(new ConditionPair("C1", "Y"));
    rule.addCondition(new ConditionPair("C2", "Y"));
    rule.addAction(new ActionPair("A1", "/"));
    rule.addAction(new ActionPair("A2", "/"));
    rules.add(rule);

    // column 3
    rule = new DecisionRule();
    rule.addCondition(new ConditionPair("C1", "N"));
    rule.addCondition(new ConditionPair("C2", "N"));
    rule.addAction(new ActionPair("A1", "*"));
    rule.addAction(new ActionPair("A2", "/"));
    rules.add(rule);

    // column 4
    rule = new DecisionRule();
    rule.addCondition(new ConditionPair("C1", "N"));
    rule.addCondition(new ConditionPair("C2", "Y"));
    rule.addAction(new ActionPair("A1", "*"));
    rule.addAction(new ActionPair("A2", "/"));
    rules.add(rule);
    // finish building the decision table

    DecisionTable dt = new DecisionTable();
    String[][] content = dt.getTableContent(rules);
    System.out.println("-----------Table Example-------------");
    System.out.println(dt.getInfo(content));

    return rules;
}

/**
 * The main method.
 * 
 * @param args
 *            the arguments
 */
public static void main(String[] args) {
    Vector<DecisionRule> rules = makeExample();

    DecisionRule rule = new DecisionRule();
    rule.addCondition(new ConditionPair("C1", "Y"));
    rule.addCondition(new ConditionPair("C2", "N"));
    rule.addAction(new ActionPair("A1", "*"));
    rule.addAction(new ActionPair("A2", "/"));

    // true
    DecisionRuleVector vec = new DecisionRuleVector();
    System.out.println(vec.exist(rules, rule));

    // false
    rule.getActions().get(0).setActionEntry("/");
    System.out.println(vec.exist(rules, rule));

    rule.getActions().clear();
    rule.getConditions().clear();
    rule.addCondition(new ConditionPair("C2", "N"));
    rule.addCondition(new ConditionPair("C1", "Y"));
    rule.addAction(new ActionPair("A2", "/"));
    rule.addAction(new ActionPair("A1", "*"));

    // true
    System.out.println(vec.exist(rules, rule));

    // false
    rule.getActions().clear();
    rule.getConditions().clear();
    rule.addCondition(new ConditionPair("C1", "Y"));
    rule.addCondition(new ConditionPair("C2", "Y"));
    rule.addAction(new ActionPair("A1", "*"));
    rule.addAction(new ActionPair("A2", "/"));
    System.out.println(vec.exist(rules, rule));
}
Posted by Yan Tang Demey 2012-10-18

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.