Class Collections3


  • public final class Collections3
    extends Object
    • Method Detail

      • add

        public static <E> List<E> add​(List<E> list,
                                      E element)
      • add

        public static <K,​V> Map<K,​V> add​(Map<K,​V> map,
                                                     K key,
                                                     V value)
      • add

        public static <E> Set<E> add​(Set<E> set,
                                     E element)
      • forEachPair

        public static <E1,​E2> void forEachPair​(Iterable<E1> iterable1,
                                                     Iterable<E2> iterable2,
                                                     BiConsumer<E1,​E2> action)
      • isDistinct

        public static <E> boolean isDistinct​(List<E> collection)
      • ofNullable

        public static <E> Set<E> ofNullable​(@Nullable
                                            E element)
      • maximalElements

        public static <E> List<E> maximalElements​(List<E> elements,
                                                  BiPredicate<E,​E> isLessThan)
        Computes a sub-list of elements which are maximal. The order is preserved.
        Type Parameters:
        E - the type
        Parameters:
        elements - the elements
        isLessThan - returns true is the first argument is less than the second argument. It is only required that the order is transitive and anti-symmetric. The reflexive hull is added automatically.
        Returns:
        a sublist only containing maximal elements.
      • partition

        public static <E> List<Set<E>> partition​(Collection<E> elements,
                                                 BiPredicate<E,​E> relation)
        Partition the elements using the given relation.
        Type Parameters:
        E - the element type.
        Parameters:
        elements - the collection containing the elements that are group into partitions.
        relation - the relation used to construct the partition. It is only required this relation is symmetric. The transitive and reflexive hull are computed automatically.
        Returns:
        the partition.
      • transformMap

        public static <K1,​K2,​V> Map<K2,​V> transformMap​(Map<K1,​V> map,
                                                                         Function<K1,​K2> transformer,
                                                                         BiFunction<? super V,​? super V,​? extends V> valueMerger)
      • transformSet

        public static <E1,​E2> Set<E2> transformSet​(Set<E1> set,
                                                         Function<E1,​E2> transformer)
        Creates a new Set by applying the transformer on each element of set.

        The implementation does not access Collection.isEmpty() or Collection.size()), since computing these values on live views might be expensive and cause a full traversal.

        Type Parameters:
        E1 - the element type of the input
        E2 - the element type of the return value
        Parameters:
        set - the input set.
        transformer - the translator function. It is not allowed to return null, since the used data-structures might be null-hostile.
        Returns:
        a new set containing all transformed objects
      • union

        public static <E> Set<E> union​(Set<E> set1,
                                       Set<E> set2)
      • compare

        public static <E extends Object & Comparable<? super E>> int compare​(Set<? extends E> s1,
                                                                             Set<? extends E> s2)