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

fr.landel.utils.assertor.OperatorAnd Maven / Gradle / Ivy

/*-
 * #%L
 * utils-assertor
 * %%
 * Copyright (C) 2016 - 2018 Gilles Landel
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
package fr.landel.utils.assertor;

import java.time.temporal.Temporal;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
import java.util.function.Function;

import fr.landel.utils.assertor.enums.EnumAnalysisMode;
import fr.landel.utils.assertor.enums.EnumOperator;
import fr.landel.utils.assertor.enums.EnumType;
import fr.landel.utils.assertor.helper.HelperStep;

/**
 * This class is an intermediate link in Assertor chain, see
 * {@link AssertorStep}.
 *
 * @since Mar 28, 2017
 * @author Gilles
 *
 * @param 
 *            the type of predicate step
 * @param 
 *            the type of checked object
 */
public interface OperatorAnd, T> {

    /**
     * @return the step result
     */
    StepAssertor getStep();

    /**
     * The only purpose is to avoid the copy of basic methods into children
     * interfaces. This is an indirect way to create specific {@link Step} by
     * overriding this interface. All children class has to override this method
     * 
     * @param result
     *            the result
     * @return the predicate step
     */
    S get(StepAssertor result);

    /**
     * Applies a predicate step in the current one with the operator
     * {@link EnumOperator#AND}. The aim of this is to provide the equivalence
     * of parenthesis in condition expressions.
     * 
     * 
     * // '' null or not empty and 'text' null or not empty
     * Assertor.that("").isNull().or().isNotEmpty().and("text").isNull().or().isNotEmpty().isOK();
     * // -> true (because: false or false and false or true, false or false =
     * // false => false and false = false => false or true = true)
     * 
     * // ('' null or not empty) and ('text' null or not empty)
     * Assertor.that("").isNull().or().isNotEmpty().and(Assertor.that("text").isNull().or().isNotEmpty()).isOK();
     * // -> false (because: (false or false) and (false or true) => false and
     * // true = false)
     * 
     * 
* * @param other * the other predicate step * @param * The type of other checked object * @param * The {@linkplain Step} type * @return this predicate step with the other injected */ default > S and(final Step other) { return this.get(HelperStep.and(this.getStep(), other.getStep())); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check another object. * * @param other * the other or next checked object to check * @param * the object type * @param * the type of predicate * @return the predicate assertor */ default > AssertorStep and(final X other) { return this.and(other, null); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check another object. * * @param other * the other or next checked object to check * @param analysisMode * the preferred analysis mode * @param * the object type * @param * the type of predicate * @return the predicate assertor */ default > AssertorStep and(final X other, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), other, EnumType.getType(other), analysisMode); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check a {@link Boolean}. * * @param other * the other or next checked {@link Boolean} to check * @return the predicate assertor */ default AssertorStepBoolean and(final Boolean other) { return this.and(other, null); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check a {@link Boolean}. * * @param other * the other or next checked {@link Boolean} to check * @param analysisMode * the preferred analysis mode * @return the predicate assertor */ default AssertorStepBoolean and(final Boolean other, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), other, EnumType.BOOLEAN, analysisMode); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check a {@link CharSequence}. * * @param other * the other or next checked {@link CharSequence} to check * @param * the {@link CharSequence} type * @return the predicate assertor */ default AssertorStepCharSequence and(final X other) { return this.and(other, null); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check a {@link CharSequence}. * * @param other * the other or next checked {@link CharSequence} to check * @param analysisMode * the preferred analysis mode * @param * the {@link CharSequence} type * @return the predicate assertor */ default AssertorStepCharSequence and(final X other, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), other, EnumType.CHAR_SEQUENCE, analysisMode); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check a {@link Number}. * * @param other * the other or next checked {@link Number} to check * @param * the {@link Number} type * @return the predicate assertor */ default > AssertorStepNumber and(final N other) { return this.and(other, null); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check a {@link Number}. * * @param other * the other or next checked {@link Number} to check * @param analysisMode * the preferred analysis mode * @param * the {@link Number} type * @return the predicate assertor */ default > AssertorStepNumber and(final N other, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), other, EnumType.getType(other), analysisMode); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check an {@code array}. * * @param other * the other or next checked {@code array} to check * @param * the array elements type * @return the predicate assertor */ default AssertorStepArray and(final X[] other) { return this.and(other, null); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check an {@code array}. * * @param other * the other or next checked {@code array} to check * @param analysisMode * the preferred analysis mode * @param * the array elements type * @return the predicate assertor */ default AssertorStepArray and(final X[] other, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), other, EnumType.ARRAY, analysisMode); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check a {@link Class}. * * @param other * the other or next checked {@link Class} to check * @param * the {@link Class} type * @return the predicate assertor */ default AssertorStepClass and(final Class other) { return this.and(other, null); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check a {@link Class}. * * @param other * the other or next checked {@link Class} to check * @param analysisMode * the preferred analysis mode * @param * the {@link Class} type * @return the predicate assertor */ default AssertorStepClass and(final Class other, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), other, EnumType.CLASS, analysisMode); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check a {@link Map}. * * @param other * the other or next checked {@link Map} to check * @param * the {@link Map} key elements type * @param * the {@link Map} value elements type * @return the predicate assertor */ default AssertorStepMap and(final Map other) { return this.and(other, null); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check a {@link Map}. * * @param other * the other or next checked {@link Map} to check * @param analysisMode * the preferred analysis mode * @param * the {@link Map} key elements type * @param * the {@link Map} value elements type * @return the predicate assertor */ default AssertorStepMap and(final Map other, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), other, EnumType.MAP, analysisMode); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check an {@link Iterable}. * * @param other * the other or next checked {@link Iterable} to check * @param * the {@link Iterable} type * @param * the {@link Iterable} elements type * @return the predicate assertor */ default , X> AssertorStepIterable and(final I other) { return this.and(other, null); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check an {@link Iterable}. * * @param other * the other or next checked {@link Iterable} to check * @param analysisMode * the preferred analysis mode * @param * the {@link Iterable} type * @param * the {@link Iterable} elements type * @return the predicate assertor */ default , X> AssertorStepIterable and(final I other, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), other, EnumType.ITERABLE, analysisMode); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check a {@link Date}. * * @param other * the other or next checked {@link Date} to check * @return the predicate assertor */ default AssertorStepDate and(final Date other) { return this.and(other, null); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check a {@link Date}. * * @param other * the other or next checked {@link Date} to check * @param analysisMode * the preferred analysis mode * @return the predicate assertor */ default AssertorStepDate and(final Date other, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), other, EnumType.DATE, analysisMode); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check a {@link Calendar}. * * @param other * the other or next checked {@link Calendar} to check * @return the predicate assertor */ default AssertorStepCalendar and(final Calendar other) { return this.and(other, null); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check a {@link Calendar}. * * @param other * the other or next checked {@link Calendar} to check * @param analysisMode * the preferred analysis mode * @return the predicate assertor */ default AssertorStepCalendar and(final Calendar other, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), other, EnumType.CALENDAR, analysisMode); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check a comparable {@link Temporal}. * * @param other * the other or next checked {@link Temporal} to check * @param * the temporal type * @return the predicate assertor */ default > AssertorStepTemporal and(final X other) { return this.and(other, null); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check a comparable {@link Temporal}. * * @param other * the other or next checked {@link Temporal} to check * @param analysisMode * the preferred analysis mode * @param * the temporal type * @return the predicate assertor */ default > AssertorStepTemporal and(final X other, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), other, EnumType.TEMPORAL, analysisMode); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check a comparable {@link Throwable}. * * @param other * the other or next checked {@link Throwable} to check * @param * the throwable type * @return the predicate assertor */ default AssertorStepThrowable and(final X other) { return this.and(other, null); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check a comparable {@link Throwable}. * * @param other * the other or next checked {@link Throwable} to check * @param analysisMode * the preferred analysis mode * @param * the throwable type * @return the predicate assertor */ default AssertorStepThrowable and(final X other, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), other, EnumType.THROWABLE, analysisMode); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check an {@link Enum}. * * @param other * the other or next checked {@link Enum} to check * @param * the type of the {@link Enum} * @return the predicate assertor */ default > AssertorStepEnum and(final X other) { return this.and(other, null); } /** * Append an operator '{@link EnumOperator#AND}' on the current step with * the ability to check an {@link Enum}. * * @param other * the other or next checked {@link Enum} to check * @param analysisMode * the preferred analysis mode * @param * the type of the {@link Enum} * @return the predicate assertor */ default > AssertorStepEnum and(final X other, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), other, EnumType.ENUMERATION, analysisMode); } /** * Append an operator '{@link EnumOperator#AND}' on the current step. * * @return the predicate assertor */ default AssertorStep and() { return () -> HelperStep.and(this.getStep()); } /** * Append a sub-assertor with the operator {@link EnumOperator#AND} on the * current step. Be sure you sub-assertor manage {@code null} values. * * @param subAssertor * the sub-assertor * @param * the predicate step type expected * @param * the type of the checked sub-object * @return the predicate step */ default , Y> S andAssertor(final Function subAssertor) { return this.get(HelperStep.and(this.getStep(), subAssertor)); } /** * Append an object through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param * the predicate step type expected * @param * the type of the checked sub-object * @return the assertor step */ default > AssertorStep andObject(final Function mapper) { return this.andObject(mapper, null); } /** * Append an object through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param analysisMode * the analysis mode ({@link EnumAnalysisMode#STANDARD}, * {@link EnumAnalysisMode#STREAM} or * {@link EnumAnalysisMode#PARALLEL}) * @param * the predicate step type expected * @param * the type of the checked sub-object * @return the assertor step */ default > AssertorStep andObject(final Function mapper, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), mapper, EnumType.UNKNOWN, analysisMode); } /** * Append a {@link Boolean} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @return the assertor step */ default AssertorStepBoolean andBoolean(final Function mapper) { return this.andBoolean(mapper, null); } /** * Append a {@link Boolean} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param analysisMode * the analysis mode ({@link EnumAnalysisMode#STANDARD}, * {@link EnumAnalysisMode#STREAM} or * {@link EnumAnalysisMode#PARALLEL}) * @return the assertor step */ default AssertorStepBoolean andBoolean(final Function mapper, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), mapper, EnumType.BOOLEAN, analysisMode); } /** * Append a {@link CharSequence} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param * the type of the {@link CharSequence} * @return the assertor step */ default AssertorStepCharSequence andCharSequence(final Function mapper) { return this.andCharSequence(mapper, null); } /** * Append a {@link CharSequence} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param analysisMode * the analysis mode ({@link EnumAnalysisMode#STANDARD}, * {@link EnumAnalysisMode#STREAM} or * {@link EnumAnalysisMode#PARALLEL}) * @param * the type of the {@link CharSequence} * @return the assertor step */ default AssertorStepCharSequence andCharSequence(final Function mapper, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), mapper, EnumType.CHAR_SEQUENCE, analysisMode); } /** * Append an array through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param * the type of the array elements * @return the assertor step */ default AssertorStepArray andArray(final Function mapper) { return this.andArray(mapper, null); } /** * Append an array through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param analysisMode * the analysis mode ({@link EnumAnalysisMode#STANDARD}, * {@link EnumAnalysisMode#STREAM} or * {@link EnumAnalysisMode#PARALLEL}) * @param * the type of the array elements * @return the assertor step */ default AssertorStepArray andArray(final Function mapper, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), mapper, EnumType.ARRAY, analysisMode); } /** * Append a {@link Date} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @return the assertor step */ default AssertorStepDate andDate(final Function mapper) { return this.andDate(mapper, null); } /** * Append a {@link Date} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param analysisMode * the analysis mode ({@link EnumAnalysisMode#STANDARD}, * {@link EnumAnalysisMode#STREAM} or * {@link EnumAnalysisMode#PARALLEL}) * @return the assertor step */ default AssertorStepDate andDate(final Function mapper, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), mapper, EnumType.DATE, analysisMode); } /** * Append a {@link Calendar} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @return the assertor step */ default AssertorStepCalendar andCalendar(final Function mapper) { return this.andCalendar(mapper, null); } /** * Append a {@link Calendar} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param analysisMode * the analysis mode ({@link EnumAnalysisMode#STANDARD}, * {@link EnumAnalysisMode#STREAM} or * {@link EnumAnalysisMode#PARALLEL}) * @return the assertor step */ default AssertorStepCalendar andCalendar(final Function mapper, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), mapper, EnumType.CALENDAR, analysisMode); } /** * Append a {@link Temporal} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param * the type of the {@link Temporal} * @return the assertor step */ default > AssertorStepTemporal andTemporal(final Function mapper) { return this.andTemporal(mapper, null); } /** * Append a {@link Temporal} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param analysisMode * the analysis mode ({@link EnumAnalysisMode#STANDARD}, * {@link EnumAnalysisMode#STREAM} or * {@link EnumAnalysisMode#PARALLEL}) * @param * the type of the {@link Temporal} * @return the assertor step */ default > AssertorStepTemporal andTemporal(final Function mapper, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), mapper, EnumType.TEMPORAL, analysisMode); } /** * Append a {@link Class} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param * the type of the {@link Class} * @return the assertor step */ default AssertorStepClass andClass(final Function> mapper) { return this.andClass(mapper, null); } /** * Append a {@link Class} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param analysisMode * the analysis mode ({@link EnumAnalysisMode#STANDARD}, * {@link EnumAnalysisMode#STREAM} or * {@link EnumAnalysisMode#PARALLEL}) * @param * the type of the {@link Class} * @return the assertor step */ default AssertorStepClass andClass(final Function> mapper, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), mapper, EnumType.CLASS, analysisMode); } /** * Append a {@link Enum} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param * the type of the {@link Enum} * @return the assertor step */ default > AssertorStepEnum andEnum(final Function mapper) { return this.andEnum(mapper, null); } /** * Append a {@link Enum} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param analysisMode * the analysis mode ({@link EnumAnalysisMode#STANDARD}, * {@link EnumAnalysisMode#STREAM} or * {@link EnumAnalysisMode#PARALLEL}) * @param * the type of the {@link Enum} * @return the assertor step */ default > AssertorStepEnum andEnum(final Function mapper, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), mapper, EnumType.ENUMERATION, analysisMode); } /** * Append a {@link Throwable} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param * the type of the {@link Throwable} * @return the assertor step */ default AssertorStepThrowable andThrowable(final Function mapper) { return this.andThrowable(mapper, null); } /** * Append a {@link Throwable} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param analysisMode * the analysis mode ({@link EnumAnalysisMode#STANDARD}, * {@link EnumAnalysisMode#STREAM} or * {@link EnumAnalysisMode#PARALLEL}) * @param * the type of the {@link Throwable} * @return the assertor step */ default AssertorStepThrowable andThrowable(final Function mapper, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), mapper, EnumType.THROWABLE, analysisMode); } /** * Append a {@link Number} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param * the type of the {@link Number} * @return the assertor step */ default > AssertorStepNumber andNumber(final Function mapper) { return this.andNumber(mapper, null); } /** * Append a {@link Number} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param analysisMode * the analysis mode ({@link EnumAnalysisMode#STANDARD}, * {@link EnumAnalysisMode#STREAM} or * {@link EnumAnalysisMode#PARALLEL}) * @param * the type of the {@link Number} * @return the assertor step */ default > AssertorStepNumber andNumber(final Function mapper, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), mapper, EnumType.NUMBER_DECIMAL, analysisMode); } /** * Append a {@link Iterable} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param * the type of the {@link Iterable} * @param * the type of the {@link Iterable} elements * @return the assertor step */ default , X> AssertorStepIterable andIterable(final Function mapper) { return this.andIterable(mapper, null); } /** * Append a {@link Iterable} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param analysisMode * the analysis mode ({@link EnumAnalysisMode#STANDARD}, * {@link EnumAnalysisMode#STREAM} or * {@link EnumAnalysisMode#PARALLEL}) * @param * the type of the {@link Iterable} * @param * the type of the {@link Iterable} elements * @return the assertor step */ default , X> AssertorStepIterable andIterable(final Function mapper, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), mapper, EnumType.ITERABLE, analysisMode); } /** * Append a {@link Map} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param * the type of the {@link Map} keys * @param * the type of the {@link Map} values * @return the assertor step */ default AssertorStepMap andMap(final Function> mapper) { return this.andMap(mapper, null); } /** * Append a {@link Map} through a mapper with the operator * {@link EnumOperator#AND} on the current step. * * @param mapper * the mapper function * @param analysisMode * the analysis mode ({@link EnumAnalysisMode#STANDARD}, * {@link EnumAnalysisMode#STREAM} or * {@link EnumAnalysisMode#PARALLEL}) * @param * the type of the {@link Map} keys * @param * the type of the {@link Map} values * @return the assertor step */ default AssertorStepMap andMap(final Function> mapper, final EnumAnalysisMode analysisMode) { return () -> HelperStep.and(this.getStep(), mapper, EnumType.MAP, analysisMode); } }