Class IteratorToolkit
java.lang.Object
org.openjdk.jmc.common.collection.IteratorToolkit
Various methods that work with iterators.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Iterator<T>
Wrap an iterator in a new iterator that filters out values based on a predicate.static <T> Iterator<T>
of
(T[] elements) Iterator that iterates over an array.static <T> Iterator<T>
Wrap an iterator in a new iterator that skips all null values.static <T> List<T>
Place all elements of an iterator in a list.
-
Constructor Details
-
IteratorToolkit
public IteratorToolkit()
-
-
Method Details
-
toList
Place all elements of an iterator in a list.- Type Parameters:
T
- input iterator type- Parameters:
itr
- iteratorsizeHint
- a hint of how many elements there are- Returns:
- a new list with all elements from the iterator
-
skipNulls
Wrap an iterator in a new iterator that skips all null values.- Type Parameters:
T
- input iterator type- Parameters:
itr
- input iterator that may produce null values- Returns:
- a new iterator that will never produce null values
-
filter
Wrap an iterator in a new iterator that filters out values based on a predicate.- Type Parameters:
T
- input iterator type- Parameters:
itr
- input iteratorfilter
- filter predicate- Returns:
- a new iterator that only contains values where the filter evaluates to true
-
of
Iterator that iterates over an array. Hopefully faster than Arrays.asList(...).iterator() since there are no concurrency checks.- Type Parameters:
T
- input iterator type- Parameters:
elements
- elements to iterate over- Returns:
- an iterator
-