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