001package Torello.Java.Function;
002
003/**
004 * Function-Pointer
005 * <SPAN CLASS=TJF>Input:</SPAN> {@code char}
006 * <SPAN CLASS=TJF>Output:</SPAN> {@code boolean}.
007 * 
008 * <BR /><BR />
009 * This is similar to Java's {@code IntPredicate}, except it explicity requires a {@code char}
010 * type in it's lambda {@code 'test'} method.
011 */
012@FunctionalInterface
013public interface CharPredicate
014{
015    /**
016     * Evaluates this predicate on the given argument.
017     * @param c primitive-{@code char} (character) input argument.
018     * @return <B>TRUE</B> if the input argument matches this predicate, and <B>FALSE</B> otherwise.
019     */
020    public boolean test(char c);
021
022    /**
023     * <EMBED CLASS="external-html" DATA-FILE-ID="PREDANDMETH">
024     * @param other A predicate that will be logically-AND'ed with this predicate
025     * @return <EMBED CLASS="external-html" DATA-FILE-ID="PREDANDRET">
026     * @throws NullPointerException if parameter {@code 'other'} is null.
027     */
028    default CharPredicate and(CharPredicate other)
029    {
030        if (other == null)
031            throw new NullPointerException("null has been passed to parameter 'other'");
032
033        return (char c) -> this.test(c) && other.test(c);
034    }
035
036    /**
037     * <EMBED CLASS="external-html" DATA-FILE-ID="PREDNEGMETH">
038     * @return <EMBED CLASS="external-html" DATA-FILE-ID="PREDNEGRET">
039     */
040    default CharPredicate negate()
041    { return (char c) -> ! this.test(c); }
042
043    /**
044     * <EMBED CLASS="external-html" DATA-FILE-ID="PREDORMETH">
045     * @param other a predicate that will be logically-ORed with this predicate
046     * @return <EMBED CLASS="external-html" DATA-FILE-ID="PREDORRET">
047     * @throws NullPointerException if parameter {@code 'other'} is null.
048     */
049    default CharPredicate or(CharPredicate other)
050    {
051        if (other == null)
052            throw new NullPointerException("null has been passed to parameter 'other'");
053
054        return (char c) -> this.test(c) || other.test(c);
055    }
056}