Package org.goplanit.utils.misc
Class IteratorUtils
- java.lang.Object
-
- org.goplanit.utils.misc.IteratorUtils
-
public class IteratorUtils extends Object
Utils for iterator class- Author:
- markr
-
-
Constructor Summary
Constructors Constructor Description IteratorUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Stream<T>
asStream(Iterator<T> iterator)
Iterator as streamstatic <T> Iterable<T>
toIterable(Iterator<T> iterator)
Get iterable from iteratorstatic <T> List<T>
toList(Iterator<T> iterator)
Map iterator to a list with a custom key obtained from the entriesstatic <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
-
-
-
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 iterableK
- type of key- Parameters:
iterator
- to usegetKey
- function to extract key from entriesmapToFill
- 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
-
-