View Javadoc

1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.rice.krms.util;
17  
18  public class ExpressionToken implements Cloneable {
19  
20      public static int And = 1;        //TODO use AndOrButton class int instead?
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 }