001/** 002 * Copyright 2005-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krms.util; 017 018/** 019 * @author Kuali Student Team 020 */ 021public class ExpressionToken implements Cloneable { 022 023 public static final int OPERATOR_AND = 1; 024 public static final int OPERATOR_OR = 2; 025 public static final int PARENTHESIS_START = 3; 026 public static final int PARENTHESIS_END = 4; 027 public static final int CONDITION = 5; 028 029 private String value; 030 private int type; 031 private String tokenID = ""; 032 033 public String getTokenID() { 034 return tokenID; 035 } 036 037 public void setTokenID(String tokenID) { 038 this.tokenID = tokenID; 039 } 040 041 public int getType() { 042 return type; 043 } 044 045 public void setType(int type) { 046 this.type = type; 047 } 048 049 public String getValue() { 050 return value; 051 } 052 053 public void setValue(String value) { 054 this.value = value; 055 } 056 057 public static ExpressionToken createAndToken(){ 058 ExpressionToken t = new ExpressionToken(); 059 t.type = OPERATOR_AND; 060 t.value = "and"; 061 return t; 062 } 063 064 public static ExpressionToken createOrToken(){ 065 ExpressionToken t = new ExpressionToken(); 066 t.type = OPERATOR_OR; 067 t.value = "or"; 068 return t; 069 } 070 071 public ExpressionToken toggleAndOr(){ 072 ExpressionToken t = new ExpressionToken (); 073 if(type == OPERATOR_AND){ 074 t.type = OPERATOR_OR; 075 t.value = "Or"; 076 077 }else if(type == OPERATOR_OR){ 078 t.type = OPERATOR_AND; 079 t.value = "And"; 080 } 081 return t; 082 } 083 084 public boolean equals(Object obj){ 085 if(obj instanceof ExpressionToken == false){ 086 return false; 087 } 088 ExpressionToken t = (ExpressionToken)obj; 089 if(t.value == null){ 090 return false; 091 } 092 if(t.value.equals(value) && t.type == type){ 093 return true; 094 } 095 return false; 096 } 097 098 public int hashCode(){ 099 int hash =1; 100 hash = hash * 31 + new Integer(type).hashCode(); 101 hash = hash * 31 + (value == null ? 0 : value.hashCode()); 102 return hash; 103 } 104 105 public ExpressionToken clone(){ 106 ExpressionToken t = new ExpressionToken(); 107 t.type = type; 108 t.value = value; 109 return t; 110 } 111 112 public String toString() { 113 if (type == OPERATOR_AND) { 114 return "and"; 115 } else if (type == OPERATOR_OR) { 116 return "or"; 117 } else if (type == PARENTHESIS_START) { 118 return "("; 119 } else if (type == PARENTHESIS_END) { 120 return ")"; 121 } else if (type == CONDITION) { 122 return value; 123 } 124 return ""; 125 } 126}