filtres should implement equals and hashcode
This commit is contained in:
parent
64479a11c3
commit
497b4a4f10
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue