001package Torello.Java.Function;
002
003/**
004 * Function-Pointer
005 * <SPAN CLASS=TJF>Input:</SPAN> {@code A, B, C, D}
006 * <SPAN CLASS=TJF>Output:</SPAN> {@code boolean}.
007 * 
008 * <BR /><BR />
009 * <EMBED CLASS='external-html' DATA-FILE-ID=BIG_PREDICATE>
010 * <EMBED CLASS="globalDefs" DATA-Name='Quad Predicate' DATA-Number=four>
011 * 
012 * @param <A> The type of the first input-parameter.
013 * @param <B> The type of the second input-parameter.
014 * @param <C> The type of the third input-parameter.
015 * @param <D> The type of the last input-parameter.
016 */
017@FunctionalInterface
018public interface QuadPredicate<A, B, C, D>
019{
020    /**
021     * Evaluates {@code "this"} predicate on the given arguments.
022     * <BR /><BR /><EMBED CLASS='external-html' DATA-FILE-ID=FUNC_INTER_METH>
023     *
024     * @param a the first input argument
025     * @param b the second input argument
026     * @param c the third input argument
027     * @param d the fourth input argument
028     * @return {@code TRUE} if the input arguments match the predicate, otherwise <B>FALSE</B>
029     */
030    public boolean test(A a, B b, C c, D d);
031
032    /**
033     * <EMBED CLASS='external-html' DATA-FILE-ID=PRED_AND_METHOD>
034     * @param other A predicate that will be logically-AND'ed with this predicate
035     * @return <EMBED CLASS='external-html' DATA-FILE-ID=PRED_AND_RETURN>
036     * @throws NullPointerException if parameter {@code 'other'} is null.
037     */
038    default QuadPredicate<A, B, C, D> and
039        (QuadPredicate<? super A, ? super B, ? super C, ? super D> other)
040    {
041        if (other == null)
042            throw new NullPointerException("null has been passed to parameter 'other");
043
044        return (A a, B b, C c, D d) ->
045            this.test(a, b, c, d) && other.test(a, b, c, d);
046    }
047
048    /**
049     * <EMBED CLASS='external-html' DATA-FILE-ID=PRED_NEGATE_METHOD>
050     * @return <EMBED CLASS='external-html' DATA-FILE-ID=PRED_NEGATE_RETURN>
051     */
052    default QuadPredicate<A, B, C, D> negate()
053    { return (A a, B b, C c, D d) -> ! this.test(a, b, c, d); }
054
055    /**
056     * <EMBED CLASS='external-html' DATA-FILE-ID=PRED_OR_METHOD>
057     * @param other a predicate that will be logically-ORed with this predicate
058     * @return <EMBED CLASS='external-html' DATA-FILE-ID=PRED_OR_RETURN>
059     * @throws NullPointerException if parameter {@code 'other'} is null.
060     */
061    default QuadPredicate<A, B, C, D> or
062        (QuadPredicate<? super A, ? super B, ? super C, ? super D> other)
063    {
064        if (other == null)
065            throw new NullPointerException("null has been passed to parameter 'other");
066
067        return (A a, B b, C c, D d) ->
068            this.test(a, b, c, d) || other.test(a, b, c, d);
069    }
070}