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