1 package net.javacoding.jspider.core.model; 2 3 4 import net.javacoding.jspider.api.model.Decision; 5 import net.javacoding.jspider.api.model.DecisionStep; 6 7 import java.util.ArrayList ; 8 9 10 16 public class DecisionInternal implements Decision { 17 18 protected int type; 19 protected String comment; 20 protected ArrayList history; 21 22 public DecisionInternal() { 23 this(Decision.RULE_DONTCARE); 24 } 25 26 public DecisionInternal(int type) { 27 this(type, "(no comment given)"); 28 } 29 30 public DecisionInternal(int type, String comment) { 31 this.type = type; 32 this.comment = comment; 33 this.history = new ArrayList (); 34 } 35 36 public int getDecision() { 37 return type; 38 } 39 40 public String getComment() { 41 return comment; 42 } 43 44 public boolean isVetoable() { 45 if (type == Decision.RULE_ACCEPT || type == Decision.RULE_DONTCARE) { 46 return true; 47 } else { 48 return false; 49 } 50 } 51 52 public void change ( Decision other ) { 53 this.type = other.getDecision(); 54 this.comment = other.getComment(); 55 } 56 57 public void merge(Decision other) { 58 if (other.getDecision() > this.getDecision()) { 59 this.change(other); 60 } 61 } 62 63 public void addStep(String rule, int ruleType, int type, String comment) { 64 history.add(new DecisionStepInternal(rule, ruleType, type, comment)); 65 } 66 67 public DecisionStep[] getSteps() { 68 return (DecisionStep[])history.toArray(new DecisionStep[history.size()]); 69 } 70 71 public String toString() { 72 return "decision : " + translate ( type ) + " - " + getComment(); 73 } 74 75 public static String translate ( int type ) { 76 switch ( type ) { 77 case Decision.RULE_ACCEPT: 78 return "ACCEPT"; 79 case Decision.RULE_FORBIDDEN: 80 return "FORBIDDEN"; 81 case Decision.RULE_IGNORE: 82 return "IGNORE"; 83 case Decision.RULE_DONTCARE: 84 return "DON'T CARE"; 85 } 86 return "ERROR!!!"; 87 } 88 89 } 90 | Popular Tags |