Class HCollection


  • public final class HCollection
    extends Object
    • Method Detail

      • asIndexMap

        public static <T> Map<T,​Integer> asIndexMap​(List<T> list)
      • add

        public static <K,​C extends Collection<V>,​V> void add​(Map<K,​C> map,
                                                                         Supplier<? extends C> constructor,
                                                                         K key,
                                                                         V value)
      • asList

        public static <T> List<T> asList​(Collection<T> collection)
      • asListRepeated

        public static <T> List<T> asListRepeated​(int count,
                                                 T element)
      • asListNonNull

        @SafeVarargs
        public static <T> List<T> asListNonNull​(T... elements)
      • totalSize

        public static int totalSize​(Collection<?>... collections)
      • difference

        public static <T> Set<T> difference​(Collection<? extends T> minuend,
                                            Collection<? extends T> subtrahend)
      • get

        public static <T> T get​(Iterable<? extends T> collection,
                                int index)
        Get the element at the specified index within the specified collection. Supports negative indices to start from the end of the list.
        Type Parameters:
        T - A supertype of the elements of the collection.
        Parameters:
        collection - The collection to get an element from.
        index - The index of the element to get. Must in the range -size <= index < size
        Returns:
        The element at the specified index.
      • getAny

        public static <T> T getAny​(Iterable<? extends T> iterable)
      • emptyList

        public static <T> List<T> emptyList()
      • emptySet

        public static <T> Set<T> emptySet()
      • getFirst

        public static <T> T getFirst​(Iterable<? extends T> iterable)
      • getLast

        public static <T> T getLast​(Iterable<? extends T> iterable)
      • getLast

        public static <T> int getLast​(List<? extends T> list,
                                      Predicate<? super T> test)
      • getLast

        public static <T> int getLast​(List<? extends T> list,
                                      BiPredicate<Integer,​? super T> test)
      • getOne

        public static <T> T getOne​(Iterable<? extends T> iterable)
        Get the single item from an iterable. Throw an exception if there are either fewer or more than one items.
        Type Parameters:
        T - The type of the items
        Parameters:
        iterable - The iterable to get the single item from
        Returns:
        The single item in the iterable
        Throws:
        IllegalArgumentException - if there are 0, 2 or more items in iterable
      • getOneOptional

        public static <T> T getOneOptional​(Iterable<? extends T> iterable,
                                           ISupplier<? extends T> ifNone)
      • isOne

        public static boolean isOne​(Iterable<?> iterable,
                                    Object object)
        Test if an iterable contains a single, specified, item.
        Parameters:
        iterable - The iterable to search.
        object - The object to search for.
        Returns:
        true if iterable contains object and nothing else.
      • removeAny

        public static <T> T removeAny​(Collection<T> collection)
      • toList

        public static <T> List<T> toList​(Iterable<T> iterable)