Class Algorithms
java.lang.Object
org.glassfish.pfl.basic.algorithm.Algorithms
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic <A> UnaryPredicate<A>and(UnaryPredicate<A> arg1, UnaryPredicate<A> arg2) static ListconvertToList(Object arg) Converts obj from an Array to a List, if obj is an array.static StringconvertToString(Object arg) Convert argument to String, either by toString, ot Arrays.toString.static <T> TdoPrivileged(Algorithms.Action<T> func) static <T> UnaryPredicate<T>static <A> voidfilter(List<A> arg, List<A> result, UnaryPredicate<A> predicate) static <A> List<A>filter(List<A> arg, UnaryPredicate<A> predicate) static <A> Afind(List<A> arg, UnaryPredicate<A> predicate) static <S,T> List<T> flatten(List<S> list, UnaryFunction<S, List<T>> map) Flatten the results of applying map to list into a list of T.static <A,R> R fold(List<A> list, R initial, BinaryFunction<R, A, R> func) getAnnotationValues(Annotation ann, boolean convertArraysToLists) Given an annotation, return a Map that maps each field (given by a method name) to its value in the annotation.static <T> TgetFirst(Collection<T> list, Runnable handleEmptyList) Return the first element of the list, or invoke handleEmptyList if list is empty.static <T> List<T>list(T... arg) Deprecated.static <A,R> void map(Collection<A> arg, Collection<R> result, UnaryFunction<A, R> func) static <A,R> List<R> map(List<A> arg, UnaryFunction<A, R> func) static <K,A, R> Map<K, R> map(Map<K, A> arg, UnaryFunction<A, R> func) static <K,V> Map<K, V> static <A,R> UnaryFunction<A, R> mapToFunction(Map<A, R> map) static <A> UnaryPredicate<A>not(UnaryPredicate<A> arg1) static <A> UnaryPredicate<A>or(UnaryPredicate<A> arg1, UnaryPredicate<A> arg2) static <S,T> Pair<S, T> pair(S first, T second) static <T> UnaryPredicate<T>
-
Method Details
-
list
Deprecated.replaced byArrays.asList(java.lang.Object...)Converts an array of objects into a list- Type Parameters:
T- type of objects- Parameters:
arg- the array of objects- Returns:
- list of objects
-
pair
-
map
-
mapToFunction
-
map
-
map
-
map
-
and
-
or
-
FALSE
-
TRUE
-
not
-
filter
-
filter
-
find
-
fold
-
flatten
Flatten the results of applying map to list into a list of T.- Type Parameters:
S- Type of elements of list.T- Type of elements of result.- Parameters:
list- List of elements of type S.map- function mapping S toList<T>.- Returns:
List<T>containing results of applying map to each element of list.
-
getFirst
Return the first element of the list, or invoke handleEmptyList if list is empty.- Type Parameters:
T- The type of the list element.- Parameters:
list- The listhandleEmptyList- A runnable to call when the list is empty. Typically throws an exception.- Returns:
- The first element of the list, if any.
-
convertToList
Converts obj from an Array to a List, if obj is an array. Otherwise just returns a List containing obj. -
convertToString
Convert argument to String, either by toString, ot Arrays.toString.- Parameters:
arg- Object to convert.
-
getAnnotationValues
Given an annotation, return a Map that maps each field (given by a method name) to its value in the annotation. If the value is an annotation, that value is recursively converted into a Map in the same way.- Parameters:
ann- The annotation to examine.convertArraysToLists- true if annotation values of array type should be converted to an appropriate list. This is often MUCH more useful, but some contexts require arrays.- Returns:
- A map of annotation fields to their values.
-
doPrivileged
-
Arrays.asList(java.lang.Object...)