Package com.forgerock.opendj.util
Class Iterators
- java.lang.Object
-
- com.forgerock.opendj.util.Iterators
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <M> Iterator<M>arrayIterator(M[] a)Returns an iterator over the elements contained ina.static <M> Iterator<M>emptyIterator()Returns an immutable empty iterator.static <M> Iterator<M>filteredIterator(Iterator<M> iterator, Predicate<? super M,Void> predicate)Returns a filtered view ofiteratorcontaining only those elements which matchpredicate.static <M,P>
Iterator<M>filteredIterator(Iterator<M> iterator, Predicate<? super M,P> predicate, P p)Returns a filtered view ofiteratorcontaining only those elements which matchpredicate.static <M> Iterator<M>singletonIterator(M value)Returns an iterator containing the single elementvalue.static <M,N,E extends RuntimeException>
Iterator<N>transformedIterator(Iterator<M> iterator, org.forgerock.util.Function<? super M,? extends N,E> function)Returns a view ofiteratorwhose values have been mapped to elements of typeNusingfunction.static <M> Iterator<M>unmodifiableIterator(Iterator<M> iterator)Returns a read-only view ofiteratorwhich does not support element removal via theremove().
-
-
-
Method Detail
-
arrayIterator
public static <M> Iterator<M> arrayIterator(M[] a)
Returns an iterator over the elements contained ina. The returned iterator does not support element removal via theremove()method.- Type Parameters:
M- The type of elements contained ina.- Parameters:
a- The array of elements to be returned by the iterator.- Returns:
- An iterator over the elements contained in
a.
-
emptyIterator
public static <M> Iterator<M> emptyIterator()
Returns an immutable empty iterator.- Type Parameters:
M- The required type of the empty iterator.- Returns:
- An immutable empty iterator.
-
filteredIterator
public static <M,P> Iterator<M> filteredIterator(Iterator<M> iterator, Predicate<? super M,P> predicate, P p)
Returns a filtered view ofiteratorcontaining only those elements which matchpredicate. The returned iterator supports element removal via theremove()method subject to any constraints imposed byiterator.- Type Parameters:
M- The type of elements contained initerator.P- The type of the additional parameter to the predicate'smatchesmethod. UseVoidfor predicates that do not need an additional parameter.- Parameters:
iterator- The iterator to be filtered.predicate- The predicate.p- A predicate specified parameter.- Returns:
- A filtered view of
iteratorcontaining only those elements which matchpredicate.
-
filteredIterator
public static <M> Iterator<M> filteredIterator(Iterator<M> iterator, Predicate<? super M,Void> predicate)
Returns a filtered view ofiteratorcontaining only those elements which matchpredicate. The returned iterator supports element removal via theremove()method subject to any constraints imposed byiterator.- Type Parameters:
M- The type of elements contained initerator.- Parameters:
iterator- The iterator to be filtered.predicate- The predicate.- Returns:
- A filtered view of
iteratorcontaining only those elements which matchpredicate.
-
singletonIterator
public static <M> Iterator<M> singletonIterator(M value)
Returns an iterator containing the single elementvalue. The returned iterator does not support element removal via theremove()method.- Type Parameters:
M- The type of the single elementvalue.- Parameters:
value- The single element to be returned by the iterator.- Returns:
- An iterator containing the single element
value.
-
transformedIterator
public static <M,N,E extends RuntimeException> Iterator<N> transformedIterator(Iterator<M> iterator, org.forgerock.util.Function<? super M,? extends N,E> function)
Returns a view ofiteratorwhose values have been mapped to elements of typeNusingfunction. The returned iterator supports element removal via theremove()method subject to any constraints imposed byiterator.- Type Parameters:
M- The type of elements contained initerator.N- The type of elements contained in the returned iterator.E- The type of the exception thrown by the function.- Parameters:
iterator- The iterator to be transformed.function- The function.- Returns:
- A view of
iteratorwhose values have been mapped to elements of typeNusingfunction.
-
unmodifiableIterator
public static <M> Iterator<M> unmodifiableIterator(Iterator<M> iterator)
Returns a read-only view ofiteratorwhich does not support element removal via theremove(). Attempts to use theremove()method will result in aUnsupportedOperationException.- Type Parameters:
M- The type of elements contained initerator.- Parameters:
iterator- The iterator to be made read-only.- Returns:
- A read-only view of
iteratorwhich does not support element removal via theremove().
-
-