diff --git a/src/java/org/apache/lucene/search/Sort.java b/src/java/org/apache/lucene/search/Sort.java
index b5fc28ca7e5..cc66b7705b1 100644
--- a/src/java/org/apache/lucene/search/Sort.java
+++ b/src/java/org/apache/lucene/search/Sort.java
@@ -18,6 +18,7 @@ package org.apache.lucene.search;
*/
import java.io.Serializable;
+import java.util.Arrays;
/**
@@ -222,4 +223,20 @@ implements Serializable {
return buffer.toString();
}
+
+ /** Returns true if o
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();
+ }
}
diff --git a/src/java/org/apache/lucene/search/SortField.java b/src/java/org/apache/lucene/search/SortField.java
index 589173d6d46..82824ba6335 100644
--- a/src/java/org/apache/lucene/search/SortField.java
+++ b/src/java/org/apache/lucene/search/SortField.java
@@ -244,4 +244,31 @@ implements Serializable {
return buffer.toString();
}
+
+ /** Returns true if o
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;
+ }
}