Class XFunc


  • public final class XFunc
    extends Object
    Normally, writing "Func" instead of "Functional" is a capital sin of writing clean code. However, in the sake of shortness for static util method class names AND in light of "Mathematics", "Sorting" and "Characters" already being shortened to the (albeit more common) names "Math", "Sort", "Chars" PLUS the unique recognizability of "Func", the shortness trumped the clarity of completeness here (as well). Rules are made for people and must be bendable if reasonable reflection (not laziness!) concludes necessity.
    • Constructor Detail

      • XFunc

        public XFunc()
    • Method Detail

      • all

        public static final <T> Predicate<T> all()
        Functional alias for return true;.
      • any

        public static final <T> Predicate<T> any()
        Functional alias for return true;.
      • none

        public static final <T> Predicate<T> none()
        Functional alias for return false;.
      • notNull

        public static <T> Predicate<T> notNull()
        Functional alias for return e != null;.
      • toNull

        public static final <T,​R> Function<T,​R> toNull()
      • passThrough

        public static final <T> Function<T,​T> passThrough()
      • noOp

        public static <E> void noOp​(E e)
        Literally a no-op Consumer.
      • select

        public static final <T> Predicate<T> select​(Predicate<T> predicate)
        Required to use lambdas or method reference in conjunction with Predicate.and(Predicate) etc.
        Parameters:
        predicate - a predicate instance
        Returns:
        the passed predicate instance without execution any further logic.
      • isEqual

        public static final <E> Predicate<E> isEqual​(E sample,
                                                     Equalator<? super E> equalator)
      • isEqualTo

        public static final <T> Predicate<T> isEqualTo​(T subject)
      • isSameAs

        public static final <T> Predicate<T> isSameAs​(T subject)
      • predicate

        public static final <T,​E extends T> Predicate<T> predicate​(E subject,
                                                                         Equalator<T> equalator)
      • not

        public static <T> Predicate<T> not​(Predicate<T> predicate)
        Fluent alias for predicate.negate().
      • aggregator

        public static final <E,​R> Aggregator<E,​R> aggregator​(BiConsumer<? super E,​? super R> joiner,
                                                                         R aggregate)
      • wrapWithSkip

        public static <E> Consumer<E> wrapWithSkip​(Consumer<? super E> procedure,
                                                   long skip)
      • wrapWithLimit

        public static <E> Consumer<E> wrapWithLimit​(Consumer<? super E> procedure,
                                                    long limit)
      • wrapWithSkipLimit

        public static <E> Consumer<E> wrapWithSkipLimit​(Consumer<? super E> procedure,
                                                        long skip,
                                                        long limit)
      • wrapWithPredicate

        public static final <E> Consumer<E> wrapWithPredicate​(Consumer<? super E> procedure,
                                                              Predicate<? super E> predicate)
      • wrapWithPredicateSkip

        public static <E> Consumer<E> wrapWithPredicateSkip​(Consumer<? super E> procedure,
                                                            Predicate<? super E> predicate,
                                                            long skip)
      • wrapWithPredicateLimit

        public static <E> Consumer<E> wrapWithPredicateLimit​(Consumer<? super E> procedure,
                                                             Predicate<? super E> predicate,
                                                             long limit)
      • wrapWithPredicateSkipLimit

        public static <E> Consumer<E> wrapWithPredicateSkipLimit​(Consumer<? super E> procedure,
                                                                 Predicate<? super E> predicate,
                                                                 long skip,
                                                                 long limit)
      • wrapWithFunction

        public static final <I,​O> Consumer<I> wrapWithFunction​(Consumer<? super O> procedure,
                                                                     Function<? super I,​O> function)
      • wrapWithFunctionSkip

        public static <I,​O> Consumer<I> wrapWithFunctionSkip​(Consumer<? super O> procedure,
                                                                   Function<? super I,​O> function,
                                                                   long skip)
      • wrapWithFunctionLimit

        public static <I,​O> Consumer<I> wrapWithFunctionLimit​(Consumer<? super O> procedure,
                                                                    Function<? super I,​O> function,
                                                                    long limit)
      • wrapWithFunctionSkipLimit

        public static <I,​O> Consumer<I> wrapWithFunctionSkipLimit​(Consumer<? super O> procedure,
                                                                        Function<? super I,​O> function,
                                                                        long skip,
                                                                        long limit)
      • wrapWithPredicateFunction

        public static final <I,​O> Consumer<I> wrapWithPredicateFunction​(Consumer<? super O> procedure,
                                                                              Predicate<? super I> predicate,
                                                                              Function<? super I,​O> function)
      • wrapWithPredicateFunctionSkip

        public static <I,​O> Consumer<I> wrapWithPredicateFunctionSkip​(Consumer<? super O> procedure,
                                                                            Predicate<? super I> predicate,
                                                                            Function<? super I,​O> function,
                                                                            long skip)
      • wrapWithPredicateFunctionLimit

        public static <I,​O> Consumer<I> wrapWithPredicateFunctionLimit​(Consumer<? super O> procedure,
                                                                             Predicate<? super I> predicate,
                                                                             Function<? super I,​O> function,
                                                                             long limit)
      • wrapWithPredicateFunctionSkipLimit

        public static <I,​O> Consumer<I> wrapWithPredicateFunctionSkipLimit​(Consumer<? super O> procedure,
                                                                                 Predicate<? super I> predicate,
                                                                                 Function<? super I,​O> function,
                                                                                 long skip,
                                                                                 long limit)
      • upcast

        public static final <T extends S,​S> Function<T,​S> upcast()
        Pass-through function with type upcast. Can sometimes be required to correctly handle nested types.

        Consider the following example with V1 extends V: (e.g. V is an interface and V1 is an implementation of V)

         XMap<K, V1> workingCollection = ... ;
         XImmutableMap<K, V> finalCollection = ConstHashTable.NewProjected(input, <K>passthrough(), <V1, V>upcast());