lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r724379 - in /lucene/java/trunk/src/java/org/apache/lucene/search: Sort.java SortField.java
Date Mon, 08 Dec 2008 15:28:17 GMT
Author: mikemccand
Date: Mon Dec  8 07:28:16 2008
New Revision: 724379

URL: http://svn.apache.org/viewvc?rev=724379&view=rev
Log:
LUCENE-1481: implement equals() and hashCode() for Sort & SortField

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/search/Sort.java
    lucene/java/trunk/src/java/org/apache/lucene/search/SortField.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/Sort.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/Sort.java?rev=724379&r1=724378&r2=724379&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/Sort.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/Sort.java Mon Dec  8 07:28:16 2008
@@ -18,6 +18,7 @@
  */
 
 import java.io.Serializable;
+import java.util.Arrays;
 
 
 /**
@@ -222,4 +223,20 @@
 
     return buffer.toString();
   }
+
+  /** Returns true if <code>o</code> is equal to this. */
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof Sort)) return false;
+    final Sort other = (Sort)o;
+    return Arrays.equals(this.fields, other.fields);
+  }
+
+  /** Returns a hash code value for this object. */
+  public int hashCode() {
+    // TODO in Java 1.5: switch to Arrays.hashCode().  The 
+    // Java 1.4 workaround below calculates the same hashCode
+    // as Java 1.5's new Arrays.hashCode()
+    return 0x45aaf665 + Arrays.asList(fields).hashCode();
+  }
 }

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/SortField.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/SortField.java?rev=724379&r1=724378&r2=724379&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/SortField.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/SortField.java Mon Dec  8 07:28:16
2008
@@ -244,4 +244,31 @@
 
     return buffer.toString();
   }
+
+  /** Returns true if <code>o</code> is equal to this.  If a
+   *  {@link #SortComparatorSource} was provided, it must
+   *  properly implement equals. */
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof SortField)) return false;
+    final SortField other = (SortField)o;
+    return (
+      other.field == this.field // field is always interned
+      && other.type == this.type
+      && other.reverse == this.reverse
+      && (other.locale == null ? this.locale == null : other.locale.equals(this.locale))
+      && (other.factory == null ? this.factory == null : other.factory.equals(this.factory))
+    );
+  }
+
+  /** Returns a hash code value for this object.  If a
+   *  {@link #SortComparatorSource} was provided, it must
+   *  properly implement hashCode. */
+  public int hashCode() {
+    int hash=type^0x346565dd + Boolean.valueOf(reverse).hashCode()^0xaf5998bb;
+    if (field != null) hash += field.hashCode()^0xff5685dd;
+    if (locale != null) hash += locale.hashCode()^0x08150815;
+    if (factory != null) hash += factory.hashCode()^0x34987555;
+    return hash;
+  }
 }



Mime
View raw message