mirror of https://github.com/apache/lucene.git
LUCENE-1481: implement equals() and hashCode() for Sort & SortField
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@724379 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
62c7438ed4
commit
e0efcd52ea
|
@ -18,6 +18,7 @@ package org.apache.lucene.search;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -222,4 +223,20 @@ implements Serializable {
|
||||||
|
|
||||||
return buffer.toString();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,4 +244,31 @@ implements Serializable {
|
||||||
|
|
||||||
return buffer.toString();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue