Package io.microsphere.util
Class IterableUtils
- java.lang.Object
-
- io.microsphere.util.IterableUtils
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <E> void
forEach(java.lang.Iterable<E> elements, java.util.function.Consumer<E> elementConsumer)
Iterates over the givenIterable
and applies the providedConsumer
to each element.static boolean
isIterable(java.lang.Class<?> clazz)
Checks if the given class is assignable fromIterable
.static boolean
isIterable(java.lang.Object object)
Checks if the given object is an instance ofIterable
.static <E> void
iterate(java.lang.Iterable<E> elements, java.util.function.Consumer<E> elementConsumer)
Iterates over the givenIterable
and applies the providedConsumer
to each element.
-
-
-
Method Detail
-
isIterable
public static boolean isIterable(@Nullable java.lang.Object object)
Checks if the given object is an instance ofIterable
.Example Usage
List<String> list = Arrays.asList("a", "b", "c"); boolean result1 = IterableUtils.isIterable(list); // true boolean result2 = IterableUtils.isIterable("string"); // false boolean result3 = IterableUtils.isIterable(null); // false
- Parameters:
object
- the object to check- Returns:
true
if the object is an instance ofIterable
,false
otherwise
-
isIterable
public static boolean isIterable(@Nullable java.lang.Class<?> clazz)
Checks if the given class is assignable fromIterable
.Example Usage
boolean result1 = IterableUtils.isIterable(List.class); // true boolean result2 = IterableUtils.isIterable(String.class); // false boolean result3 = IterableUtils.isIterable(null); // false
- Parameters:
clazz
- the class to check- Returns:
true
if the class is assignable fromIterable
,false
otherwise- See Also:
ClassUtils.isAssignableFrom(Class, Class)
-
iterate
public static <E> void iterate(@Nullable java.lang.Iterable<E> elements, @Nonnull java.util.function.Consumer<E> elementConsumer)
Iterates over the givenIterable
and applies the providedConsumer
to each element.Example Usage
List<String> list = Arrays.asList("a", "b", "c"); IterableUtils.iterate(list, System.out::println); // Output: // a // b // c
- Type Parameters:
E
- the type of elements in theIterable
- Parameters:
elements
- theIterable
to iterate overelementConsumer
- theConsumer
to apply to each element
-
forEach
public static <E> void forEach(@Nullable java.lang.Iterable<E> elements, @Nonnull java.util.function.Consumer<E> elementConsumer)
Iterates over the givenIterable
and applies the providedConsumer
to each element.This method is equivalent to
iterate(Iterable, Consumer)
.Example Usage
List<String> list = Arrays.asList("a", "b", "c"); IterableUtils.forEach(list, System.out::println); // Output: // a // b // c
- Type Parameters:
E
- the type of elements in theIterable
- Parameters:
elements
- theIterable
to iterate overelementConsumer
- theConsumer
to apply to each element- See Also:
iterate(Iterable, Consumer)
-
-