Class IteratorUtils


  • public class IteratorUtils
    extends Object
    Utils for iterator class
    Author:
    markr
    • Constructor Detail

      • IteratorUtils

        public IteratorUtils()
    • Method Detail

      • toIterable

        public static <T> Iterable<T> toIterable​(Iterator<T> iterator)
        Get iterable from iterator
        Type Parameters:
        T - type of iterator values
        Parameters:
        iterator - to convert to iterable
        Returns:
        iterable
      • toMap

        public static <T,​K> Map<K,​T> toMap​(Iterator<T> iterator,
                                                       Function<T,​K> getKey,
                                                       Map<K,​T> mapToFill)
        Map iterator to a map with a custom key obtained from the entries
        Type Parameters:
        T - type of iterable
        K - type of key
        Parameters:
        iterator - to use
        getKey - function to extract key from entries
        mapToFill - to fill
        Returns:
        populated map
      • toList

        public static <T> List<T> toList​(Iterator<T> iterator)
        Map iterator to a list with a custom key obtained from the entries
        Type Parameters:
        T - type of iterator
        Parameters:
        iterator - to use
        Returns:
        populated list
      • asStream

        public static <T> Stream<T> asStream​(Iterator<T> iterator)
        Iterator as stream
        Type Parameters:
        T - type of entries
        Parameters:
        iterator - to get stream for
        Returns:
        stream