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> voidforEach(java.lang.Iterable<E> elements, java.util.function.Consumer<E> elementConsumer)Iterates over the givenIterableand applies the providedConsumerto each element.static booleanisIterable(java.lang.Class<?> clazz)Checks if the given class is assignable fromIterable.static booleanisIterable(java.lang.Object object)Checks if the given object is an instance ofIterable.static <E> voiditerate(java.lang.Iterable<E> elements, java.util.function.Consumer<E> elementConsumer)Iterates over the givenIterableand applies the providedConsumerto 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:
trueif the object is an instance ofIterable,falseotherwise
-
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:
trueif the class is assignable fromIterable,falseotherwise- 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 givenIterableand applies the providedConsumerto 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- theIterableto iterate overelementConsumer- theConsumerto 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 givenIterableand applies the providedConsumerto 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- theIterableto iterate overelementConsumer- theConsumerto apply to each element- See Also:
iterate(Iterable, Consumer)
-
-