Class Iterators
java.lang.Object
fr.lirmm.graphik.util.stream.Iterators
Helper methods for creating and collecting closeable iterators.
- Author:
- Clément Sipieter (INRIA) <clement@6pi.fr>
-
Method Summary
Modifier and TypeMethodDescriptionstatic intcount(CloseableIterator<?> it) Counts the number of remaining elements in an iterator.static intCounts the number of remaining elements in an iterator without checked exceptions.static <T> CloseableIteratorWithoutException<T> Construct and return an empty iterator.static <E> CloseableIteratorWithoutException<E> singletonIterator(E e) Creates an iterator yielding a single element.static <T extends Comparable<T>>
CloseableIterator<T> sort(CloseableIterator<T> it) Return an iterator over sorted elements from the specified iterator.static <T extends Comparable<T>>
Iterator<T> Return an iterator over sorted elements from the specified iterator.static <T> List<T> toList(CloseableIterator<T> it) Collects all remaining elements from an iterator into a list.static <T> List<T> Collects all remaining elements from an iterator into a list.static <T> Set<T> toSet(CloseableIterator<T> it) Collects all remaining elements from an iterator into a set.static <T> Set<T> Collects all remaining elements from an iterator into a set.static <T extends Comparable<T>>
CloseableIterator<T> uniq(CloseableIterator<T> it) Remove all equals elements.static <T extends Comparable<T>>
Iterator<T> Remove all equals elements.static <T> CloseableIterator<T> uniqLocaly(CloseableIterator<T> it) Remove adjacent equals elements.
-
Method Details
-
emptyIterator
Construct and return an empty iterator. The hasNext method will always return false and the next method will always return null.- Type Parameters:
T- the element type- Returns:
- An instance of a
CloseableIteratorWithoutException
-
singletonIterator
Creates an iterator yielding a single element.- Type Parameters:
E- the element type- Parameters:
e- the single element to iterate over- Returns:
- an iterator containing only
e
-
count
Counts the number of remaining elements in an iterator.- Parameters:
it- the iterator to consume- Returns:
- the number of remaining elements
- Throws:
IteratorException- if the iterator cannot be consumed
-
count
Counts the number of remaining elements in an iterator without checked exceptions.- Parameters:
it- the iterator to consume- Returns:
- the number of remaining elements
-
uniqLocaly
Remove adjacent equals elements.- Type Parameters:
T- the element type- Parameters:
it- the iterator to filter- Returns:
- a CloseableIterator.
-
sort
public static <T extends Comparable<T>> CloseableIterator<T> sort(CloseableIterator<T> it) throws IteratorException Return an iterator over sorted elements from the specified iterator.- Type Parameters:
T- the element type- Parameters:
it- the iterator to sort- Returns:
- a sorted CloseableIterator over elements from the specified Iterator.
- Throws:
IteratorException- if the iterator cannot be consumed
-
sort
Return an iterator over sorted elements from the specified iterator.- Type Parameters:
T- the element type- Parameters:
it- the iterator to sort- Returns:
- a sorted Iterator over elements from the specified Iterator.
-
uniq
public static <T extends Comparable<T>> CloseableIterator<T> uniq(CloseableIterator<T> it) throws IteratorException Remove all equals elements.- Type Parameters:
T- the element type- Parameters:
it- the iterator to deduplicate- Returns:
- a CloseableIterator over elements from the specified it without duplicate.
- Throws:
IteratorException- if the iterator cannot be consumed
-
uniq
Remove all equals elements.- Type Parameters:
T- the element type- Parameters:
it- the iterator to deduplicate- Returns:
- an Iterator over elements from the specified it without duplicate.
-
toList
Collects all remaining elements from an iterator into a list.- Type Parameters:
T- the element type- Parameters:
it- the iterator to consume- Returns:
- a List containing all elements accessible by the specified iterator.
- Throws:
IteratorException- if the iterator cannot be consumed
-
toList
Collects all remaining elements from an iterator into a list.- Type Parameters:
T- the element type- Parameters:
it- the iterator to consume- Returns:
- a List containing all elements accessible by the specified iterator.
-
toSet
Collects all remaining elements from an iterator into a set.- Type Parameters:
T- the element type- Parameters:
it- the iterator to consume- Returns:
- a Set containing all elements accessible by the specified iterator.
- Throws:
IteratorException- if the iterator cannot be consumed
-
toSet
Collects all remaining elements from an iterator into a set.- Type Parameters:
T- the element type- Parameters:
it- the iterator to consume- Returns:
- a Set containing all elements accessible by the specified iterator.
-