Class Iterators
java.lang.Object
com.saperion.common.lang.iterator.Iterators
Utility class for iterator treatment.
- Author:
- agz
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TextractSingleElement(Iterator<? extends T> iteratorInput, Criterion<? super T> criterion) static <T> voidfilter(Iterator<T> iteratorInput, Criterion<? super T> criterion, Collection<? super T> colOutput) Iterates through the element of the specified inputIteratorand adds those elements that satisfy the specifiedCriterionto the specified outputCollection.static <T> ArrayList<T>newArrayList(Iterator<? extends T> iteratorInput, Criterion<? super T> criterion, int sizeGuess) static booleanstartsWith(Iterator<?> iterator1, Iterator<?> iterator2) Returns whether the first specifiedIteratorstarts 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 inputIteratorand adds those elements that satisfy the specifiedCriterionto the specified outputCollection. The specified inputIteratormust not benull. The specifiedCriterionmay benull, in which case all elements of the inputIteratorare copied to the outputCollection. The specified outputCollectionmust not benull. After this call the specified inputIteratorwill be expired.- Type Parameters:
T- Type of elements of the inputIterator- Parameters:
iteratorInput- inputIteratorwhose elements are to filter with the specifiedCriterionand to add to the outputCollectioncriterion-Criterionto filter the elements of the inputIteratorwithcolOutput- outputCollectionto accept the filtered input
-
newArrayList
public static <T> ArrayList<T> newArrayList(Iterator<? extends T> iteratorInput, Criterion<? super T> criterion, int sizeGuess) Creates a newArrayListwith those elements of the specified inputIteratorthat satisfy the specifiedCriterion. The specified inputIteratormust not benull. The specifiedCriterionmay benull, in which case all elements of the inputIteratorare copied to the newArrayList. After this call the specified inputIteratorwill be expired.- Type Parameters:
T- Type of the elements of the newArrayList- Parameters:
iteratorInput- inputIteratorwhose elements are to filter with the specifiedCriterionand to add to the newArrayListcriterion-Criterionto filter the inputIteratorwithsizeGuess- size guess of the new list/count of filtered elements- Returns:
- new
ArrayListwith those elements of the specified inputIteratorthat 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 inputIteratorthat satisfies the specifiedCriterion. Returnsnullif no such element exists. Throws a runtime exception if more than one element satisfy the specifiedCriterion. The specified inputIteratormust not benull. The specifiedCriterionmay benull, in which case theIteratormust not iterate through more than one element. After this call the specified inputIteratorwill be expired.- Type Parameters:
T- Type of the element to return- Parameters:
iteratorInput- inputIteratorwhose elements are to filter with the specifiedCriterioncriterion-Criterionto filter the inputIteratorwith- Returns:
- the one-and-only element of the specified input
Iteratorthat satisfies the specifiedCriterion
-
startsWith
Returns whether the first specifiedIteratorstarts 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 firstIteratorpoints to the first element that is not contained in the secondIteratorand the secondIteratorhas no more elements to iterate. If this method returnsfalse, the positions of bothIterators are undefined.
-