Revision: 15301
          http://gate.svn.sourceforge.net/gate/?rev=15301&view=rev
Author:   valyt
Date:     2012-02-02 10:15:29 +0000 (Thu, 02 Feb 2012)
Log Message:
-----------
Re-implemented hashCode and equals (actually got Eclipse to do it), as the old 
versions were defective.

Modified Paths:
--------------
    gate/trunk/src/gate/jape/constraint/AbstractConstraintPredicate.java
    gate/trunk/src/gate/jape/constraint/EmbeddedConstraintPredicate.java

Modified: gate/trunk/src/gate/jape/constraint/AbstractConstraintPredicate.java
===================================================================
--- gate/trunk/src/gate/jape/constraint/AbstractConstraintPredicate.java        
2012-02-02 02:27:29 UTC (rev 15300)
+++ gate/trunk/src/gate/jape/constraint/AbstractConstraintPredicate.java        
2012-02-02 10:15:29 UTC (rev 15301)
@@ -38,37 +38,38 @@
     setValue(value);
   }
 
+  public String toString() {
+    // If value is a String, quote it. Otherwise (for things like
+    // Numbers), don't.
+    Object val = getValue();
+    if(val instanceof String) val = "\"" + val + "\"";
+    return accessor + " " + getOperator() + " " + val;
+  }
+
+  @Override
   public int hashCode() {
-    int hashCode = getOperator().hashCode();
-    hashCode = 37 * hashCode + ((accessor != null) ? accessor.hashCode() : 0);
-    hashCode = 37 * hashCode + ((value != null) ? value.hashCode() : 0);
-    return hashCode;
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((accessor == null) ? 0 : accessor.hashCode());
+    result = prime * result + ((value == null) ? 0 : value.hashCode());
+    return result;
   }
 
+  @Override
   public boolean equals(Object obj) {
+    if(this == obj) return true;
     if(obj == null) return false;
-    if(obj == this) return true;
-    if(!(this.getClass().equals(obj.getClass()))) return false;
-
-    ConstraintPredicate a = (ConstraintPredicate)obj;
-
-    if(accessor != a.getAccessor() && accessor != null
-            && !accessor.equals(a.getAccessor())) return false;
-
-    if(value != a.getValue() && value != null && !value.equals(a.getValue()))
-      return false;
-
+    if(!(obj instanceof AbstractConstraintPredicate)) return false;
+    AbstractConstraintPredicate other = (AbstractConstraintPredicate)obj;
+    if(accessor == null) {
+      if(other.accessor != null) return false;
+    } else if(!accessor.equals(other.accessor)) return false;
+    if(value == null) {
+      if(other.value != null) return false;
+    } else if(!value.equals(other.value)) return false;
     return true;
   }
 
-  public String toString() {
-    // If value is a String, quote it. Otherwise (for things like
-    // Numbers), don't.
-    Object val = getValue();
-    if(val instanceof String) val = "\"" + val + "\"";
-    return accessor + " " + getOperator() + " " + val;
-  }
-
   public boolean matches(Annotation annot, AnnotationSet context) throws 
JapeException {
     //get the appropriate value using the accessor and then have
     //concrete subclasses do the eval

Modified: gate/trunk/src/gate/jape/constraint/EmbeddedConstraintPredicate.java
===================================================================
--- gate/trunk/src/gate/jape/constraint/EmbeddedConstraintPredicate.java        
2012-02-02 02:27:29 UTC (rev 15300)
+++ gate/trunk/src/gate/jape/constraint/EmbeddedConstraintPredicate.java        
2012-02-02 10:15:29 UTC (rev 15301)
@@ -110,11 +110,36 @@
   public String toString() {
     StringBuilder str = new StringBuilder();
     str.append(getOperator()).append(" ");
-    if(annotType != null)  str.append(annotType).append(": ");
-    if(valueConstraint != null) str.append(valueConstraint);
+    if(annotType != null)  str.append(annotType);
+    if(valueConstraint != null){
+      str.append(": ").append(valueConstraint);
+    }
     return str.toString();
   }
   
-  
-  
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = super.hashCode();
+    result = prime * result + ((annotType == null) ? 0 : annotType.hashCode());
+    result =
+        prime * result
+            + ((valueConstraint == null) ? 0 : valueConstraint.hashCode());
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if(this == obj) return true;
+    if(!super.equals(obj)) return false;
+    if(!(obj instanceof EmbeddedConstraintPredicate)) return false;
+    EmbeddedConstraintPredicate other = (EmbeddedConstraintPredicate)obj;
+    if(annotType == null) {
+      if(other.annotType != null) return false;
+    } else if(!annotType.equals(other.annotType)) return false;
+    if(valueConstraint == null) {
+      if(other.valueConstraint != null) return false;
+    } else if(!valueConstraint.equals(other.valueConstraint)) return false;
+    return true;
+  }
 }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to