类 Iterables
- java.lang.Object
-
- net.dongliu.commons.collection.Iterables
-
public class Iterables extends java.lang.ObjectUtils methods for Iterable
-
-
构造器概要
构造器 构造器 说明 Iterables()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static <T> java.util.Optional<T>find(java.lang.Iterable<T> iterable, java.util.function.Predicate<? super T> predicate)Fetch the first element accepted by predicate in Iterable.static <T> @Nullable TfindOrNull(java.lang.Iterable<T> list, java.util.function.Predicate<? super T> predicate)Fetch the first element accepted by predicate in Iterable.static <T> java.util.Optional<T>first(java.lang.Iterable<T> iterable)Fetch the first element of iterable.static <T> @Nullable TfirstOrNull(java.lang.Iterable<T> iterable)Fetch the first element of iterable.static <T> voidforEachIndexed(java.lang.Iterable<T> iterable, IndexedConsumer<? super T> consumer)Traverse on a collection.static <T> voidforEachLastAware(java.lang.Iterable<T> iterable, LastAwareConsumer<? super T> consumer)Traverse on a collection.static <T> TgetOneExactly(java.lang.Iterable<T> iterable)Return the element in iterable, if iterable has one and only one element.static <T> java.util.stream.Stream<T>stream(java.lang.Iterable<T> iterable)Creates a new sequential stream fro iterable.
-
-
-
方法详细资料
-
getOneExactly
public static <T> T getOneExactly(java.lang.Iterable<T> iterable) throws java.util.NoSuchElementException, TooManyElementsExceptionReturn the element in iterable, if iterable has one and only one element. Throw an exception otherwise.- 抛出:
java.util.NoSuchElementException- if iterable has no elementTooManyElementsException- if iterable has more than one element
-
first
public static <T> java.util.Optional<T> first(java.lang.Iterable<T> iterable)
Fetch the first element of iterable. The element should not be null, or NullPointerException will be thrown.- 参数:
iterable- can not be null- 返回:
- Optional contain the value, or empty Optional if not exists
-
firstOrNull
public static <T> @Nullable T firstOrNull(java.lang.Iterable<T> iterable)
Fetch the first element of iterable. The element should not be null, or NullPointerException will be thrown.- 参数:
iterable- can not be null- 返回:
- the first value, or null if not exists
-
find
public static <T> java.util.Optional<T> find(java.lang.Iterable<T> iterable, java.util.function.Predicate<? super T> predicate)Fetch the first element accepted by predicate in Iterable. The element should not be null, or NullPointerException will be thrown.- 参数:
iterable- can not be null- 返回:
- Optional
-
findOrNull
public static <T> @Nullable T findOrNull(java.lang.Iterable<T> list, java.util.function.Predicate<? super T> predicate)Fetch the first element accepted by predicate in Iterable.- 参数:
list- can not be null- 返回:
- The first accepted element. If list is empty, return null.
-
stream
public static <T> java.util.stream.Stream<T> stream(java.lang.Iterable<T> iterable)
Creates a new sequential stream fro iterable.- 返回:
- new stream
-
forEachLastAware
public static <T> void forEachLastAware(java.lang.Iterable<T> iterable, LastAwareConsumer<? super T> consumer)Traverse on a collection.- 类型参数:
T- the data type- 参数:
iterable- the collectionconsumer- the consumer
-
forEachIndexed
public static <T> void forEachIndexed(java.lang.Iterable<T> iterable, IndexedConsumer<? super T> consumer)Traverse on a collection.- 类型参数:
T- the data type- 参数:
iterable- the collectionconsumer- the consumer
-
-