1 11 package org.eclipse.core.expressions; 12 13 import org.eclipse.core.runtime.CoreException; 14 15 27 public abstract class Expression { 28 29 42 protected static final boolean equals(final Object left, final Object right) { 43 return left == null ? right == null : ((right != null) && left 44 .equals(right)); 45 } 46 47 62 protected static final boolean equals(final Object [] leftArray, final Object [] rightArray) { 63 if (leftArray == rightArray) { 64 return true; 65 } 66 67 if (leftArray == null) { 68 return (rightArray == null); 69 } else if (rightArray == null) { 70 return false; 71 } 72 73 if (leftArray.length != rightArray.length) { 74 return false; 75 } 76 77 for (int i= 0; i < leftArray.length; i++) { 78 final Object left= leftArray[i]; 79 final Object right= rightArray[i]; 80 final boolean equal= (left == null) ? (right == null) : (left.equals(right)); 81 if (!equal) { 82 return false; 83 } 84 } 85 86 return true; 87 } 88 89 101 protected static final int hashCode(final Object object) { 102 return object != null ? object.hashCode() : 0; 103 } 104 105 116 protected static final int hashCode(final Object [] array) { 117 if (array == null) { 118 return 0; 119 } 120 int hashCode= array.getClass().getName().hashCode(); 121 for (int i= 0; i < array.length; i++) { 122 hashCode= hashCode * HASH_FACTOR + hashCode(array[i]); 123 } 124 return hashCode; 125 } 126 127 131 protected static final int HASH_CODE_NOT_COMPUTED = -1; 132 133 136 protected static final int HASH_FACTOR = 89; 137 138 141 protected static final String ATT_VALUE= "value"; 143 146 public static final Expression TRUE= new Expression() { 147 public EvaluationResult evaluate(IEvaluationContext context) { 148 return EvaluationResult.TRUE; 149 } 150 public void collectExpressionInfo(ExpressionInfo info) { 151 } 152 }; 153 154 157 public static final Expression FALSE= new Expression() { 158 public EvaluationResult evaluate(IEvaluationContext context) { 159 return EvaluationResult.FALSE; 160 } 161 public void collectExpressionInfo(ExpressionInfo info) { 162 } 163 }; 164 165 169 private transient int fHashCode= HASH_CODE_NOT_COMPUTED; 170 171 182 public abstract EvaluationResult evaluate(IEvaluationContext context) throws CoreException; 183 184 195 public final ExpressionInfo computeExpressionInfo() { 196 ExpressionInfo result= new ExpressionInfo(); 197 collectExpressionInfo(result); 198 return result; 199 } 200 201 211 public void collectExpressionInfo(ExpressionInfo info) { 212 info.addMisBehavingExpressionType(getClass()); 213 } 214 215 227 protected int computeHashCode() { 228 return super.hashCode(); 229 } 230 231 234 public int hashCode() { 235 if (fHashCode != HASH_CODE_NOT_COMPUTED) 236 return fHashCode; 237 fHashCode= computeHashCode(); 238 if (fHashCode == HASH_CODE_NOT_COMPUTED) 239 fHashCode++; 240 return fHashCode; 241 } 242 } 243 | Popular Tags |