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

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

There is a newer version: 0.6.3
Show newest version
package net.avcompris.commons.query.impl;

import static net.avcompris.commons.query.Filtering.Type.AND;

import java.util.Arrays;

import net.avcompris.commons.query.And;
import net.avcompris.commons.query.Filtering;
import net.avcompris.commons.query.FilteringHandler;

final class AndProxy, U extends Filtering.Field> extends AbstractConnectorProxy
		implements And {

	public AndProxy(final Class filteringClass, final Filtering[] fs) {

		super(filteringClass, "and", fs);
	}

	public AndProxy(final Class filteringClass, final Filtering f1, final Filtering f2) {

		super(filteringClass, "and", f1, f2);
	}

	public AndProxy(final Class filteringClass, final Filtering f, final Filtering[] fs) {

		super(filteringClass, "and", f, fs);
	}

	public AndProxy(final Class filteringClass, final Filtering[] fs1, final Filtering[] fs2) {

		super(filteringClass, "and", fs1, fs2);
	}

	public AndProxy(final Class filteringClass, final Filtering[] fs, final Filtering f) {

		super(filteringClass, "and", fs, f);
	}

	@Override
	public boolean match(final Object arg) {

		for (final Filtering f : fs) {

			if (!f.match(arg)) {

				return false;
			}
		}

		return true;
	}

	@Override
	public void applyTo(final FilteringHandler handler) {

		for (final Filtering f : fs) {

			final FilteringHandler subHandler = handler.newAndMember();

			f.applyTo(subHandler);
		}
	}

	@Override
	public Type getType() {

		return AND;
	}

	@Override
	public Filtering[] getArgs() {

		return Arrays.copyOf(fs, fs.length);
	}
}