Class CollectionUtil

    • Method Detail

      • toStream

        public static <T> Stream<T> toStream​(@NonNull
                                             Iterator<T> iterator)
        Get a Stream for the provided Iterable.
        Type Parameters:
        T - the type to iterate on
        Parameters:
        iterator - the iterator
        Returns:
        the stream
      • toIterable

        @NonNull
        public static <T> Iterable<T> toIterable​(@NonNull
                                                 Stream<T> stream)
        Get an Iterable for the provided Stream.
        Type Parameters:
        T - the type to iterate on
        Parameters:
        stream - the stream to iterate over
        Returns:
        the resulting iterable instance
      • toIterable

        @NonNull
        public static <T> Iterable<T> toIterable​(@NonNull
                                                 Iterator<T> iterator)
        Get an Iterable for the provided Iterator.
        Type Parameters:
        T - the type to iterate on
        Parameters:
        iterator - the iterator
        Returns:
        the resulting iterable instance
      • toDescendingIterable

        @NonNull
        public static <T> Iterable<T> toDescendingIterable​(@NonNull
                                                           List<T> list)
        Get a reverse Iterable for the provided List.
        Type Parameters:
        T - the type to iterate on
        Parameters:
        list - the list of items to iterate over
        Returns:
        the resulting iterable instance
      • toList

        @NonNull
        public static <T> List<T> toList​(Iterable<T> iterable)
        Convert the provided Iterable to a list of the same generic type.
        Type Parameters:
        T - the collection item's generic type
        Parameters:
        iterable - the Iterable to convert to a list
        Returns:
        the list
      • toList

        @NonNull
        public static <T> List<T> toList​(Iterator<T> iterator)
        Convert the provided Iterator to a list of the same generic type.
        Type Parameters:
        T - the collection item's generic type
        Parameters:
        iterator - the Iterator to convert to a list
        Returns:
        the list
      • descendingIterator

        @NonNull
        public static <T> Iterator<T> descendingIterator​(@NonNull
                                                         List<T> list)
        Get a reverse Iterator for the provided List.
        Type Parameters:
        T - the type to iterate on
        Parameters:
        list - the list of items to iterate over
        Returns:
        the resulting Iterator instance
      • singleton

        @NonNull
        public static <T> Set<T> singleton​(@NonNull
                                           T value)
      • emptySet

        @NonNull
        public static <T> Set<T> emptySet()
      • singletonList

        @NonNull
        public static <T> List<T> singletonList​(@NonNull
                                                T instance)
      • emptyMap

        @NonNull
        public static <K,​V> Map<K,​V> emptyMap()
      • singletonMap

        @NonNull
        public static <K,​V> Map<K,​V> singletonMap​(@NonNull
                                                              K key,
                                                              @NonNull
                                                              V value)
      • unmodifiableMap

        @NonNull
        public static <K,​V> Map<K,​V> unmodifiableMap​(@NonNull
                                                                 Map<K,​V> map)