Package graphql.util

Class FpKit


  • public class FpKit
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      FpKit()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method 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,​NewKey>
      java.util.Map<NewKey,​com.google.common.collect.ImmutableList<T>>
      filterAndGroupingBy​(java.util.Collection<T> list, java.util.function.Predicate<? super T> predicate, java.util.function.Function<T,​NewKey> function)  
      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,​com.google.common.collect.ImmutableList<T>>
      groupingBy​(java.util.stream.Stream<T> stream, 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,​NewKey>
      java.util.Map<NewKey,​T>
      groupingByUniqueKey​(java.util.stream.Stream<T> stream, java.util.function.Function<T,​NewKey> keyFunction)  
      static <T> java.util.Set<T> intersection​(java.util.Set<T> set1, java.util.Set<T> set2)
      Faster set intersection.
      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)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FpKit

        public FpKit()
    • Method Detail

      • getByName

        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)
      • groupingBy

        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)
      • filterAndGroupingBy

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

        public static <T,​NewKey> java.util.Map<NewKey,​com.google.common.collect.ImmutableList<T>> groupingBy​(java.util.stream.Stream<T> stream,
                                                                                                                         java.util.function.Function<T,​NewKey> function)
      • groupingByUniqueKey

        public static <T,​NewKey> java.util.Map<NewKey,​T> groupingByUniqueKey​(java.util.Collection<T> list,
                                                                                         java.util.function.Function<T,​NewKey> keyFunction)
      • groupingByUniqueKey

        public static <T,​NewKey> java.util.Map<NewKey,​T> groupingByUniqueKey​(java.util.stream.Stream<T> stream,
                                                                                         java.util.function.Function<T,​NewKey> keyFunction)
      • getByName

        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)
      • mergeFirst

        public static <T> java.util.function.BinaryOperator<T> mergeFirst()
      • toCollection

        public 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. 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:
        java.lang.ClassCastException - if it's not an Iterable
      • toListOrSingletonList

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

        public static boolean isIterable​(java.lang.Object result)
      • toIterable

        public static <T> java.lang.Iterable<T> toIterable​(java.lang.Object iterableResult)
      • toSize

        public static java.util.OptionalInt toSize​(java.lang.Object iterableResult)
      • concat

        public static <T> java.util.List<T> concat​(java.util.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> java.util.List<T> concat​(java.util.List<T> l1,
                                                   java.util.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> java.util.List<T> valuesToList​(java.util.Map<?,​T> map)
      • mapEntries

        public static <K,​V,​U> java.util.List<U> mapEntries​(java.util.Map<K,​V> map,
                                                                       java.util.function.BiFunction<K,​V,​U> function)
      • transposeMatrix

        public static <T> java.util.List<java.util.List<T>> transposeMatrix​(java.util.List<? extends java.util.List<T>> matrix)
      • flatList

        public static <T> java.util.concurrent.CompletableFuture<java.util.List<T>> flatList​(java.util.concurrent.CompletableFuture<java.util.List<java.util.List<T>>> cf)
      • flatList

        public static <T> java.util.List<T> flatList​(java.util.List<java.util.List<T>> listLists)
      • findOne

        public static <T> java.util.Optional<T> findOne​(java.util.Collection<T> list,
                                                        java.util.function.Predicate<T> filter)
      • findOneOrNull

        public static <T> T findOneOrNull​(java.util.List<T> list,
                                          java.util.function.Predicate<T> filter)
      • findIndex

        public static <T> int findIndex​(java.util.List<T> list,
                                        java.util.function.Predicate<T> filter)
      • filterList

        public static <T> java.util.List<T> filterList​(java.util.Collection<T> list,
                                                       java.util.function.Predicate<T> filter)
      • filterSet

        public static <T> java.util.Set<T> filterSet​(java.util.Collection<T> input,
                                                     java.util.function.Predicate<T> filter)
      • newList

        public static <K,​V> java.util.function.Function<K,​java.util.List<V>> newList()
        Used in simple Map.computeIfAbsent(Object, java.util.function.Function) cases
        Type Parameters:
        K - for Key
        V - for Value
        Returns:
        a function that allocates a list
      • intraThreadMemoize

        public 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. 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> 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.

        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> java.util.Set<T> intersection​(java.util.Set<T> set1,
                                                        java.util.Set<T> set2)
        Faster set intersection.
        Type Parameters:
        T - for two
        Parameters:
        set1 - first set
        set2 - second set
        Returns:
        intersection set