All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.avcompris.commons.query.impl.AbstractAlwaysXxxProxy Maven / Gradle / Ivy

There is a newer version: 0.6.3
Show newest version
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 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