Class Functions
- java.lang.Object
-
- org.eclipse.collections.impl.block.factory.Functions
-
public final class Functions extends java.lang.Object
-
-
Nested Class Summary
-
Field Summary
Fields Modifier and Type Field Description private static CheckedFunction<java.lang.String,java.lang.Class<?>>CLASS_FOR_NAMEprivate static Function<java.lang.Object,java.lang.Class<?>>CLASS_FUNCTIONprivate static Function<java.lang.Double,java.lang.Double>DOUBLE_PASS_THRU_FUNCTIONprivate static Function<java.lang.Object,java.lang.Boolean>FALSE_FUNCTIONprivate static Functions.FirstOfPairFunction<?>FIRST_OF_PAIR_FUNCTIONprivate static Function<java.lang.Integer,java.lang.Integer>INTEGER_PASS_THRU_FUNCTIONprivate static Function<java.lang.Long,java.lang.Long>LONG_PASS_THRU_FUNCTIONprivate static Function<?,?>MAP_KEY_FUNCTIONprivate static Function<?,?>MAP_VALUE_FUNCTIONprivate static Function<java.lang.Number,java.lang.Double>MATH_SIN_FUNCTIONprivate static Function<?,?>PASS_THRU_FUNCTIONprivate static Functions.SecondOfPairFunction<?>SECOND_OF_PAIR_FUNCTIONprivate static Function<java.lang.Iterable<?>,java.lang.Integer>SIZE_FUNCTIONprivate static Function<java.lang.Integer,java.lang.Integer>SQUARED_INTEGERprivate static Function<java.lang.String,java.lang.Integer>STRING_TO_INTEGER_FUNCTIONprivate static Function<java.lang.String,java.lang.String>STRING_TRIM_FUNCTIONprivate static Functions.SwappedPairFunction<?,?>SWAPPED_PAIR_FUNCTIONprivate static Function<java.lang.Object,java.lang.String>TO_STRING_FUNCTIONprivate static Function<java.lang.Object,java.lang.Boolean>TRUE_FUNCTION
-
Constructor Summary
Constructors Modifier Constructor Description privateFunctions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,P,R>
Function<T,R>bind(Function2<? super T,? super P,? extends R> function, P parameter)Bind the parameter passed to a Function2 into a new Function.static <T1,T2>
ObjectIntProcedure<T1>bind(ObjectIntProcedure<? super T2> delegate, Function<? super T1,T2> function)Bind the input of a ObjectIntProcedure to the result of a function, returning a new ObjectIntProcedure.static <T1,T2>
Procedure<T1>bind(Procedure<? super T2> delegate, Function<? super T1,T2> function)Bind the input of a Procedure to the result of a function, returning a new Procedure.static <T1,T2,T3>
Procedure2<T1,T3>bind(Procedure2<? super T2,T3> delegate, Function<? super T1,T2> function)Bind the input of the first argument of a Procedure2 to the result of a function, returning a new Procedure2.static <T extends java.lang.Comparable<? super T>,V>
CaseFunction<T,V>caseDefault(Function<? super T,? extends V> defaultFunction)static <T extends java.lang.Comparable<? super T>,V>
CaseFunction<T,V>caseDefault(Function<? super T,? extends V> defaultFunction, Predicate<? super T> predicate, Function<? super T,? extends V> function)static <T,V>
Function<T,V>cast(Function<T,V> function)Allows a Java 8 lambda and method reference to be used in a method taking a Function as a parameter without any ambiguity.static <T1,T2,T3>
Functions.FunctionChain<T1,T2,T3>chain(Function<T1,T2> function1, Function<? super T2,T3> function2)static <T1,T2>
Functions.BooleanFunctionChain<T1,T2>chainBoolean(Function<T1,T2> function1, BooleanFunction<? super T2> function2)static <T1,T2>
Functions.ByteFunctionChain<T1,T2>chainByte(Function<T1,T2> function1, ByteFunction<? super T2> function2)static <T1,T2>
Functions.CharFunctionChain<T1,T2>chainChar(Function<T1,T2> function1, CharFunction<? super T2> function2)static <T1,T2>
Functions.DoubleFunctionChain<T1,T2>chainDouble(Function<T1,T2> function1, DoubleFunction<? super T2> function2)static <T1,T2>
Functions.FloatFunctionChain<T1,T2>chainFloat(Function<T1,T2> function1, FloatFunction<? super T2> function2)static <T1,T2>
Functions.IntFunctionChain<T1,T2>chainInt(Function<T1,T2> function1, IntFunction<? super T2> function2)static <T1,T2>
Functions.LongFunctionChain<T1,T2>chainLong(Function<T1,T2> function1, LongFunction<? super T2> function2)static <T1,T2>
Functions.ShortFunctionChain<T1,T2>chainShort(Function<T1,T2> function1, ShortFunction<? super T2> function2)static Function<java.lang.String,java.lang.Class<?>>classForName()static <T1,T2,I extends java.lang.Iterable<T2>>
Function<T1,I>firstNotEmptyCollectionValue(Function<T1,I>... functions)static <T> Function<T,java.lang.String>firstNotEmptyStringValue(Function<T,java.lang.String>... functions)static <T,V>
Function<T,V>firstNotNullValue(Function<T,V>... functions)static <V1> Function<Pair<V1,?>,V1>firstOfPair()static Function<java.lang.Double,java.lang.Double>getDoublePassThru()static Function<java.lang.Object,java.lang.Boolean>getFalse()static <T,V>
Function<T,V>getFixedValue(V value)static Function<java.lang.Integer,java.lang.Integer>getIntegerPassThru()static <K> Function<java.util.Map.Entry<K,?>,K>getKeyFunction()static Function<java.lang.Long,java.lang.Long>getLongPassThru()static Function<java.lang.Number,java.lang.Double>getMathSinFunction()static Function<java.lang.Object,java.lang.String>getNullSafeToString(java.lang.String defaultValue)static Function<java.lang.Number,java.lang.Number>getNumberPassThru()static <T> Function<T,T>getPassThru()Alias for identity().static Function<java.lang.Iterable<?>,java.lang.Integer>getSizeOf()static Function<java.lang.String,java.lang.String>getStringPassThru()static Function<java.lang.String,java.lang.Integer>getStringToInteger()static Function<java.lang.String,java.lang.String>getStringTrim()static Function<java.lang.Object,java.lang.Class<?>>getToClass()static Function<java.lang.Object,java.lang.String>getToString()static Function<java.lang.Object,java.lang.Boolean>getTrue()static <V> Function<java.util.Map.Entry<?,V>,V>getValueFunction()static <T> Function<T,T>identity()static <T,V>
Function<T,V>ifElse(Predicate<? super T> predicate, Function<? super T,? extends V> trueFunction, Function<? super T,? extends V> falseFunction)static <T,V>
Function<T,V>ifTrue(Predicate<? super T> predicate, Function<? super T,? extends V> function)static <T,V>
Function<T,V>nullSafe(Function<? super T,? extends V> function)static <T,V>
Function<T,V>nullSafe(Function<? super T,? extends V> function, V nullValue)static <T,V1,V2>
Function<T,Pair<V1,V2>>pair(Function<? super T,V1> function1, Function<? super T,V2> function2)static <V2> Function<Pair<?,V2>,V2>secondOfPair()static Function<java.lang.Integer,java.lang.Integer>squaredInteger()static <S,T>
Function<Pair<S,T>,Pair<T,S>>swappedPair()Swap the input pair and return the swapped pair.static <T,V>
Function<T,V>synchronizedEach(Function<T,V> function)static <T,V>
Function<T,V>throwing(ThrowingFunction<T,V> throwingFunction)Allows a lambda or anonymous inner class that needs to throw a checked exception to be safely wrapped as a Function that will throw a RuntimeException, wrapping the checked exception that is the cause.static <T,V>
Function<T,V>throwing(ThrowingFunction<T,V> throwingFunction, Function2<T,? super java.lang.Throwable,? extends java.lang.RuntimeException> rethrow)Allows a lambda or anonymous inner class that needs to throw a checked exception to be safely wrapped as a Function that will throw a user specified RuntimeException based on the provided function.static <T> SerializableComparator<T>toBooleanComparator(BooleanFunction<T> function)static <T> SerializableComparator<T>toByteComparator(ByteFunction<T> function)static <T> SerializableComparator<T>toCharComparator(CharFunction<T> function)static <T> SerializableComparator<T>toDoubleComparator(DoubleFunction<T> function)static <T> SerializableComparator<T>toFloatComparator(FloatFunction<T> function)static <T> SerializableComparator<T>toIntComparator(IntFunction<T> function)static <T> SerializableComparator<T>toLongComparator(LongFunction<T> function)static <T> SerializableComparator<T>toShortComparator(ShortFunction<T> function)static <T,V>
Function<T,V>withDefault(Function<? super T,? extends V> function, V defaultValue)
-
-
-
Field Detail
-
DOUBLE_PASS_THRU_FUNCTION
private static final Function<java.lang.Double,java.lang.Double> DOUBLE_PASS_THRU_FUNCTION
-
INTEGER_PASS_THRU_FUNCTION
private static final Function<java.lang.Integer,java.lang.Integer> INTEGER_PASS_THRU_FUNCTION
-
LONG_PASS_THRU_FUNCTION
private static final Function<java.lang.Long,java.lang.Long> LONG_PASS_THRU_FUNCTION
-
TRUE_FUNCTION
private static final Function<java.lang.Object,java.lang.Boolean> TRUE_FUNCTION
-
FALSE_FUNCTION
private static final Function<java.lang.Object,java.lang.Boolean> FALSE_FUNCTION
-
PASS_THRU_FUNCTION
private static final Function<?,?> PASS_THRU_FUNCTION
-
STRING_TRIM_FUNCTION
private static final Function<java.lang.String,java.lang.String> STRING_TRIM_FUNCTION
-
CLASS_FUNCTION
private static final Function<java.lang.Object,java.lang.Class<?>> CLASS_FUNCTION
-
MATH_SIN_FUNCTION
private static final Function<java.lang.Number,java.lang.Double> MATH_SIN_FUNCTION
-
SQUARED_INTEGER
private static final Function<java.lang.Integer,java.lang.Integer> SQUARED_INTEGER
-
TO_STRING_FUNCTION
private static final Function<java.lang.Object,java.lang.String> TO_STRING_FUNCTION
-
STRING_TO_INTEGER_FUNCTION
private static final Function<java.lang.String,java.lang.Integer> STRING_TO_INTEGER_FUNCTION
-
MAP_KEY_FUNCTION
private static final Function<?,?> MAP_KEY_FUNCTION
-
MAP_VALUE_FUNCTION
private static final Function<?,?> MAP_VALUE_FUNCTION
-
SIZE_FUNCTION
private static final Function<java.lang.Iterable<?>,java.lang.Integer> SIZE_FUNCTION
-
FIRST_OF_PAIR_FUNCTION
private static final Functions.FirstOfPairFunction<?> FIRST_OF_PAIR_FUNCTION
-
SECOND_OF_PAIR_FUNCTION
private static final Functions.SecondOfPairFunction<?> SECOND_OF_PAIR_FUNCTION
-
CLASS_FOR_NAME
private static final CheckedFunction<java.lang.String,java.lang.Class<?>> CLASS_FOR_NAME
-
SWAPPED_PAIR_FUNCTION
private static final Functions.SwappedPairFunction<?,?> SWAPPED_PAIR_FUNCTION
-
-
Method Detail
-
throwing
public static <T,V> Function<T,V> throwing(ThrowingFunction<T,V> throwingFunction)
Allows a lambda or anonymous inner class that needs to throw a checked exception to be safely wrapped as a Function that will throw a RuntimeException, wrapping the checked exception that is the cause.
-
throwing
public static <T,V> Function<T,V> throwing(ThrowingFunction<T,V> throwingFunction, Function2<T,? super java.lang.Throwable,? extends java.lang.RuntimeException> rethrow)
Allows a lambda or anonymous inner class that needs to throw a checked exception to be safely wrapped as a Function that will throw a user specified RuntimeException based on the provided function. The function is passed the current element and the checked exception that was thrown as context arguments.
-
cast
public static <T,V> Function<T,V> cast(Function<T,V> function)
Allows a Java 8 lambda and method reference to be used in a method taking a Function as a parameter without any ambiguity.
-
getPassThru
public static <T> Function<T,T> getPassThru()
Alias for identity(). Inlineable.- See Also:
identity()
-
identity
public static <T> Function<T,T> identity()
- Since:
- 6.0
-
getTrue
public static Function<java.lang.Object,java.lang.Boolean> getTrue()
- Since:
- 6.0
-
getFalse
public static Function<java.lang.Object,java.lang.Boolean> getFalse()
- Since:
- 6.0
-
getFixedValue
public static <T,V> Function<T,V> getFixedValue(V value)
-
getToClass
public static Function<java.lang.Object,java.lang.Class<?>> getToClass()
-
getMathSinFunction
public static Function<java.lang.Number,java.lang.Double> getMathSinFunction()
-
getNumberPassThru
public static Function<java.lang.Number,java.lang.Number> getNumberPassThru()
-
getIntegerPassThru
public static Function<java.lang.Integer,java.lang.Integer> getIntegerPassThru()
-
getLongPassThru
public static Function<java.lang.Long,java.lang.Long> getLongPassThru()
-
getDoublePassThru
public static Function<java.lang.Double,java.lang.Double> getDoublePassThru()
-
getStringPassThru
public static Function<java.lang.String,java.lang.String> getStringPassThru()
-
getStringTrim
public static Function<java.lang.String,java.lang.String> getStringTrim()
-
getToString
public static Function<java.lang.Object,java.lang.String> getToString()
-
getNullSafeToString
public static Function<java.lang.Object,java.lang.String> getNullSafeToString(java.lang.String defaultValue)
-
toBooleanComparator
public static <T> SerializableComparator<T> toBooleanComparator(BooleanFunction<T> function)
-
toByteComparator
public static <T> SerializableComparator<T> toByteComparator(ByteFunction<T> function)
-
toCharComparator
public static <T> SerializableComparator<T> toCharComparator(CharFunction<T> function)
-
toFloatComparator
public static <T> SerializableComparator<T> toFloatComparator(FloatFunction<T> function)
-
toShortComparator
public static <T> SerializableComparator<T> toShortComparator(ShortFunction<T> function)
-
toIntComparator
public static <T> SerializableComparator<T> toIntComparator(IntFunction<T> function)
-
toDoubleComparator
public static <T> SerializableComparator<T> toDoubleComparator(DoubleFunction<T> function)
-
toLongComparator
public static <T> SerializableComparator<T> toLongComparator(LongFunction<T> function)
-
getStringToInteger
public static Function<java.lang.String,java.lang.Integer> getStringToInteger()
-
withDefault
public static <T,V> Function<T,V> withDefault(Function<? super T,? extends V> function, V defaultValue)
-
nullSafe
public static <T,V> Function<T,V> nullSafe(Function<? super T,? extends V> function, V nullValue)
-
swappedPair
public static <S,T> Function<Pair<S,T>,Pair<T,S>> swappedPair()
Swap the input pair and return the swapped pair.- Returns:
- A function that gets the swapped pair
Iterable
-
bind
public static <T,P,R> Function<T,R> bind(Function2<? super T,? super P,? extends R> function, P parameter)
Bind the parameter passed to a Function2 into a new Function.- Parameters:
function- The Function2 to delegate the invocation to.parameter- The parameter the use in the invocation of the delegate function.- Returns:
- A new Function
-
bind
public static <T1,T2> Procedure<T1> bind(Procedure<? super T2> delegate, Function<? super T1,T2> function)
Bind the input of a Procedure to the result of a function, returning a new Procedure.- Parameters:
delegate- The Procedure to delegate the invocation to.function- The Function that will create the input for the delegate- Returns:
- A new Procedure
-
bind
public static <T1,T2> ObjectIntProcedure<T1> bind(ObjectIntProcedure<? super T2> delegate, Function<? super T1,T2> function)
Bind the input of a ObjectIntProcedure to the result of a function, returning a new ObjectIntProcedure.- Parameters:
delegate- The ObjectIntProcedure to delegate the invocation to.function- The Function that will create the input for the delegate- Returns:
- A new ObjectIntProcedure
-
bind
public static <T1,T2,T3> Procedure2<T1,T3> bind(Procedure2<? super T2,T3> delegate, Function<? super T1,T2> function)
Bind the input of the first argument of a Procedure2 to the result of a function, returning a new Procedure2.- Parameters:
delegate- The Procedure2 to delegate the invocation to.function- The Function that will create the input for the delegate- Returns:
- A new Procedure2
-
squaredInteger
public static Function<java.lang.Integer,java.lang.Integer> squaredInteger()
-
firstNotNullValue
public static <T,V> Function<T,V> firstNotNullValue(Function<T,V>... functions)
-
firstNotEmptyStringValue
public static <T> Function<T,java.lang.String> firstNotEmptyStringValue(Function<T,java.lang.String>... functions)
-
firstNotEmptyCollectionValue
public static <T1,T2,I extends java.lang.Iterable<T2>> Function<T1,I> firstNotEmptyCollectionValue(Function<T1,I>... functions)
-
ifTrue
public static <T,V> Function<T,V> ifTrue(Predicate<? super T> predicate, Function<? super T,? extends V> function)
-
ifElse
public static <T,V> Function<T,V> ifElse(Predicate<? super T> predicate, Function<? super T,? extends V> trueFunction, Function<? super T,? extends V> falseFunction)
-
caseDefault
public static <T extends java.lang.Comparable<? super T>,V> CaseFunction<T,V> caseDefault(Function<? super T,? extends V> defaultFunction)
-
caseDefault
public static <T extends java.lang.Comparable<? super T>,V> CaseFunction<T,V> caseDefault(Function<? super T,? extends V> defaultFunction, Predicate<? super T> predicate, Function<? super T,? extends V> function)
-
classForName
public static Function<java.lang.String,java.lang.Class<?>> classForName()
-
chain
public static <T1,T2,T3> Functions.FunctionChain<T1,T2,T3> chain(Function<T1,T2> function1, Function<? super T2,T3> function2)
-
chainBoolean
public static <T1,T2> Functions.BooleanFunctionChain<T1,T2> chainBoolean(Function<T1,T2> function1, BooleanFunction<? super T2> function2)
-
chainByte
public static <T1,T2> Functions.ByteFunctionChain<T1,T2> chainByte(Function<T1,T2> function1, ByteFunction<? super T2> function2)
-
chainChar
public static <T1,T2> Functions.CharFunctionChain<T1,T2> chainChar(Function<T1,T2> function1, CharFunction<? super T2> function2)
-
chainDouble
public static <T1,T2> Functions.DoubleFunctionChain<T1,T2> chainDouble(Function<T1,T2> function1, DoubleFunction<? super T2> function2)
-
chainFloat
public static <T1,T2> Functions.FloatFunctionChain<T1,T2> chainFloat(Function<T1,T2> function1, FloatFunction<? super T2> function2)
-
chainInt
public static <T1,T2> Functions.IntFunctionChain<T1,T2> chainInt(Function<T1,T2> function1, IntFunction<? super T2> function2)
-
chainLong
public static <T1,T2> Functions.LongFunctionChain<T1,T2> chainLong(Function<T1,T2> function1, LongFunction<? super T2> function2)
-
chainShort
public static <T1,T2> Functions.ShortFunctionChain<T1,T2> chainShort(Function<T1,T2> function1, ShortFunction<? super T2> function2)
-
pair
public static <T,V1,V2> Function<T,Pair<V1,V2>> pair(Function<? super T,V1> function1, Function<? super T,V2> function2)
-
getKeyFunction
public static <K> Function<java.util.Map.Entry<K,?>,K> getKeyFunction()
- Returns:
- A function that gets the key out of a
Map.Entry
-
getValueFunction
public static <V> Function<java.util.Map.Entry<?,V>,V> getValueFunction()
- Returns:
- A function that gets the value out of a
Map.Entry
-
getSizeOf
public static Function<java.lang.Iterable<?>,java.lang.Integer> getSizeOf()
- Returns:
- A function that gets the size of an
Iterable
-
-