filtres should implement equals and hashcode

This commit is contained in:
kimchy 2010-06-09 21:23:19 +03:00
parent 64479a11c3
commit 497b4a4f10
4 changed files with 56 additions and 1 deletions

View File

@ -34,7 +34,6 @@ import java.io.IOException;
* @author kimchy (Shay Banon)
*/
// General TODOs on FieldData
// TODO Make storing of freqs optional
// TODO Optimize the order (both int[] and int[][] when they are sparse, create an Order abstraction)
public abstract class FieldData {

View File

@ -55,4 +55,25 @@ public class AndFilter extends Filter {
}
return new AndDocSet(sets);
}
@Override public int hashCode() {
int hash = 7;
hash = 31 * hash + (null == filters ? 0 : filters.hashCode());
return hash;
}
@Override public boolean equals(Object obj) {
if (this == obj)
return true;
if ((obj == null) || (obj.getClass() != this.getClass()))
return false;
AndFilter other = (AndFilter) obj;
return equalFilters(filters, other.filters);
}
private boolean equalFilters(List<? extends Filter> filters1, List<? extends Filter> filters2) {
return (filters1 == filters2) || ((filters1 != null) && filters1.equals(filters2));
}
}

View File

@ -45,4 +45,18 @@ public class NotFilter extends Filter {
@Override public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
return new NotDocSet(DocSets.convert(reader, filter.getDocIdSet(reader)), reader.maxDoc());
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NotFilter notFilter = (NotFilter) o;
return !(filter != null ? !filter.equals(notFilter.filter) : notFilter.filter != null);
}
@Override
public int hashCode() {
return filter != null ? filter.hashCode() : 0;
}
}

View File

@ -55,4 +55,25 @@ public class OrFilter extends Filter {
}
return new OrDocSet(sets);
}
@Override public int hashCode() {
int hash = 7;
hash = 31 * hash + (null == filters ? 0 : filters.hashCode());
return hash;
}
@Override public boolean equals(Object obj) {
if (this == obj)
return true;
if ((obj == null) || (obj.getClass() != this.getClass()))
return false;
OrFilter other = (OrFilter) obj;
return equalFilters(filters, other.filters);
}
private boolean equalFilters(List<? extends Filter> filters1, List<? extends Filter> filters2) {
return (filters1 == filters2) || ((filters1 != null) && filters1.equals(filters2));
}
}