Class Iterators
- java.lang.Object
-
- com.saperion.common.lang.iterator.Iterators
-
public final class Iterators extends java.lang.Object
Utility class for iterator treatment.- Author:
- agz
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
extractSingleElement(java.util.Iterator<? extends T> iteratorInput, Criterion<? super T> criterion)
Returns the one-and-only element of the specified specified inputIterator
that satisfies the specifiedCriterion
.static <T> void
filter(java.util.Iterator<T> iteratorInput, Criterion<? super T> criterion, java.util.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> java.util.ArrayList<T>
newArrayList(java.util.Iterator<? extends T> iteratorInput, Criterion<? super T> criterion, int sizeGuess)
Creates a newArrayList
with those elements of the specified inputIterator
that satisfy the specifiedCriterion
.static boolean
startsWith(java.util.Iterator<?> iterator1, java.util.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 Detail
-
filter
public static <T> void filter(java.util.Iterator<T> iteratorInput, Criterion<? super T> criterion, java.util.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> java.util.ArrayList<T> newArrayList(java.util.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(java.util.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
public static boolean startsWith(java.util.Iterator<?> iterator1, java.util.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. 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.- Parameters:
iterator1
-Iterator
to test the first objects foriterator2
-Iterator
that contains the sequence of starting objects to test the firstIterator
for- Returns:
- whether the first specified
Iterator
starts with the same elements as the second specifiedIterator
-
-