Class Iterators


  • public final class Iterators
    extends Object
    Utility methods for manipulating Iterators.
    • Method Detail

      • arrayIterator

        public static <M> Iterator<M> arrayIterator​(M[] a)
        Returns an iterator over the elements contained in a. The returned iterator does not support element removal via the remove() method.
        Type Parameters:
        M - The type of elements contained in a.
        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 of iterator containing only those elements which match predicate. The returned iterator supports element removal via the remove() method subject to any constraints imposed by iterator.
        Type Parameters:
        M - The type of elements contained in iterator.
        P - The type of the additional parameter to the predicate's matches method. Use Void for 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 iterator containing only those elements which match predicate.
      • filteredIterator

        public static <M> Iterator<M> filteredIterator​(Iterator<M> iterator,
                                                       Predicate<? super M,​Void> predicate)
        Returns a filtered view of iterator containing only those elements which match predicate. The returned iterator supports element removal via the remove() method subject to any constraints imposed by iterator.
        Type Parameters:
        M - The type of elements contained in iterator.
        Parameters:
        iterator - The iterator to be filtered.
        predicate - The predicate.
        Returns:
        A filtered view of iterator containing only those elements which match predicate.
      • singletonIterator

        public static <M> Iterator<M> singletonIterator​(M value)
        Returns an iterator containing the single element value. The returned iterator does not support element removal via the remove() method.
        Type Parameters:
        M - The type of the single element value.
        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 of iterator whose values have been mapped to elements of type N using function. The returned iterator supports element removal via the remove() method subject to any constraints imposed by iterator.
        Type Parameters:
        M - The type of elements contained in iterator.
        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 iterator whose values have been mapped to elements of type N using function.
      • unmodifiableIterator

        public static <M> Iterator<M> unmodifiableIterator​(Iterator<M> iterator)
        Returns a read-only view of iterator which does not support element removal via the remove(). Attempts to use the remove() method will result in a UnsupportedOperationException.
        Type Parameters:
        M - The type of elements contained in iterator.
        Parameters:
        iterator - The iterator to be made read-only.
        Returns:
        A read-only view of iterator which does not support element removal via the remove().