Package de.xima.fc.utils
Class IterableUtils
java.lang.Object
de.xima.fc.utils.IterableUtils
Additional utilities for
Iterables not found in other libraries.- Author:
- XIMA MEDIA GmbH
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceRepresents an item with an index. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TfirstOrNull(Iterable<T> iterable) Similar to thefirstmethod from Apache Commons, but returnsnullinstead of throwing if the iterable is empty.static <T> Iterable<IterableUtils.Indexed<T>>Wraps an iterable and adds the index to each element.
-
Constructor Details
-
IterableUtils
public IterableUtils()
-
-
Method Details
-
withIndex
Wraps an iterable and adds the index to each element.- Type Parameters:
T- Type of the elements in the iterable.- Parameters:
iterable- Iterable to wrap.- Returns:
- An iterable that iterates over the same elements, but with a 0-based index added to each element.
-
firstOrNull
Similar to thefirstmethod from Apache Commons, but returnsnullinstead of throwing if the iterable is empty.- Type Parameters:
T- Type of the items in the iterable.- Parameters:
iterable- Iterable to process.- Returns:
- The first item in the iterable, or
nullif either the iterable isnullor it contains no items.
-