1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.util;
17
18 public class ExpressionToken implements Cloneable {
19
20 public static int And = 1;
21 public static int Or = 2;
22 public static int StartParenthesis = 3;
23 public static int EndParenthesis = 4;
24 public static int Condition = 5;
25 public String value;
26 public int type;
27 private String tokenID = "";
28
29 public String getTokenID() {
30 return tokenID;
31 }
32
33 public void setTokenID(String tokenID) {
34 this.tokenID = tokenID;
35 }
36
37 public int getType() {
38 return type;
39 }
40
41 public void setType(int type) {
42 this.type = type;
43 }
44
45 public static ExpressionToken createAndToken(){
46 ExpressionToken t = new ExpressionToken();
47 t.type = And;
48 t.value = "and";
49 return t;
50 }
51
52 public static ExpressionToken createOrToken(){
53 ExpressionToken t = new ExpressionToken();
54 t.type = Or;
55 t.value = "or";
56 return t;
57 }
58
59 public ExpressionToken toggleAndOr(){
60 ExpressionToken t = new ExpressionToken ();
61 if(type == And){
62 t.type = Or;
63 t.value = "Or";
64
65 }else if(type == Or){
66 t.type = And;
67 t.value = "And";
68 }
69 return t;
70 }
71
72 public boolean equals(Object obj){
73 if(obj instanceof ExpressionToken == false){
74 return false;
75 }
76 ExpressionToken t = (ExpressionToken)obj;
77 if(t.value == null){
78 return false;
79 }
80 if(t.value.equals(value) && t.type == type){
81 return true;
82 }
83 return false;
84 }
85
86 public int hashCode(){
87 int hash =1;
88 hash = hash * 31 + new Integer(type).hashCode();
89 hash = hash * 31 + (value == null ? 0 : value.hashCode());
90 return hash;
91 }
92
93 public ExpressionToken clone(){
94 ExpressionToken t = new ExpressionToken();
95 t.type = type;
96 t.value = value;
97 return t;
98 }
99
100 public String toString() {
101 if (type == And) {
102 return "and";
103 } else if (type == Or) {
104 return "or";
105 } else if (type == StartParenthesis) {
106 return "(";
107 } else if (type == EndParenthesis) {
108 return ")";
109 } else if (type == Condition) {
110 return value;
111 }
112 return "";
113 }
114 }