public abstract class Functions extends Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
Functions.ArrayEqualityComparer
Array equality comparer.
|
private static class |
Functions.GeneratingList<E>
List that generates each element using a function.
|
private static class |
Functions.IdentityEqualityComparer
Identity equality comparer.
|
private static class |
Functions.Ignore<R,T0,T1>
Ignore.
|
private static class |
Functions.NullsFirstComparator
Nulls first comparator.
|
private static class |
Functions.NullsFirstReverseComparator
Nulls first reverse comparator.
|
private static class |
Functions.NullsLastComparator
Nulls last comparator.
|
private static class |
Functions.NullsLastReverseComparator
Nulls last reverse comparator.
|
private static class |
Functions.SelectorEqualityComparer<T,T2>
Selector equality comparer.
|
| Modifier and Type | Field and Description |
|---|---|
private static EqualityComparer<Object[]> |
ARRAY_COMPARER |
private static Function1 |
CONSTANT_NULL_FUNCTION1 |
static Map<Class<? extends Function>,Class> |
FUNCTION_RESULT_TYPES |
private static Map<Class,Class<? extends Function>> |
FUNCTION1_CLASSES |
private static EqualityComparer<Object> |
IDENTITY_COMPARER |
private static Comparator |
NULLS_FIRST_COMPARATOR |
private static Comparator |
NULLS_FIRST_REVERSE_COMPARATOR |
private static Comparator |
NULLS_LAST_COMPARATOR |
private static Comparator |
NULLS_LAST_REVERSE_COMPARATOR |
private static Function1 |
TO_STRING_FUNCTION1 |
| Modifier | Constructor and Description |
|---|---|
private |
Functions() |
| Modifier and Type | Method and Description |
|---|---|
static <T1> Function1<T1,Double> |
adapt(DoubleFunction1<T1> f)
|
static <T1> Function1<T1,Float> |
adapt(FloatFunction1<T1> f)
|
static <T1> Function1<T1,Integer> |
adapt(IntegerFunction1<T1> f)
|
static <T1,R> List<R> |
adapt(List<T1> list,
Function1<T1,R> f)
Deprecated.
Use
Lists.transform(java.util.List<F>, com.google.common.base.Function<? super F, ? extends T>) |
static <T1> Function1<T1,Long> |
adapt(LongFunction1<T1> f)
|
static <T,R> List<R> |
adapt(T[] ts,
Function1<T,R> f)
Deprecated.
Use
Lists.transform(java.util.List<F>, com.google.common.base.Function<? super F, ? extends T>)
and Arrays.asList(Object[]) |
static <E> boolean |
all(List<? extends E> list,
Predicate1<E> predicate)
Returns whether
predicate is true for all elements of
list. |
static <T1,R> List<R> |
apply(List<T1> list,
Function1<T1,R> f)
Creates a copy of a list, applying a function to each element.
|
static <T> EqualityComparer<T[]> |
arrayComparer()
Returns an
EqualityComparer that works on arrays of objects. |
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> |
constantNull()
Returns a 1-parameter function that always returns null.
|
static <E> boolean |
exists(List<? extends E> list,
Predicate1<E> predicate)
Returns whether there is an element in
list for which
predicate is true. |
static <T> Predicate1<T> |
falsePredicate1()
A predicate with one parameter that always returns
true. |
static <T1,T2> Predicate2<T1,T2> |
falsePredicate2()
A predicate with two parameters that always returns
false. |
static <E> List<E> |
filter(List<E> list,
Predicate1<E> predicate)
Returns a list that contains only elements of
list that match
predicate. |
static Class<? extends Function> |
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,
Function1<Integer,E> fn)
Returns a list generated by applying a function to each index between
0 and
size - 1. |
static <T> EqualityComparer<T> |
identityComparer()
Returns an
EqualityComparer that uses object identity and hash
code. |
static <TSource> Function1<TSource,TSource> |
identitySelector() |
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.
|
private static <K,V> Map<V,K> |
inverse(Map<K,V> map) |
private static <K,V> Map<K,V> |
map(K k,
V v,
Object... rest) |
static <T extends Comparable<T>> |
nullsComparator(boolean nullsFirst,
boolean reverse)
Returns a
Comparator that 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 an
EqualityComparer that uses a selector function. |
private static <T> Predicate1<T> |
toPredicate(Function1<T,Boolean> function)
Converts a 1-parameter function to a predicate.
|
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) |
static <TSource> Function1<TSource,String> |
toStringSelector()
Returns a selector that calls the
Object.toString() method on
each element. |
static <T> Predicate1<T> |
truePredicate1()
A predicate with one parameter that always returns
true. |
static <T1,T2> Predicate2<T1,T2> |
truePredicate2()
A predicate with two parameters that always returns
true. |
public static final Map<Class<? extends Function>,Class> FUNCTION_RESULT_TYPES
private static final Comparator NULLS_FIRST_COMPARATOR
private static final Comparator NULLS_LAST_COMPARATOR
private static final Comparator NULLS_LAST_REVERSE_COMPARATOR
private static final Comparator NULLS_FIRST_REVERSE_COMPARATOR
private static final EqualityComparer<Object> IDENTITY_COMPARER
private static final EqualityComparer<Object[]> ARRAY_COMPARER
private static final Function1 CONSTANT_NULL_FUNCTION1
private static final Function1 TO_STRING_FUNCTION1
public static <T,R> Function1<T,R> constant(R r)
public static <T,R> Function1<T,R> constantNull()
public static <T> Predicate1<T> truePredicate1()
true.T - First parameter typepublic static <T> Predicate1<T> falsePredicate1()
true.T - First parameter typepublic static <T1,T2> Predicate2<T1,T2> truePredicate2()
true.T1 - First parameter typeT2 - Second parameter typepublic static <T1,T2> Predicate2<T1,T2> falsePredicate2()
false.T1 - First parameter typeT2 - Second parameter typepublic static <TSource> Function1<TSource,TSource> identitySelector()
public static <TSource> Function1<TSource,String> toStringSelector()
Object.toString() method on
each element.public static <T,T2> Predicate1<T> ofTypePredicate(Class<T2> clazz)
T - Type of objects to testT2 - Desired typeclazz - Desired typepublic static <T1,T2> Predicate2<T1,T2> toPredicate2(Predicate1<T1> p1)
public static <T1,T2> Predicate2<T1,T2> toPredicate(Function2<T1,T2,Boolean> function)
private static <T> Predicate1<T> toPredicate(Function1<T,Boolean> function)
public static Class<? extends Function> functionClass(Type aClass)
For example:
functionClass(Integer.TYPE) returns IntegerFunction1.class functionClass(String.class) returns Function1.classaClass - Return typepublic static <T1> Function1<T1,Integer> adapt(IntegerFunction1<T1> f)
public static <T1> Function1<T1,Double> adapt(DoubleFunction1<T1> f)
public static <T1> Function1<T1,Long> adapt(LongFunction1<T1> f)
public static <T1> Function1<T1,Float> adapt(FloatFunction1<T1> f)
@Deprecated public static <T1,R> List<R> adapt(List<T1> list, Function1<T1,R> f)
Lists.transform(java.util.List<F>, com.google.common.base.Function<? super F, ? extends T>)@Deprecated public static <T,R> List<R> adapt(T[] ts, Function1<T,R> f)
Lists.transform(java.util.List<F>, com.google.common.base.Function<? super F, ? extends T>)
and Arrays.asList(Object[])public static <T1,R> List<R> apply(List<T1> list, Function1<T1,R> f)
public static <E> List<E> filter(List<E> list, Predicate1<E> predicate)
list that match
predicate. Avoids allocating a list if all elements match or no
elements match.public static <E> boolean exists(List<? extends E> list, Predicate1<E> predicate)
list for which
predicate is true.public static <E> boolean all(List<? extends E> list, Predicate1<E> predicate)
predicate is true for all elements of
list.public static <E> List<E> generate(int size, Function1<Integer,E> fn)
size - 1.public static <R> Function0<R> ignore0()
R - Return typepublic static <R,T0> Function1<R,T0> ignore1()
R - Return typeT0 - Type of parameter 0public static <R,T0,T1> Function2<R,T0,T1> ignore2()
R - Return typeT0 - Type of parameter 0T1 - Type of parameter 1public static <T extends Comparable<T>> Comparator<T> nullsComparator(boolean nullsFirst, boolean reverse)
Comparator that handles null values.nullsFirst - Whether nulls come before all other valuesreverse - Whether to reverse the usual order of Comparablespublic static <T> EqualityComparer<T> identityComparer()
EqualityComparer that uses object identity and hash
code.public static <T> EqualityComparer<T[]> arrayComparer()
EqualityComparer that works on arrays of objects.public static <T,T2> EqualityComparer<T> selectorComparer(Function1<T,T2> selector)
EqualityComparer that uses a selector function.Copyright © 2012–2021 The Apache Software Foundation. All rights reserved.