Class Functions
java.lang.Object
org.apache.calcite.linq4j.function.Functions
Utilities relating to functions.
-
Field Summary
FieldsModifier and TypeFieldDescription -
Method Summary
Modifier and TypeMethodDescriptionstatic <T1,R> List<R> Deprecated.adapt(DoubleFunction1<T1> f) adapt(FloatFunction1<T1> f) adapt(IntegerFunction1<T1> f) adapt(LongFunction1<T1> f) static <T,R> List<R> Deprecated.UseLists.transform(java.util.List<F>, com.google.common.base.Function<? super F, ? extends T>)andArrays.asList(Object[])static <E> booleanall(List<? extends E> list, Predicate1<E> predicate) Returns whetherpredicateis true for all elements oflist.static <T1,R> List<R> Creates a copy of a list, applying a function to each element.static <T> EqualityComparer<T[]>Returns anEqualityComparerthat works on arrays of objects.static intcompareLists(List<?> b0, List<?> b1) static intcompareObjectArrays(Object[] b0, Object[] b1) static <T,R> Function1<T, R> constant(R r) Returns a 1-parameter function that always returns the same value.static <T,R> Function1<T, R> Returns a 1-parameter function that always returns null.static <E> booleanexists(List<? extends E> list, Predicate1<E> predicate) Returns whether there is an element inlistfor whichpredicateis true.static <T> Predicate1<T>A predicate with one parameter that always returnstrue.static <T1,T2> Predicate2<T1, T2> A predicate with two parameters that always returnsfalse.static <E> List<E>filter(List<E> list, Predicate1<E> predicate) Returns a list that contains only elements oflistthat matchpredicate.functionClass(Type aClass) Returns the appropriate interface for a lambda function with 1 argument and the given return type.static <E> List<E>generate(int size, IntFunction<E> fn) Returns a list generated by applying a function to each index between 0 andsize- 1.static <T> EqualityComparer<T>Returns anEqualityComparerthat uses object identity and hash code.static <TSource> Function1<TSource,TSource> static <R> Function0<R>ignore0()Returns a function of arity 0 that does nothing.static <R,T0> Function1<R, T0> ignore1()Returns a function of arity 1 that does nothing.static <R,T0, T1> Function2<R, T0, T1> ignore2()Returns a function of arity 2 that does nothing.static <T extends Comparable<T>>
Comparator<T>nullsComparator(boolean nullsFirst, boolean reverse) Returns aComparatorthat handles null values.static <T extends Comparable<T>>
Comparator<T>nullsComparator(boolean nullsFirst, boolean reverse, Comparator<T> comparator) Returns aComparatorthat handles null values.static <T,T2> Predicate1<T> ofTypePredicate(Class<T2> clazz) Creates a predicate that returns whether an object is an instance of a particular type or is null.static <T,T2> EqualityComparer<T> selectorComparer(Function1<T, T2> selector) Returns anEqualityComparerthat uses a selector function.static <T1,T2> Predicate2<T1, T2> toPredicate(Function2<T1, T2, Boolean> function) Converts a 2-parameter function to a predicate.static <T1,T2> Predicate2<T1, T2> toPredicate2(Predicate1<T1> p1) Returns a selector that calls theObject.toString()method on each element.static <T> Predicate1<T>A predicate with one parameter that always returnstrue.static <T1,T2> Predicate2<T1, T2> A predicate with two parameters that always returnstrue.
-
Field Details
-
FUNCTION_RESULT_TYPES
-
-
Method Details
-
constant
Returns a 1-parameter function that always returns the same value. -
constantNull
Returns a 1-parameter function that always returns null. -
truePredicate1
A predicate with one parameter that always returnstrue.- Type Parameters:
T- First parameter type- Returns:
- Predicate that always returns true
-
falsePredicate1
A predicate with one parameter that always returnstrue.- Type Parameters:
T- First parameter type- Returns:
- Predicate that always returns true
-
truePredicate2
A predicate with two parameters that always returnstrue.- Type Parameters:
T1- First parameter typeT2- Second parameter type- Returns:
- Predicate that always returns true
-
falsePredicate2
A predicate with two parameters that always returnsfalse.- Type Parameters:
T1- First parameter typeT2- Second parameter type- Returns:
- Predicate that always returns false
-
identitySelector
-
toStringSelector
Returns a selector that calls theObject.toString()method on each element. -
ofTypePredicate
Creates a predicate that returns whether an object is an instance of a particular type or is null.- Type Parameters:
T- Type of objects to testT2- Desired type- Parameters:
clazz- Desired type- Returns:
- Predicate that tests for desired type
-
toPredicate2
-
toPredicate
Converts a 2-parameter function to a predicate. -
functionClass
Returns the appropriate interface for a lambda function with 1 argument and the given return type.For example: functionClass(Integer.TYPE) returns IntegerFunction1.class; functionClass(String.class) returns Function1.class.
- Parameters:
aClass- Return type- Returns:
- Function class
-
adapt
-
adapt
-
adapt
-
adapt
-
adapt
Deprecated.UseLists.transform(java.util.List<F>, com.google.common.base.Function<? super F, ? extends T>)Creates a view of a list that applies a function to each element. -
adapt
Deprecated.UseLists.transform(java.util.List<F>, com.google.common.base.Function<? super F, ? extends T>)andArrays.asList(Object[])Creates a view of an array that applies a function to each element. -
apply
Creates a copy of a list, applying a function to each element. -
filter
Returns a list that contains only elements oflistthat matchpredicate. Avoids allocating a list if all elements match or no elements match. -
exists
Returns whether there is an element inlistfor whichpredicateis true. -
all
Returns whetherpredicateis true for all elements oflist. -
generate
Returns a list generated by applying a function to each index between 0 andsize- 1. -
ignore0
Returns a function of arity 0 that does nothing.- Type Parameters:
R- Return type- Returns:
- Function that does nothing.
-
ignore1
Returns a function of arity 1 that does nothing.- Type Parameters:
R- Return typeT0- Type of parameter 0- Returns:
- Function that does nothing.
-
ignore2
Returns a function of arity 2 that does nothing.- Type Parameters:
R- Return typeT0- Type of parameter 0T1- Type of parameter 1- Returns:
- Function that does nothing.
-
nullsComparator
public static <T extends Comparable<T>> Comparator<T> nullsComparator(boolean nullsFirst, boolean reverse) Returns aComparatorthat handles null values.- Parameters:
nullsFirst- Whether nulls come before all other valuesreverse- Whether to reverse the usual order ofComparables
-
nullsComparator
public static <T extends Comparable<T>> Comparator<T> nullsComparator(boolean nullsFirst, boolean reverse, Comparator<T> comparator) Returns aComparatorthat handles null values.- Parameters:
nullsFirst- Whether nulls come before all other valuesreverse- Whether to reverse the usual order ofComparablescomparator- Comparator to be used for comparison
-
identityComparer
Returns anEqualityComparerthat uses object identity and hash code. -
arrayComparer
Returns anEqualityComparerthat works on arrays of objects. -
selectorComparer
Returns anEqualityComparerthat uses a selector function. -
compareLists
-
compareObjectArrays
-
Lists.transform(java.util.List<F>, com.google.common.base.Function<? super F, ? extends T>)