Package com.forgerock.opendj.util
Class Iterables
- java.lang.Object
-
- com.forgerock.opendj.util.Iterables
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <M> Iterable<M>arrayIterable(M[] a)Returns an iterable containing the elements ofa.static <M> Iterable<M>emptyIterable()Returns an immutable empty iterable.static <M> Iterable<M>filteredIterable(Iterable<M> iterable, Predicate<? super M,Void> predicate)Returns a filtered view ofiterablecontaining only those elements which matchpredicate.static <M,P>
Iterable<M>filteredIterable(Iterable<M> iterable, Predicate<? super M,P> predicate, P p)Returns a filtered view ofiterablecontaining only those elements which matchpredicate.static booleanisEmpty(Iterable<?> iterable)Returnstrueif the provided iterable does not contain any elements.static <M> Iterable<M>singletonIterable(M value)Returns an iterable containing the single elementvalue.static intsize(Iterable<?> iterable)Returns the number of elements contained in the provided iterable.static StringtoString(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.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 ofiterablewhose values have been mapped to elements of typeNusingfunction.static <M> Iterable<M>unmodifiableIterable(Iterable<M> iterable)Returns a read-only view ofiterablewhose iterator does not support element removal via theremove().
-
-
-
Method Detail
-
arrayIterable
public static <M> Iterable<M> arrayIterable(M[] a)
Returns an iterable containing the elements ofa. The returned iterable's iterator does not support element removal via theremove()method.- Type Parameters:
M- The type of elements contained ina.- 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 ofiterablecontaining only those elements which matchpredicate. The returned iterable's iterator supports element removal via theremove()method subject to any constraints imposed byiterable.- Type Parameters:
M- The type of elements contained initerable.P- The type of the additional parameter to the predicate'smatchesmethod. UseVoidfor 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
iterablecontaining only those elements which matchpredicate.
-
filteredIterable
public static <M> Iterable<M> filteredIterable(Iterable<M> iterable, Predicate<? super M,Void> predicate)
Returns a filtered view ofiterablecontaining only those elements which matchpredicate. The returned iterable's iterator supports element removal via theremove()method subject to any constraints imposed byiterable.- Type Parameters:
M- The type of elements contained initerable.- Parameters:
iterable- The iterable to be filtered.predicate- The predicate.- Returns:
- A filtered view of
iterablecontaining only those elements which matchpredicate.
-
isEmpty
public static boolean isEmpty(Iterable<?> iterable)
Returnstrueif the provided iterable does not contain any elements.- Parameters:
iterable- The iterable.- Returns:
trueif the provided iterable does not contain any elements.
-
singletonIterable
public static <M> Iterable<M> singletonIterable(M value)
Returns an iterable containing the single elementvalue. The returned iterable's iterator does not support element removal via theremove()method.- Type Parameters:
M- The type of the single elementvalue.- 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 ofiterablewhose values have been mapped to elements of typeNusingfunction. The returned iterable's iterator supports element removal via theremove()method subject to any constraints imposed byiterable.- Type Parameters:
M- The type of elements contained initerable.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
iterablewhose values have been mapped to elements of typeNusingfunction.
-
unmodifiableIterable
public static <M> Iterable<M> unmodifiableIterable(Iterable<M> iterable)
Returns a read-only view ofiterablewhose iterator does not support element removal via theremove(). Attempts to use theremove()method will result in aUnsupportedOperationException.- Type Parameters:
M- The type of elements contained initerable.- Parameters:
iterable- The iterable to be made read-only.- Returns:
- A read-only view of
iterablewhose iterator does not support element removal via theremove().
-
-