Package graphql.util

Class FpKit

java.lang.Object
graphql.util.FpKit

public class FpKit extends Object
  • Constructor Details

    • FpKit

      public FpKit()
  • Method Details

    • getByName

      public static <T> Map<String,T> getByName(List<T> namedObjects, Function<T,String> nameFn, BinaryOperator<T> mergeFunc)
    • toMap

      public static <T, NewKey> Map<NewKey,T> toMap(Collection<T> collection, Function<T,NewKey> keyFunction, BinaryOperator<T> mergeFunc)
    • groupingBy

      public static <T, NewKey> Map<NewKey,com.google.common.collect.ImmutableList<T>> groupingBy(Collection<T> list, Function<T,NewKey> function)
    • filterAndGroupingBy

      public static <T, NewKey> Map<NewKey,com.google.common.collect.ImmutableList<T>> filterAndGroupingBy(Collection<T> list, Predicate<? super T> predicate, Function<T,NewKey> function)
    • toMapByUniqueKey

      public static <T, NewKey> Map<NewKey,T> toMapByUniqueKey(Collection<T> list, Function<T,NewKey> keyFunction)
    • getByName

      public static <T> Map<String,T> getByName(List<T> namedObjects, Function<T,String> nameFn)
    • mergeFirst

      public static <T> BinaryOperator<T> mergeFirst()
    • toCollection

      public static <T> Collection<T> toCollection(Object iterableResult)
      Converts an object that should be an Iterable into a Collection efficiently, leaving it alone if it is already is one. Useful when you want to get the size of something
      Type Parameters:
      T - the type of thing
      Parameters:
      iterableResult - the result object
      Returns:
      an Iterable from that object
      Throws:
      ClassCastException - if it's not an Iterable
    • arrayListSizedTo

      public static <T> @NonNull List<T> arrayListSizedTo(@NonNull Collection<?> collection)
      Creates an ArrayList sized appropriately to the collection, typically for copying
      Type Parameters:
      T - to two
      Parameters:
      collection - the collection of a certain size
      Returns:
      a new ArrayList initially sized to the same as the collection
    • toListOrSingletonList

      public static <T> List<T> toListOrSingletonList(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
      Type Parameters:
      T - for two
      Parameters:
      possibleIterable - the possible
      Returns:
      an list one way or another
    • isIterable

      public static boolean isIterable(Object result)
    • toIterable

      public static <T> Iterable<T> toIterable(Object iterableResult)
    • toSize

      public static OptionalInt toSize(Object iterableResult)
    • concat

      public static <T> List<T> concat(List<T> l, T t)
      Concatenates (appends) a single elements to an existing list
      Type Parameters:
      T - the type of elements of the list
      Parameters:
      l - the list onto which to append the element
      t - the element to append
      Returns:
      a new list composed of the first list elements and the new element
    • concat

      public static <T> List<T> concat(List<T> l1, List<T> l2)
      Concatenates two lists into one
      Type Parameters:
      T - the type of element of the lists
      Parameters:
      l1 - the first list to concatenate
      l2 - the second list to concatenate
      Returns:
      a new list composed of the two concatenated lists elements
    • valuesToList

      public static <T> List<T> valuesToList(Map<?,T> map)
    • transposeMatrix

      public static <T> List<List<T>> transposeMatrix(List<? extends List<T>> matrix)
    • findOne

      public static <T> Optional<T> findOne(Collection<T> list, Predicate<T> filter)
    • findOneOrNull

      public static <T> T findOneOrNull(List<T> list, Predicate<T> filter)
    • findIndex

      public static <T> int findIndex(List<T> list, Predicate<T> filter)
    • filterList

      public static <T> List<T> filterList(Collection<T> list, Predicate<T> filter)
    • filterSet

      public static <T> Set<T> filterSet(Collection<T> input, Predicate<T> filter)
    • newList

      public static <K, V> Function<K,List<V>> newList()
      Type Parameters:
      K - for Key
      V - for Value
      Returns:
      a function that allocates a list
    • intraThreadMemoize

      public static <T> Supplier<T> intraThreadMemoize(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. This means that it's possible that your delegate supplier MAY be called more than once across threads, but only once on the same thread.
      Type Parameters:
      T - for two
      Parameters:
      delegate - the supplier to delegate to
      Returns:
      a supplier that will memoize values in the context of the current thread
    • interThreadMemoize

      public static <T> Supplier<T> interThreadMemoize(Supplier<T> delegate)
      This will memoize the Supplier across threads and make sure the Supplier is exactly called once.

      Use for potentially costly actions. Otherwise consider intraThreadMemoize(Supplier)

      Type Parameters:
      T - for two
      Parameters:
      delegate - the supplier to delegate to
      Returns:
      a supplier that will memoize values in the context of the all the threads
    • intersection

      public static <T> Set<T> intersection(Set<T> set1, Set<T> set2)
      Faster set intersection.
      Type Parameters:
      T - for two
      Parameters:
      set1 - first set
      set2 - second set
      Returns:
      intersection set