Class Iterators
- java.lang.Object
-
- com.saperion.common.lang.iterator.Iterators
-
public final class Iterators extends java.lang.ObjectUtility class for iterator treatment.- Author:
- agz
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TextractSingleElement(java.util.Iterator<? extends T> iteratorInput, Criterion<? super T> criterion)Returns the one-and-only element of the specified specified inputIteratorthat satisfies the specifiedCriterion.static <T> voidfilter(java.util.Iterator<T> iteratorInput, Criterion<? super T> criterion, java.util.Collection<? super T> colOutput)Iterates through the element of the specified inputIteratorand adds those elements that satisfy the specifiedCriterionto the specified outputCollection.static <T> java.util.ArrayList<T>newArrayList(java.util.Iterator<? extends T> iteratorInput, Criterion<? super T> criterion, int sizeGuess)Creates a newArrayListwith those elements of the specified inputIteratorthat satisfy the specifiedCriterion.static booleanstartsWith(java.util.Iterator<?> iterator1, java.util.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 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 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> java.util.ArrayList<T> newArrayList(java.util.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(java.util.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
public static boolean startsWith(java.util.Iterator<?> iterator1, java.util.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. 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.- Parameters:
iterator1-Iteratorto test the first objects foriterator2-Iteratorthat contains the sequence of starting objects to test the firstIteratorfor- Returns:
- whether the first specified
Iteratorstarts with the same elements as the second specifiedIterator
-
-