Class Iterators
java.lang.Object
com.saperion.common.lang.iterator.Iterators
Utility class for iterator treatment.
- Author:
- agz
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
extractSingleElement
(Iterator<? extends T> iteratorInput, Criterion<? super T> criterion) static <T> void
filter
(Iterator<T> iteratorInput, Criterion<? super T> criterion, Collection<? super T> colOutput) Iterates through the element of the specified inputIterator
and adds those elements that satisfy the specifiedCriterion
to the specified outputCollection
.static <T> ArrayList<T>
newArrayList
(Iterator<? extends T> iteratorInput, Criterion<? super T> criterion, int sizeGuess) static boolean
startsWith
(Iterator<?> iterator1, Iterator<?> iterator2) Returns whether the first specifiedIterator
starts with the same elements as the second specifiedIterator
(byObject.equals(Object)
-comparison) and contains at least the same number of elements.
-
Method Details
-
filter
public static <T> void filter(Iterator<T> iteratorInput, Criterion<? super T> criterion, Collection<? super T> colOutput) Iterates through the element of the specified inputIterator
and adds those elements that satisfy the specifiedCriterion
to the specified outputCollection
. The specified inputIterator
must not benull
. The specifiedCriterion
may benull
, in which case all elements of the inputIterator
are copied to the outputCollection
. The specified outputCollection
must not benull
. After this call the specified inputIterator
will be expired.- Type Parameters:
T
- Type of elements of the inputIterator
- Parameters:
iteratorInput
- inputIterator
whose elements are to filter with the specifiedCriterion
and to add to the outputCollection
criterion
-Criterion
to filter the elements of the inputIterator
withcolOutput
- outputCollection
to accept the filtered input
-
newArrayList
public static <T> ArrayList<T> newArrayList(Iterator<? extends T> iteratorInput, Criterion<? super T> criterion, int sizeGuess) Creates a newArrayList
with those elements of the specified inputIterator
that satisfy the specifiedCriterion
. The specified inputIterator
must not benull
. The specifiedCriterion
may benull
, in which case all elements of the inputIterator
are copied to the newArrayList
. After this call the specified inputIterator
will be expired.- Type Parameters:
T
- Type of the elements of the newArrayList
- Parameters:
iteratorInput
- inputIterator
whose elements are to filter with the specifiedCriterion
and to add to the newArrayList
criterion
-Criterion
to filter the inputIterator
withsizeGuess
- size guess of the new list/count of filtered elements- Returns:
- new
ArrayList
with those elements of the specified inputIterator
that satisfy the specifiedCriterion
-
extractSingleElement
public static <T> T extractSingleElement(Iterator<? extends T> iteratorInput, Criterion<? super T> criterion) Returns the one-and-only element of the specified specified inputIterator
that satisfies the specifiedCriterion
. Returnsnull
if no such element exists. Throws a runtime exception if more than one element satisfy the specifiedCriterion
. The specified inputIterator
must not benull
. The specifiedCriterion
may benull
, in which case theIterator
must not iterate through more than one element. After this call the specified inputIterator
will be expired.- Type Parameters:
T
- Type of the element to return- Parameters:
iteratorInput
- inputIterator
whose elements are to filter with the specifiedCriterion
criterion
-Criterion
to filter the inputIterator
with- Returns:
- the one-and-only element of the specified input
Iterator
that satisfies the specifiedCriterion
-
startsWith
Returns whether the first specifiedIterator
starts with the same elements as the second specifiedIterator
(byObject.equals(Object)
-comparison) and contains at least the same number of elements. If this method returnstrue
, the firstIterator
points to the first element that is not contained in the secondIterator
and the secondIterator
has no more elements to iterate. If this method returnsfalse
, the positions of bothIterator
s are undefined.
-