add hashCode and equals to filters LUCENE-439

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@328729 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2005-10-26 21:05:35 +00:00
parent d587bd1cc6
commit 1d0b4a23d5
3 changed files with 44 additions and 0 deletions

View File

@ -68,4 +68,13 @@ public class CachingWrapperFilter extends Filter {
public String toString() {
return "CachingWrapperFilter("+filter+")";
}
public boolean equals(Object o) {
if (!(o instanceof CachingWrapperFilter)) return false;
return this.filter.equals(((CachingWrapperFilter)o).filter);
}
public int hashCode() {
return filter.hashCode() ^ 0x1117BF25;
}
}

View File

@ -75,4 +75,13 @@ public class QueryFilter extends Filter {
public String toString() {
return "QueryFilter("+query+")";
}
public boolean equals(Object o) {
if (!(o instanceof QueryFilter)) return false;
return this.query.equals(((QueryFilter)o).query);
}
public int hashCode() {
return query.hashCode() ^ 0x923F64B9;
}
}

View File

@ -167,4 +167,30 @@ public class RangeFilter extends Filter {
buffer.append(includeUpper ? "]" : "}");
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 RangeFilter)) return false;
RangeFilter other = (RangeFilter) o;
if (!this.fieldName.equals(other.fieldName)
|| this.includeLower != other.includeLower
|| this.includeUpper != other.includeUpper
) { return false; }
if (this.lowerTerm != null ? !this.lowerTerm.equals(other.lowerTerm) : other.lowerTerm != null) return false;
if (this.upperTerm != null ? !this.upperTerm.equals(other.upperTerm) : other.upperTerm != null) return false;
return true;
}
/** Returns a hash code value for this object.*/
public int hashCode() {
int h = fieldName.hashCode();
h ^= lowerTerm != null ? lowerTerm.hashCode() : 0xB6ECE882;
h = (h << 1) | (h >>> 31); // rotate to distinguish lower from upper
h ^= (upperTerm != null ? (upperTerm.hashCode()) : 0x91BEC2C2);
h ^= (includeLower ? 0xD484B933 : 0)
^ (includeUpper ? 0x6AE423AC : 0);
return h;
}
}