1 23 24 package org.objectweb.medor.expression.lib; 25 26 import org.objectweb.medor.expression.api.Expression; 27 import org.objectweb.medor.expression.api.Operator; 28 29 import java.sql.Time ; 30 import java.sql.Timestamp ; 31 import java.text.Collator ; 32 import java.util.Date ; 33 34 38 public class Equal extends BasicComparator { 39 40 private int strength = Collator.PRIMARY; 41 42 public Equal() { 43 } 44 45 public Equal(int strength) { 46 this.strength = strength; 47 } 48 49 public Equal(Expression l, Expression r) { 50 super(l, r); 51 } 52 53 public Object clone(Object clone, java.util.Map obj2clone) throws CloneNotSupportedException { 54 clone = super.clone(clone, obj2clone); 55 ((Equal) clone).strength = strength; 56 return clone; 57 } 58 59 public boolean evaluate(Object op1, Object op2) { 60 boolean result = false; 61 if (op1 instanceof Character ) { 62 Character o1 = (Character ) op1; 63 Character o2 = (Character ) op2; 64 result = (o1.compareTo(o2) == 0); 65 } 66 else if (op1 instanceof Long ) { 67 Long o1 = (Long ) op1; 68 Long o2 = (Long ) op2; 69 result = (o1.compareTo(o2) == 0); 70 } 71 else if (op1 instanceof Short ) { 72 Short o1 = (Short ) op1; 73 Short o2 = (Short ) op2; 74 result = (o1.compareTo(o2) == 0); 75 } 76 else if (op1 instanceof Integer ) { 77 Integer o1 = (Integer ) op1; 78 Integer o2 = (Integer ) op2; 79 result = (o1.compareTo(o2) == 0); 80 } 81 else if (op1 instanceof Float ) { 82 Float o1 = (Float ) op1; 83 Float o2 = (Float ) op2; 84 result = (o1.compareTo(o2) == 0); 85 } 86 else if (op1 instanceof Double ) { 87 Double o1 = (Double ) op1; 88 Double o2 = (Double ) op2; 89 result = (o1.compareTo(o2) == 0); 90 } 91 else if (op1 instanceof Byte ) { 92 Byte o1 = (Byte ) op1; 93 Byte o2 = (Byte ) op2; 94 result = (o1.compareTo(o2) == 0); 95 } 96 else if (op1 instanceof Date ) { 97 Date o1 = (Date ) op1; 98 Date o2 = (Date ) op2; 99 result = (o1.compareTo(o2) == 0); 100 } 101 else if (op1 instanceof Time ) { 102 Time o1 = (Time ) op1; 103 Time o2 = (Time ) op2; 104 result = (o1.compareTo(o2) == 0); 105 } 106 else if (op1 instanceof Timestamp ) { 107 Timestamp o1 = (Timestamp ) op1; 108 Timestamp o2 = (Timestamp ) op2; 109 result = (o1.compareTo(o2) == 0); 110 } 111 else if (op1 instanceof String ) { 112 Collator myCollator = Collator.getInstance(); 113 myCollator.setStrength(strength); 114 String o1 = (String ) op1; 115 String o2 = (String ) op2; 116 result = (myCollator.compare(o1, o2) == 0); 117 } 118 return result; 119 } 120 121 public boolean evaluate(int op1, int op2) { 122 return (op1 == op2); 123 } 124 125 public boolean evaluate(int op1, short op2) { 126 return (op1 == op2); 127 } 128 129 public boolean evaluate(int op1, long op2) { 130 return (op1 == op2); 131 } 132 133 public boolean evaluate(int op1, float op2) { 134 return (op1 == op2); 135 } 136 137 public boolean evaluate(int op1, double op2) { 138 return (op1 == op2); 139 } 140 141 public boolean evaluate(float op1, float op2) { 142 return (op1 == op2); 143 } 144 145 public boolean evaluate(float op1, short op2) { 146 return (op1 == op2); 147 } 148 149 public boolean evaluate(float op1, int op2) { 150 return (op1 == op2); 151 } 152 153 public boolean evaluate(float op1, long op2) { 154 return (op1 == op2); 155 } 156 157 public boolean evaluate(float op1, double op2) { 158 return (op1 == op2); 159 } 160 161 public boolean evaluate(char op1, char op2) { 162 return (op1 == op2); 163 } 164 165 public boolean evaluate(long op1, short op2) { 166 return (op1 == op2); 167 } 168 169 public boolean evaluate(long op1, int op2) { 170 return (op1 == op2); 171 } 172 173 public boolean evaluate(long op1, long op2) { 174 return (op1 == op2); 175 } 176 177 public boolean evaluate(long op1, float op2) { 178 return (op1 == op2); 179 } 180 181 public boolean evaluate(long op1, double op2) { 182 return (op1 == op2); 183 } 184 185 public boolean evaluate(double op1, short op2) { 186 return (op1 == op2); 187 } 188 189 public boolean evaluate(double op1, int op2) { 190 return (op1 == op2); 191 } 192 193 public boolean evaluate(double op1, long op2) { 194 return (op1 == op2); 195 } 196 197 public boolean evaluate(double op1, float op2) { 198 return (op1 == op2); 199 } 200 201 public boolean evaluate(double op1, double op2) { 202 return (op1 == op2); 203 } 204 205 public boolean evaluate(boolean op1, boolean op2) { 206 return (op1 == op2); 207 } 208 209 public boolean evaluate(String op1, String op2) { 210 Collator myCollator = Collator.getInstance(); 211 myCollator.setStrength(strength); 212 return (myCollator.compare(op1, op2) == 0); 213 } 214 215 public String getOperatorString() { 216 return Operator.EQUAL; 217 } 218 } 219 | Popular Tags |