net.avcompris.commons.query.impl.NotProxy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of avc-commons3-query Show documentation
Show all versions of avc-commons3-query Show documentation
Common classes for avc-commons3 queries and filtering.
package net.avcompris.commons.query.impl;
import static com.google.common.base.Preconditions.checkNotNull;
import static net.avcompris.commons.query.Filtering.Type.NOT;
import javax.annotation.Nullable;
import net.avcompris.commons.query.Filtering;
import net.avcompris.commons.query.FilteringHandler;
import net.avcompris.commons.query.Not;
final class NotProxy, U extends Filtering.Field> extends AbstractFilteringProxy
implements Not {
private final Filtering f;
public NotProxy(final Class extends T> filteringClass, final Filtering f) {
super(filteringClass);
this.f = checkNotNull(f, "f");
}
@Override
public boolean match(final Object arg) {
return !f.match(arg);
}
@Override
public void applyTo(final FilteringHandler handler) {
final FilteringHandler subHandler = handler.newNotMember();
f.applyTo(subHandler);
}
@Override
public int hashCode() {
return 10_000 - 2 * f.hashCode();
}
@Override
public boolean equals(@Nullable final Object arg) {
if (arg == null || !(arg instanceof FilteringProxy)) {
return false;
}
@SuppressWarnings("unchecked")
final FilteringProxy filteringProxy = (FilteringProxy) arg;
if (!filteringClass.equals(filteringProxy.getFilteringClass())) {
return false;
}
final NotProxy refProxy = (NotProxy) filteringProxy.getImpl();
return f.equals(refProxy.f);
}
@Override
public String toString() {
return "not(" + f + ")";
}
@Override
public Type getType() {
return NOT;
}
@Override
public Filtering getArg() {
return f;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy