java.lang.Object
org.glassfish.pfl.basic.algorithm.Algorithms

public final class Algorithms extends Object
  • Method Details

    • pair

      public static <S, T> Pair<S,T> pair(S first, T second)
    • map

      public static <K, V> Map<K,V> map(Pair<K,V>... pairs)
    • mapToFunction

      public static <A, R> UnaryFunction<A,R> mapToFunction(Map<A,R> map)
    • map

      public static <A, R> void map(Collection<A> arg, Collection<R> result, UnaryFunction<A,R> func)
    • map

      public static <K, A, R> Map<K,R> map(Map<K,A> arg, UnaryFunction<A,R> func)
    • map

      public static <A, R> List<R> map(List<A> arg, UnaryFunction<A,R> func)
    • and

      public static <A> UnaryPredicate<A> and(UnaryPredicate<A> arg1, UnaryPredicate<A> arg2)
    • or

      public static <A> UnaryPredicate<A> or(UnaryPredicate<A> arg1, UnaryPredicate<A> arg2)
    • FALSE

      public static <T> UnaryPredicate<T> FALSE(Class<T> cls)
    • TRUE

      public static <T> UnaryPredicate<T> TRUE(Class<T> cls)
    • not

      public static <A> UnaryPredicate<A> not(UnaryPredicate<A> arg1)
    • filter

      public static <A> void filter(List<A> arg, List<A> result, UnaryPredicate<A> predicate)
    • filter

      public static <A> List<A> filter(List<A> arg, UnaryPredicate<A> predicate)
    • find

      public static <A> A find(List<A> arg, UnaryPredicate<A> predicate)
    • fold

      public static <A, R> R fold(List<A> list, R initial, BinaryFunction<R,A,R> func)
    • flatten

      public 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.
      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 to List<T>.
      Returns:
      List<T> containing results of applying map to each element of list.
    • getFirst

      public static <T> T getFirst(Collection<T> list, Runnable handleEmptyList)
      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 list
      handleEmptyList - A runnable to call when the list is empty. Typically throws an exception.
      Returns:
      The first element of the list, if any.
    • convertToList

      public static List convertToList(Object arg)
      Converts obj from an Array to a List, if obj is an array. Otherwise just returns a List containing obj.
    • convertToString

      public static String convertToString(Object arg)
      Convert argument to String, either by toString, ot Arrays.toString.
      Parameters:
      arg - Object to convert.
    • doPrivileged

      public static <T> T doPrivileged(Algorithms.Action<T> func)