类 Iterables


  • public class Iterables
    extends java.lang.Object
    Utils 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 T findOrNull​(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 T firstOrNull​(java.lang.Iterable<T> iterable)
      Fetch the first element of iterable.
      static <T> void forEachIndexed​(java.lang.Iterable<T> iterable, IndexedConsumer<? super T> consumer)
      Traverse on a collection.
      static <T> void forEachLastAware​(java.lang.Iterable<T> iterable, LastAwareConsumer<? super T> consumer)
      Traverse on a collection.
      static <T> T getOneExactly​(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.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 构造器详细资料

      • Iterables

        public Iterables()
    • 方法详细资料

      • getOneExactly

        public static <T> T getOneExactly​(java.lang.Iterable<T> iterable)
                                   throws java.util.NoSuchElementException,
                                          TooManyElementsException
        Return the element in iterable, if iterable has one and only one element. Throw an exception otherwise.
        抛出:
        java.util.NoSuchElementException - if iterable has no element
        TooManyElementsException - 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 collection
        consumer - 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 collection
        consumer - the consumer