net.avcompris.commons.query.impl.AbstractAlwaysXxxProxy 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 javax.annotation.Nullable;
import net.avcompris.commons.query.Filtering;
import net.avcompris.commons.query.FilteringHandler;
abstract class AbstractAlwaysXxxProxy, U extends Filtering.Field>
extends AbstractFilteringProxy {
private final boolean value;
protected AbstractAlwaysXxxProxy(final Class extends T> filteringClass, final boolean value) {
super(filteringClass);
this.value = value;
}
@Override
public boolean match(final Object arg) {
return value;
}
@Override
public void applyTo(final FilteringHandler handler) {
if (value) {
handler.setTrue();
} else {
handler.setFalse();
}
}
@Override
public final int hashCode() {
return filteringClass.hashCode() //
+ (value ? 1 : 0);
}
@Override
public final boolean equals(@Nullable final Object arg) {
if (arg == null || !(arg instanceof FilteringProxy) || !(arg instanceof AbstractAlwaysXxxProxy)) {
return false;
}
@SuppressWarnings("unchecked")
final FilteringProxy filteringProxy = (FilteringProxy) arg;
if (!filteringClass.equals(filteringProxy.getFilteringClass())) {
return false;
}
@SuppressWarnings("unchecked")
final AbstractAlwaysXxxProxy refProxy = (AbstractAlwaysXxxProxy) arg;
final boolean refValue = refProxy.value;
return value == refValue;
}
@Override
public final String toString() {
return Boolean.toString(value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy