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 SummaryAll 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- 
filterpublic 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 input- Iterator
- Parameters:
- iteratorInput- input- Iteratorwhose elements are to filter with the specified- Criterionand to add to the output- Collection
- criterion-- Criterionto filter the elements of the input- Iteratorwith
- colOutput- output- Collectionto accept the filtered input
 
 - 
newArrayListpublic 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 new- ArrayList
- Parameters:
- iteratorInput- input- Iteratorwhose elements are to filter with the specified- Criterionand to add to the new- ArrayList
- criterion-- Criterionto filter the input- Iteratorwith
- sizeGuess- size guess of the new list/count of filtered elements
- Returns:
- new ArrayListwith those elements of the specified inputIteratorthat satisfy the specifiedCriterion
 
 - 
extractSingleElementpublic 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- input- Iteratorwhose elements are to filter with the specified- Criterion
- criterion-- Criterionto filter the input- Iteratorwith
- Returns:
- the one-and-only element of the specified input Iteratorthat satisfies the specifiedCriterion
 
 - 
startsWithpublic 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 for
- iterator2-- Iteratorthat contains the sequence of starting objects to test the first- Iteratorfor
- Returns:
- whether the first specified Iteratorstarts with the same elements as the second specifiedIterator
 
 
- 
 
-