KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > javacoding > jspider > core > model > DecisionInternal


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 JavaDoc;
8
9
10 /**
11  *
12  * $Id: DecisionInternal.java,v 1.1 2003/03/09 09:25:22 vanrogu Exp $
13  *
14  * @author Günther Van Roey
15  */

16 public class DecisionInternal implements Decision {
17
18     protected int type;
19     protected String JavaDoc comment;
20     protected ArrayList JavaDoc 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 JavaDoc comment) {
31         this.type = type;
32         this.comment = comment;
33         this.history = new ArrayList JavaDoc();
34     }
35
36     public int getDecision() {
37         return type;
38     }
39
40     public String JavaDoc 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 JavaDoc rule, int ruleType, int type, String JavaDoc 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 JavaDoc toString() {
72         return "decision : " + translate ( type ) + " - " + getComment();
73     }
74
75     public static String JavaDoc 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