Package extra166y

Class CommonOps


  • public class CommonOps
    extends java.lang.Object
    A collection of static factory methods providing commonly useful implementations of operations.
    • Method Detail

      • naturalComparator

        public static <T extends java.lang.Comparable<? super T>> java.util.Comparator<T> naturalComparator​(java.lang.Class<T> type)
        Returns a Comparator for Comparable objects
      • naturalMaxReducer

        public static <T extends java.lang.Comparable<? super T>> Ops.Reducer<T> naturalMaxReducer​(java.lang.Class<T> type)
        Returns a reducer returning the maximum of two Comparable elements, treating null as less than any non-null element.
      • naturalMinReducer

        public static <T extends java.lang.Comparable<? super T>> Ops.Reducer<T> naturalMinReducer​(java.lang.Class<T> type)
        Returns a reducer returning the minimum of two Comparable elements, treating null as greater than any non-null element.
      • maxReducer

        public static <T> Ops.Reducer<T> maxReducer​(java.util.Comparator<? super T> comparator)
        Returns a reducer returning the maximum of two elements, using the given comparator, and treating null as less than any non-null element.
      • minReducer

        public static <T> Ops.Reducer<T> minReducer​(java.util.Comparator<? super T> comparator)
        Returns a reducer returning the minimum of two elements, using the given comparator, and treating null as greater than any non-null element.
      • castedComparator

        public static java.util.Comparator<java.lang.Object> castedComparator()
        Returns a Comparator that casts its arguments as Comparable on each comparison, throwing ClassCastException on failure.
      • castedMaxReducer

        public static Ops.Reducer<java.lang.Object> castedMaxReducer()
        Returns a reducer returning maximum of two values, or null if both arguments are null, and that casts its arguments as Comparable on each comparison, throwing ClassCastException on failure.
      • castedMinReducer

        public static Ops.Reducer<java.lang.Object> castedMinReducer()
        Returns a reducer returning minimum of two values, or null if both arguments are null, and that casts its arguments as Comparable on each comparison, throwing ClassCastException on failure.
      • naturalDoubleComparator

        public static Ops.DoubleComparator naturalDoubleComparator()
        Returns a comparator for doubles relying on natural ordering
      • naturalDoubleMaxReducer

        public static Ops.DoubleReducer naturalDoubleMaxReducer()
        Returns a reducer returning the maximum of two double elements, using natural comparator
      • naturalDoubleMinReducer

        public static Ops.DoubleReducer naturalDoubleMinReducer()
        Returns a reducer returning the minimum of two double elements, using natural comparator
      • doubleMaxReducer

        public static Ops.DoubleReducer doubleMaxReducer​(Ops.DoubleComparator comparator)
        Returns a reducer returning the maximum of two double elements, using the given comparator
      • doubleMinReducer

        public static Ops.DoubleReducer doubleMinReducer​(Ops.DoubleComparator comparator)
        Returns a reducer returning the minimum of two double elements, using the given comparator
      • naturalLongComparator

        public static Ops.LongComparator naturalLongComparator()
        Returns a comparator for longs relying on natural ordering
      • naturalLongMaxReducer

        public static Ops.LongReducer naturalLongMaxReducer()
        Returns a reducer returning the maximum of two long elements, using natural comparator
      • naturalLongMinReducer

        public static Ops.LongReducer naturalLongMinReducer()
        A reducer returning the minimum of two long elements, using natural comparator
      • longMaxReducer

        public static Ops.LongReducer longMaxReducer​(Ops.LongComparator comparator)
        Returns a reducer returning the maximum of two long elements, using the given comparator
      • longMinReducer

        public static Ops.LongReducer longMinReducer​(Ops.LongComparator comparator)
        Returns a reducer returning the minimum of two long elements, using the given comparator
      • compoundOp

        public static <T,​U,​V> Ops.Op<T,​V> compoundOp​(Ops.Op<? super T,​? extends U> first,
                                                                       Ops.Op<? super U,​? extends V> second)
        Returns a composite mapper that applies a second mapper to the results of applying the first one
      • compoundOp

        public static <T,​V> Ops.Op<T,​V> compoundOp​(Ops.ObjectToDouble<? super T> first,
                                                               Ops.DoubleToObject<? extends V> second)
        Returns a composite mapper that applies a second mapper to the results of applying the first one
      • compoundOp

        public static <T,​V> Ops.Op<T,​V> compoundOp​(Ops.ObjectToLong<? super T> first,
                                                               Ops.LongToObject<? extends V> second)
        Returns a composite mapper that applies a second mapper to the results of applying the first one
      • compoundOp

        public static <T,​V> Ops.DoubleToObject<V> compoundOp​(Ops.DoubleToObject<? extends T> first,
                                                                   Ops.Op<? super T,​? extends V> second)
        Returns a composite mapper that applies a second mapper to the results of applying the first one
      • compoundOp

        public static <T,​V> Ops.LongToObject<V> compoundOp​(Ops.LongToObject<? extends T> first,
                                                                 Ops.Op<? super T,​? extends V> second)
        Returns a composite mapper that applies a second mapper to the results of applying the first one
      • compoundOp

        public static <T,​U> Ops.ObjectToDouble<T> compoundOp​(Ops.Op<? super T,​? extends U> first,
                                                                   Ops.ObjectToDouble<? super U> second)
        Returns a composite mapper that applies a second mapper to the results of applying the first one
      • compoundOp

        public static <T,​U> Ops.ObjectToLong<T> compoundOp​(Ops.Op<? super T,​? extends U> first,
                                                                 Ops.ObjectToLong<? super U> second)
        Returns a composite mapper that applies a second mapper to the results of applying the first one
      • compoundOp

        public static <T> Ops.ObjectToLong<T> compoundOp​(Ops.ObjectToLong<? super T> first,
                                                         Ops.LongOp second)
        Returns a composite mapper that applies a second mapper to the results of applying the first one
      • compoundOp

        public static Ops.DoubleOp compoundOp​(Ops.DoubleOp first,
                                              Ops.DoubleOp second)
        Returns a composite mapper that applies a second mapper to the results of applying the first one
      • compoundOp

        public static <T> Ops.LongToObject<T> compoundOp​(Ops.LongOp first,
                                                         Ops.LongToObject<? extends T> second)
        Returns a composite mapper that applies a second mapper to the results of applying the first one
      • compoundOp

        public static <T> Ops.LongOp compoundOp​(Ops.LongToObject<? extends T> first,
                                                Ops.ObjectToLong<? super T> second)
        Returns a composite mapper that applies a second mapper to the results of applying the first one
      • compoundOp

        public static Ops.LongOp compoundOp​(Ops.LongOp first,
                                            Ops.LongOp second)
        Returns a composite mapper that applies a second mapper to the results of applying the first one
      • notPredicate

        public static <T> Ops.Predicate<T> notPredicate​(Ops.Predicate<T> pred)
        Returns a predicate evaluating to the negation of its contained predicate
      • andPredicate

        public static <S,​T extends S> Ops.Predicate<T> andPredicate​(Ops.Predicate<S> first,
                                                                          Ops.Predicate<? super T> second)
        Returns a predicate evaluating to the conjunction of its contained predicates
      • orPredicate

        public static <S,​T extends S> Ops.Predicate<T> orPredicate​(Ops.Predicate<S> first,
                                                                         Ops.Predicate<? super T> second)
        Returns a predicate evaluating to the disjunction of its contained predicates
      • isNonNullPredicate

        public static Ops.Predicate<java.lang.Object> isNonNullPredicate()
        Returns a predicate evaluating to true if its argument is non-null
      • isNullPredicate

        public static Ops.Predicate<java.lang.Object> isNullPredicate()
        Returns a predicate evaluating to true if its argument is null
      • instanceofPredicate

        public static Ops.Predicate<java.lang.Object> instanceofPredicate​(java.lang.Class type)
        Returns a predicate evaluating to true if its argument is an instance of (see Class.isInstance(java.lang.Object) the given type (class).
      • isAssignablePredicate

        public static Ops.Predicate<java.lang.Object> isAssignablePredicate​(java.lang.Class type)
        Returns a predicate evaluating to true if its argument is assignable from (see Class.isAssignableFrom(java.lang.Class<?>) the given type (class).
      • doubleAdder

        public static Ops.DoubleReducer doubleAdder()
        Returns a reducer that adds two double elements
      • longAdder

        public static Ops.LongReducer longAdder()
        Returns a reducer that adds two long elements
      • intAdder

        public static Ops.IntReducer intAdder()
        Returns a reducer that adds two int elements
      • doubleRandom

        public static Ops.DoubleGenerator doubleRandom()
        Returns a generator producing uniform random values between zero and one, with the same properties as Random.nextDouble()
      • doubleRandom

        public static Ops.DoubleGenerator doubleRandom​(double bound)
        Returns a generator producing uniform random values between zero and the given bound, with the same properties as Random.nextDouble().
        Parameters:
        bound - the upper bound (exclusive) of opd values
      • doubleRandom

        public static Ops.DoubleGenerator doubleRandom​(double least,
                                                       double bound)
        Returns a generator producing uniform random values between the given least value (inclusive) and bound (exclusive)
        Parameters:
        least - the least value returned
        bound - the upper bound (exclusive) of opd values
      • longRandom

        public static Ops.LongGenerator longRandom()
        Returns a generator producing uniform random values with the same properties as Random.nextLong()
      • longRandom

        public static Ops.LongGenerator longRandom​(long bound)
        Returns a generator producing uniform random values with the same properties as Random.nextInt(int)
        Parameters:
        bound - the upper bound (exclusive) of opd values
      • longRandom

        public static Ops.LongGenerator longRandom​(long least,
                                                   long bound)
        Returns a generator producing uniform random values between the given least value (inclusive) and bound (exclusive).
        Parameters:
        least - the least value returned
        bound - the upper bound (exclusive) of opd values
      • intRandom

        public static Ops.IntGenerator intRandom()
        Returns a generator producing uniform random values with the same properties as Random.nextInt()
      • intRandom

        public static Ops.IntGenerator intRandom​(int bound)
        Returns a generator producing uniform random values with the same properties as Random.nextInt(int)
        Parameters:
        bound - the upper bound (exclusive) of opd values
      • intRandom

        public static Ops.IntGenerator intRandom​(int least,
                                                 int bound)
        Returns a generator producing uniform random values between the given least value (inclusive) and bound (exclusive)
        Parameters:
        least - the least value returned
        bound - the upper bound (exclusive) of opd values
      • equalityPredicate

        public static Ops.BinaryPredicate<java.lang.Object,​java.lang.Object> equalityPredicate()
        Returns a predicate evaluating to true if the first argument equals the second
      • identityPredicate

        public static Ops.BinaryPredicate<java.lang.Object,​java.lang.Object> identityPredicate()
        Returns a predicate evaluating to true if the first argument == the second
      • intEqualityPredicate

        public static Ops.BinaryIntPredicate intEqualityPredicate()
        Returns a predicate evaluating to true if the first argument == the second
      • longEqualityPredicate

        public static Ops.BinaryLongPredicate longEqualityPredicate()
        Returns a predicate evaluating to true if the first argument == the second
      • doubleEqualityPredicate

        public static Ops.BinaryDoublePredicate doubleEqualityPredicate()
        Returns a predicate evaluating to true if the first argument == the second
      • inequalityPredicate

        public static Ops.BinaryPredicate<java.lang.Object,​java.lang.Object> inequalityPredicate()
        Returns a predicate evaluating to true if the first argument !equals the second
      • nonidentityPredicate

        public static Ops.BinaryPredicate<java.lang.Object,​java.lang.Object> nonidentityPredicate()
        Returns a predicate evaluating to true if the first argument != the second
      • intInequalityPredicate

        public static Ops.BinaryIntPredicate intInequalityPredicate()
        Returns a predicate evaluating to true if the first argument != the second
      • longInequalityPredicate

        public static Ops.BinaryLongPredicate longInequalityPredicate()
        Returns a predicate evaluating to true if the first argument == the second
      • doubleInequalityPredicate

        public static Ops.BinaryDoublePredicate doubleInequalityPredicate()
        Returns a predicate evaluating to true if the first argument != the second