Class Iterables


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

      • arrayIterable

        public static <M> Iterable<M> arrayIterable​(M[] a)
        Returns an iterable containing the elements of a. The returned iterable's 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.
        Returns:
        An iterable containing the elements of a.
      • emptyIterable

        public static <M> Iterable<M> emptyIterable()
        Returns an immutable empty iterable.
        Type Parameters:
        M - The required type of the empty iterable.
        Returns:
        An immutable empty iterable.
      • filteredIterable

        public static <M,​P> Iterable<M> filteredIterable​(Iterable<M> iterable,
                                                               Predicate<? super M,​P> predicate,
                                                               P p)
        Returns a filtered view of iterable containing only those elements which match predicate. The returned iterable's iterator supports element removal via the remove() method subject to any constraints imposed by iterable.
        Type Parameters:
        M - The type of elements contained in iterable.
        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:
        iterable - The iterable to be filtered.
        predicate - The predicate.
        p - A predicate specified parameter.
        Returns:
        A filtered view of iterable containing only those elements which match predicate.
      • filteredIterable

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

        public static boolean isEmpty​(Iterable<?> iterable)
        Returns true if the provided iterable does not contain any elements.
        Parameters:
        iterable - The iterable.
        Returns:
        true if the provided iterable does not contain any elements.
      • singletonIterable

        public static <M> Iterable<M> singletonIterable​(M value)
        Returns an iterable containing the single element value. The returned iterable's 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.
        Returns:
        An iterable containing the single element value.
      • size

        public static int size​(Iterable<?> iterable)
        Returns the number of elements contained in the provided iterable.
        Parameters:
        iterable - The iterable.
        Returns:
        The number of elements contained in the provided iterable.
      • toString

        public static String toString​(Iterable<?> iterable)
        Returns a string representation of the provided iterable composed of an opening square bracket, followed by each element separated by commas, and then a closing square bracket.
        Parameters:
        iterable - The iterable whose string representation is to be returned.
        Returns:
        A string representation of the provided iterable.
        See Also:
        AbstractCollection.toString()
      • transformedIterable

        public static <M,​N,​E extends RuntimeException> Iterable<N> transformedIterable​(Iterable<M> iterable,
                                                                                                   org.forgerock.util.Function<? super M,​? extends N,​E> function)
        Returns a view of iterable whose values have been mapped to elements of type N using function. The returned iterable's iterator supports element removal via the remove() method subject to any constraints imposed by iterable.
        Type Parameters:
        M - The type of elements contained in iterable.
        N - The type of elements contained in the returned iterable.
        E - The type of the exception thrown by the function.
        Parameters:
        iterable - The iterable to be transformed.
        function - The function.
        Returns:
        A view of iterable whose values have been mapped to elements of type N using function.
      • unmodifiableIterable

        public static <M> Iterable<M> unmodifiableIterable​(Iterable<M> iterable)
        Returns a read-only view of iterable whose iterator 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 iterable.
        Parameters:
        iterable - The iterable to be made read-only.
        Returns:
        A read-only view of iterable whose iterator does not support element removal via the remove().