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

net.avcompris.commons.query.impl.OrProxy 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.OR;

import java.util.Arrays;

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

final class OrProxy, U extends Filtering.Field> extends AbstractConnectorProxy
		implements Or {

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

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

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

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

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

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

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

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

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

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

	@Override
	public boolean match(final Object arg) {

		for (final Filtering f : fs) {

			if (f.match(arg)) {

				return true;
			}
		}

		return false;
	}

	@Override
	public void applyTo(final FilteringHandler handler) {

		for (final Filtering f : fs) {

			final FilteringHandler subHandler = handler.newOrMember();

			f.applyTo(subHandler);
		}
	}

	@Override
	public Type getType() {

		return OR;
	}

	@Override
	public Filtering[] getArgs() {

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