Package com.atlassian.adf.util
Class Functions
- java.lang.Object
-
- com.atlassian.adf.util.Functions
-
@Internal @ReturnValuesAreNonnullByDefault public abstract class Functions extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> booleaniterateJoined(Iterable<T> source, Consumer<? super T> effect, Runnable joiner)Iterates thesourcecollection, callingeffectfor each element with calls to thejoinerbetween them.static <T,U>
List<U>mapToList(Iterable<T> source, Function<? super T,? extends U> mapper)Given an iterable collection, map each element from the collection to a new value and return the resulting values as a list.static <T,U>
List<U>mapToList(Stream<T> source, Function<? super T,? extends U> mapper)Given a stream, map each element from it to a new value and return the resulting values as a list.static <T,U>
List<U>mapToList(T[] source, Function<? super T,? extends U> mapper)Given an array, map each element from the array to a new value and return the resulting values as a list.static <T> Function<T,Void>voidFn(Consumer<T> effect)Convenience wrapper to turn aConsumer<T>into aFunction<T, Void>.
-
-
-
Method Detail
-
voidFn
public static <T> Function<T,Void> voidFn(Consumer<T> effect)
Convenience wrapper to turn aConsumer<T>into aFunction<T, Void>. It is common to need to do this when working with lambdas, and unfortunately Java doesn't know how to work this out for itself.- Type Parameters:
T- the inferred input parameter type for the originalConsumer- Parameters:
effect- the consumer to be reimagined as aVoid-returning function- Returns:
- the resulting function that returns
Void
-
mapToList
public static <T,U> List<U> mapToList(T[] source, Function<? super T,? extends U> mapper)
Given an array, map each element from the array to a new value and return the resulting values as a list.- Type Parameters:
T- the inferred input typeU- the inferred output type- Parameters:
source- the array of input valuesmapper- the mapping function to apply to each input value; must not returnnull- Returns:
- an (unmodifiable) list of the resulting values
-
mapToList
public static <T,U> List<U> mapToList(Iterable<T> source, Function<? super T,? extends U> mapper)
Given an iterable collection, map each element from the collection to a new value and return the resulting values as a list.- Type Parameters:
T- the inferred input typeU- the inferred output type- Parameters:
source- the collection of input valuesmapper- the mapping function to apply to each input value; must not returnnull- Returns:
- an (unmodifiable) list of the resulting values
-
mapToList
public static <T,U> List<U> mapToList(Stream<T> source, Function<? super T,? extends U> mapper)
Given a stream, map each element from it to a new value and return the resulting values as a list.- Type Parameters:
T- the inferred input typeU- the inferred output type- Parameters:
source- the stream of input valuesmapper- the mapping function to apply to each input value; must not returnnull- Returns:
- an (unmodifiable) list of the resulting values
-
iterateJoined
public static <T> boolean iterateJoined(Iterable<T> source, Consumer<? super T> effect, Runnable joiner)
Iterates thesourcecollection, callingeffectfor each element with calls to thejoinerbetween them. If thesourcecollection is empty, there is no effect.For example, if
sourceisList.of("foo", "bar", "baz"), then the sequence of calls will be:effect.accept("foo"); joiner.run(); effect.accept("bar"); joiner.run(); effect.accept("baz");- Type Parameters:
T- the inferred element type supplied bysource- Parameters:
source- supplies the elements to iterate overeffect- what to do with each element from the collectionjoiner- what to do between any two elements from the collection- Returns:
trueif thesourcecollection supplied at least one element;falseif it was empty
-
-