public class FpKit
extends java.lang.Object
Constructor and Description |
---|
FpKit() |
Modifier and Type | Method and Description |
---|---|
static <T> java.util.List<T> |
concat(java.util.List<T> l1,
java.util.List<T> l2)
Concatenates two lists into one
|
static <T> java.util.List<T> |
concat(java.util.List<T> l,
T t)
Concatenates (appends) a single elements to an existing list
|
static <T> java.util.List<T> |
filterList(java.util.Collection<T> list,
java.util.function.Predicate<T> filter) |
static <T> java.util.Set<T> |
filterSet(java.util.Collection<T> input,
java.util.function.Predicate<T> filter) |
static <T> int |
findIndex(java.util.List<T> list,
java.util.function.Predicate<T> filter) |
static <T> java.util.Optional<T> |
findOne(java.util.Collection<T> list,
java.util.function.Predicate<T> filter) |
static <T> T |
findOneOrNull(java.util.List<T> list,
java.util.function.Predicate<T> filter) |
static <T> java.util.concurrent.CompletableFuture<java.util.List<T>> |
flatList(java.util.concurrent.CompletableFuture<java.util.List<java.util.List<T>>> cf) |
static <T> java.util.List<T> |
flatList(java.util.List<java.util.List<T>> listLists) |
static <T> java.util.Map<java.lang.String,T> |
getByName(java.util.List<T> namedObjects,
java.util.function.Function<T,java.lang.String> nameFn) |
static <T> java.util.Map<java.lang.String,T> |
getByName(java.util.List<T> namedObjects,
java.util.function.Function<T,java.lang.String> nameFn,
java.util.function.BinaryOperator<T> mergeFunc) |
static <T,NewKey> java.util.Map<NewKey,com.google.common.collect.ImmutableList<T>> |
groupingBy(java.util.Collection<T> list,
java.util.function.Function<T,NewKey> function) |
static <T,NewKey> java.util.Map<NewKey,T> |
groupingByUniqueKey(java.util.Collection<T> list,
java.util.function.Function<T,NewKey> keyFunction) |
static <T> java.util.function.Supplier<T> |
interThreadMemoize(java.util.function.Supplier<T> delegate)
This will memoize the Supplier across threads and make sure the Supplier is exactly called once.
|
static <T> java.util.function.Supplier<T> |
intraThreadMemoize(java.util.function.Supplier<T> delegate)
This will memoize the Supplier within the current thread's visibility, that is it does not
use volatile reads but rather use a sentinel check and re-reads the delegate supplier
value if the read has not stuck to this thread.
|
static boolean |
isIterable(java.lang.Object result) |
static <K,V,U> java.util.List<U> |
mapEntries(java.util.Map<K,V> map,
java.util.function.BiFunction<K,V,U> function) |
static <T> java.util.function.BinaryOperator<T> |
mergeFirst() |
static <K,V> java.util.function.Function<K,java.util.List<V>> |
newList()
Used in simple
Map.computeIfAbsent(Object, java.util.function.Function) cases |
static <T> java.util.Collection<T> |
toCollection(java.lang.Object iterableResult)
Converts an object that should be an Iterable into a Collection efficiently, leaving
it alone if it is already is one.
|
static <T> java.lang.Iterable<T> |
toIterable(java.lang.Object iterableResult) |
static <T> java.util.List<T> |
toListOrSingletonList(java.lang.Object possibleIterable)
Converts a value into a list if it's really a collection or array of things
else it turns it into a singleton list containing that one value
|
static java.util.OptionalInt |
toSize(java.lang.Object iterableResult) |
static <T> java.util.List<java.util.List<T>> |
transposeMatrix(java.util.List<? extends java.util.List<T>> matrix) |
static <T> java.util.List<T> |
valuesToList(java.util.Map<?,T> map) |
public static <T> java.util.Map<java.lang.String,T> getByName(java.util.List<T> namedObjects, java.util.function.Function<T,java.lang.String> nameFn, java.util.function.BinaryOperator<T> mergeFunc)
public static <T,NewKey> java.util.Map<NewKey,com.google.common.collect.ImmutableList<T>> groupingBy(java.util.Collection<T> list, java.util.function.Function<T,NewKey> function)
public static <T,NewKey> java.util.Map<NewKey,T> groupingByUniqueKey(java.util.Collection<T> list, java.util.function.Function<T,NewKey> keyFunction)
public static <T> java.util.Map<java.lang.String,T> getByName(java.util.List<T> namedObjects, java.util.function.Function<T,java.lang.String> nameFn)
public static <T> java.util.function.BinaryOperator<T> mergeFirst()
public static <T> java.util.Collection<T> toCollection(java.lang.Object iterableResult)
T
- the type of thingiterableResult
- the result objectjava.lang.ClassCastException
- if it's not an Iterablepublic static <T> java.util.List<T> toListOrSingletonList(java.lang.Object possibleIterable)
T
- for twopossibleIterable
- the possiblepublic static boolean isIterable(java.lang.Object result)
public static <T> java.lang.Iterable<T> toIterable(java.lang.Object iterableResult)
public static java.util.OptionalInt toSize(java.lang.Object iterableResult)
public static <T> java.util.List<T> concat(java.util.List<T> l, T t)
T
- the type of elements of the listl
- the list onto which to append the elementt
- the element to appendpublic static <T> java.util.List<T> concat(java.util.List<T> l1, java.util.List<T> l2)
T
- the type of element of the listsl1
- the first list to concatenatel2
- the second list to concatenatepublic static <T> java.util.List<T> valuesToList(java.util.Map<?,T> map)
public static <K,V,U> java.util.List<U> mapEntries(java.util.Map<K,V> map, java.util.function.BiFunction<K,V,U> function)
public static <T> java.util.List<java.util.List<T>> transposeMatrix(java.util.List<? extends java.util.List<T>> matrix)
public static <T> java.util.concurrent.CompletableFuture<java.util.List<T>> flatList(java.util.concurrent.CompletableFuture<java.util.List<java.util.List<T>>> cf)
public static <T> java.util.List<T> flatList(java.util.List<java.util.List<T>> listLists)
public static <T> java.util.Optional<T> findOne(java.util.Collection<T> list, java.util.function.Predicate<T> filter)
public static <T> T findOneOrNull(java.util.List<T> list, java.util.function.Predicate<T> filter)
public static <T> int findIndex(java.util.List<T> list, java.util.function.Predicate<T> filter)
public static <T> java.util.List<T> filterList(java.util.Collection<T> list, java.util.function.Predicate<T> filter)
public static <T> java.util.Set<T> filterSet(java.util.Collection<T> input, java.util.function.Predicate<T> filter)
public static <K,V> java.util.function.Function<K,java.util.List<V>> newList()
Map.computeIfAbsent(Object, java.util.function.Function)
casesK
- for KeyV
- for Valuepublic static <T> java.util.function.Supplier<T> intraThreadMemoize(java.util.function.Supplier<T> delegate)
T
- for twodelegate
- the supplier to delegate topublic static <T> java.util.function.Supplier<T> interThreadMemoize(java.util.function.Supplier<T> delegate)
Use for potentially costly actions. Otherwise consider intraThreadMemoize(Supplier)
T
- for twodelegate
- the supplier to delegate to