1 23 package org.mdarad.framework.expr; 24 25 import java.util.Collection ; 26 import java.util.Hashtable ; 27 import java.util.Iterator ; 28 import java.util.Locale ; 29 import java.util.Map ; 30 31 49 public class OperatorTypes { 50 51 52 55 protected static Map operatorTypes = new Hashtable (); 56 57 58 62 public static OperatorType EQUAL = new OperatorType(new String ("EQUAL"), "EQUAL"); 63 66 public static OperatorType LOWER_THAN = new OperatorType(new String ("LOWER_THAN"), "LOWER_THAN"); 67 70 public static OperatorType LOWER_THAN_OR_EQUAL = new OperatorType(new String ("LOWER_OR_EQUAL"), "LOWER_OR_EQUAL"); 71 74 public static OperatorType GREATER_THAN = new OperatorType(new String ("GREATER_THAN"), "GREATER_THAN"); 75 78 public static OperatorType GREATER_THAN_OR_EQUAL = new OperatorType(new String ("GREATER_THAN_OR_EQUAL"), "GREATER_THAN_OR_EQUAL"); 79 82 public static OperatorType BOOLEAN = new OperatorType(new String ("BOOLEAN"), "BOOLEAN"); 83 86 public static OperatorType LIKE = new OperatorType(new String ("LIKE"), "LIKE"); 87 90 public static OperatorType START_WITH = new OperatorType(new String ("START_WITH"), "START_WITH"); 91 94 public static OperatorType END_WITH = new OperatorType(new String ("END_WITH"), "END_WITH"); 95 98 public static OperatorType IN = new OperatorType(new String ("IN"), "IN"); 99 100 101 static { 103 add(EQUAL); 104 add(LOWER_THAN); 105 add(GREATER_THAN); 106 add(LOWER_THAN_OR_EQUAL); 107 add(GREATER_THAN_OR_EQUAL); 108 add(BOOLEAN); 109 110 } 111 112 113 118 protected static final void add(OperatorType allowable) { 119 operatorTypes.put(allowable.getValue(), allowable); 120 } 121 122 131 public static OperatorType getAllowableOperators(String value) { 132 if( value == null) { 134 return null; 135 } 136 137 OperatorType allowable = (OperatorType) operatorTypes.get(value); 139 140 if (allowable == null) { 142 throw new IllegalStateException ("Code:" + value); 143 } 144 145 return allowable; 146 } 147 148 154 public static String [] getAllowableLabels(Locale locale) { 155 if (locale == null) 157 throw new IllegalArgumentException ("The locale object must not be null to retreive the labels"); 158 159 String [] labels = new String [operatorTypes.size()]; 161 int i = 0; 162 Iterator iterator = operatorTypes.values().iterator(); 163 while(iterator.hasNext()) { 166 OperatorType allowable = (OperatorType) iterator.next(); 167 labels[i++] = allowable.getLabel(); } 169 return labels; 170 } 171 172 178 public static Collection getAllowableValues() { 179 return operatorTypes.keySet(); 180 } 181 182 186 public String toString () { 187 return operatorTypes.toString(); 188 } 189 190 191 } 192 | Popular Tags |