Package one.microstream.functional
Class XFunc
- java.lang.Object
-
- one.microstream.functional.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
XFunc.MaxInteger
-
Constructor Summary
Constructors Constructor Description XFunc()
-
Method Summary
Modifier and Type Method Description static <E,R>
Aggregator<E,R>aggregator(BiConsumer<? super E,? super R> joiner, R aggregate)
static <T> Predicate<T>
all()
Functional alias forreturn true;
.static <T> Predicate<T>
all(Predicate<? super T>... predicates)
static <T> Predicate<T>
any()
Functional alias forreturn true;
.static <E> AggregateCount<E>
count()
static <E> Aggregator<E,Long>
counter()
static <E> Predicate<E>
isEqual(E sample, Equalator<? super E> equalator)
static <T> Predicate<T>
isEqualTo(T subject)
static Predicate<Object>
isInstanceOf(Class<?> type)
static Predicate<Object>
isInstanceOf(Class<?>... types)
static <T> Predicate<T>
isSameAs(T subject)
static Aggregator<Integer,Integer>
max(int initialValue)
static <T> Predicate<T>
none()
Functional alias forreturn false;
.static <E> void
noOp(E e)
Literally a no-opConsumer
.static <T> Predicate<T>
not(Predicate<T> predicate)
Fluent alias forpredicate.negate()
.static Predicate<Object>
notIsInstanceOf(Class<?> type)
static Predicate<Object>
notIsInstanceOf(Class<?>... types)
static <T> Predicate<T>
notNull()
Functional alias forreturn e != null;
.static <T> Predicate<T>
one(Predicate<? super T>... predicates)
static <T> Function<T,T>
passThrough()
static <T,E extends T>
Predicate<T>predicate(E subject, Equalator<T> equalator)
static <T> Predicate<T>
select(Predicate<T> predicate)
Required to use lambdas or method reference in conjunction withPredicate.and(Predicate)
etc.static <T,R>
Function<T,R>toNull()
static <T extends S,S>
Function<T,S>upcast()
Pass-through function with type upcast.static <I,O>
Consumer<I>wrapWithFunction(Consumer<? super O> target, Function<? super I,O> function)
static <I,O>
Consumer<I>wrapWithFunctionLimit(Consumer<? super O> target, Function<? super I,O> function, long limit)
static <I,O>
Consumer<I>wrapWithFunctionSkip(Consumer<? super O> target, Function<? super I,O> function, long skip)
static <I,O>
Consumer<I>wrapWithFunctionSkipLimit(Consumer<? super O> target, Function<? super I,O> function, long skip, long limit)
static <E> Consumer<E>
wrapWithLimit(Consumer<? super E> target, long limit)
static <E> Consumer<E>
wrapWithPredicate(Consumer<? super E> target, Predicate<? super E> predicate)
static <I,O>
Consumer<I>wrapWithPredicateFunction(Consumer<? super O> target, Predicate<? super I> predicate, Function<? super I,O> function)
static <I,O>
Consumer<I>wrapWithPredicateFunctionLimit(Consumer<? super O> target, Predicate<? super I> predicate, Function<? super I,O> function, long limit)
static <I,O>
Consumer<I>wrapWithPredicateFunctionSkip(Consumer<? super O> target, Predicate<? super I> predicate, Function<? super I,O> function, long skip)
static <I,O>
Consumer<I>wrapWithPredicateFunctionSkipLimit(Consumer<? super O> target, Predicate<? super I> predicate, Function<? super I,O> function, long skip, long limit)
static <E> Consumer<E>
wrapWithPredicateLimit(Consumer<? super E> target, Predicate<? super E> predicate, long limit)
static <E> Consumer<E>
wrapWithPredicateSkip(Consumer<? super E> target, Predicate<? super E> predicate, long skip)
static <E> Consumer<E>
wrapWithPredicateSkipLimit(Consumer<? super E> target, Predicate<? super E> predicate, long skip, long limit)
static <E> Consumer<E>
wrapWithSkip(Consumer<? super E> target, long skip)
static <E> Consumer<E>
wrapWithSkipLimit(Consumer<? super E> target, long skip, long limit)
-
-
-
Method Detail
-
all
public static final <T> Predicate<T> all()
Functional alias forreturn true;
.
-
any
public static final <T> Predicate<T> any()
Functional alias forreturn true;
.
-
none
public static final <T> Predicate<T> none()
Functional alias forreturn false;
.
-
notNull
public static <T> Predicate<T> notNull()
Functional alias forreturn 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-opConsumer
.
-
all
@SafeVarargs public static final <T> Predicate<T> all(Predicate<? super T>... predicates)
-
select
public static final <T> Predicate<T> select(Predicate<T> predicate)
Required to use lambdas or method reference in conjunction withPredicate.and(Predicate)
etc.- Parameters:
predicate
- a predicate instance- Returns:
- the passed predicate instance without execution any further logic.
-
one
@SafeVarargs public static final <T> Predicate<T> one(Predicate<? super T>... predicates)
-
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 forpredicate.negate()
.
-
max
public static final Aggregator<Integer,Integer> max(int initialValue)
-
count
public static final <E> AggregateCount<E> count()
-
aggregator
public static final <E,R> Aggregator<E,R> aggregator(BiConsumer<? super E,? super R> joiner, R aggregate)
-
counter
public static <E> Aggregator<E,Long> counter()
-
wrapWithSkipLimit
public static <E> Consumer<E> wrapWithSkipLimit(Consumer<? super E> target, long skip, long limit)
-
wrapWithPredicate
public static final <E> Consumer<E> wrapWithPredicate(Consumer<? super E> target, Predicate<? super E> predicate)
-
wrapWithPredicateSkip
public static <E> Consumer<E> wrapWithPredicateSkip(Consumer<? super E> target, Predicate<? super E> predicate, long skip)
-
wrapWithPredicateLimit
public static <E> Consumer<E> wrapWithPredicateLimit(Consumer<? super E> target, Predicate<? super E> predicate, long limit)
-
wrapWithPredicateSkipLimit
public static <E> Consumer<E> wrapWithPredicateSkipLimit(Consumer<? super E> target, Predicate<? super E> predicate, long skip, long limit)
-
wrapWithFunction
public static final <I,O> Consumer<I> wrapWithFunction(Consumer<? super O> target, Function<? super I,O> function)
-
wrapWithFunctionSkip
public static <I,O> Consumer<I> wrapWithFunctionSkip(Consumer<? super O> target, Function<? super I,O> function, long skip)
-
wrapWithFunctionLimit
public static <I,O> Consumer<I> wrapWithFunctionLimit(Consumer<? super O> target, Function<? super I,O> function, long limit)
-
wrapWithFunctionSkipLimit
public static <I,O> Consumer<I> wrapWithFunctionSkipLimit(Consumer<? super O> target, Function<? super I,O> function, long skip, long limit)
-
wrapWithPredicateFunction
public static final <I,O> Consumer<I> wrapWithPredicateFunction(Consumer<? super O> target, Predicate<? super I> predicate, Function<? super I,O> function)
-
wrapWithPredicateFunctionSkip
public static <I,O> Consumer<I> wrapWithPredicateFunctionSkip(Consumer<? super O> target, Predicate<? super I> predicate, Function<? super I,O> function, long skip)
-
wrapWithPredicateFunctionLimit
public static <I,O> Consumer<I> wrapWithPredicateFunctionLimit(Consumer<? super O> target, Predicate<? super I> predicate, Function<? super I,O> function, long limit)
-
wrapWithPredicateFunctionSkipLimit
public static <I,O> Consumer<I> wrapWithPredicateFunctionSkipLimit(Consumer<? super O> target, 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());
-
-