Class Iterables


  • public final class Iterables
    extends java.lang.Object
    The base utility class for some operations, which doesn't exist in the jdk 8
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Iterables()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> boolean contains​(T t, T[] array)  
      static <T> java.util.List<T> filter​(java.lang.Iterable<T> iterable, java.util.function.Predicate<T> predicate)  
      static <T> void filter​(java.lang.Iterable<T> iterable, java.util.function.Predicate<T> predicate, java.util.Collection<T> out)  
      static <T> T first​(java.lang.Iterable<T> iterable, java.util.function.Predicate<T> predicate)
      Filters the first item in an Iterable, which the predicate returns true
      static <T> T first​(T[] iterable, java.util.function.Predicate<T> predicate)  
      static <T> void forEach​(java.util.Enumeration<T> enumeration, java.util.function.Consumer<T> consumer)
      Iterates all keys in a Enumeration class instance.
      static <T> void forEach​(java.util.Enumeration<T> enumeration, java.util.function.Consumer<T> consumer, java.util.function.Consumer<java.lang.Throwable> throwableConsumer)
      Iterates all keys in a Enumeration class instance.
      static <T> void forEach​(java.util.Iterator<T> iterator, java.util.function.Consumer<T> consumer)
      Iterates all keys in a List class instance.
      static <T> void forEach​(java.util.Iterator<T> iterator, java.util.function.Consumer<T> consumer, java.util.function.Consumer<java.lang.Throwable> throwableConsumer)
      Iterates all keys in a Iterator class instance.
      static <T> void forEach​(java.util.List<T> list, java.util.function.Consumer<T> consumer)
      Iterates all keys in a List class instance.
      static void forEach​(java.util.Properties properties, java.util.function.Consumer<java.lang.String> consumer)
      Iterates all keys in a Properties class instance.
      static <T,​V>
      java.util.List<V>
      map​(java.util.Collection<T> coll, java.util.function.Function<T,​V> function)  
      static <T,​V>
      java.util.List<V>
      map​(T[] array, java.util.function.Function<T,​V> function)  
      static <T> java.util.concurrent.ArrayBlockingQueue<T> newArrayBlockingQueue​(int capacity)  
      static <T> java.util.concurrent.ArrayBlockingQueue<T> newArrayBlockingQueue​(int capacity, boolean fair)  
      static <T> java.util.concurrent.ArrayBlockingQueue<T> newArrayBlockingQueue​(int capacity, boolean fair, java.util.Collection<T> collection)  
      static <T> java.util.ArrayList<T> newArrayList()  
      static <T> java.util.ArrayList<T> newArrayList​(int capacity)  
      static <T> java.util.ArrayList<T> newArrayList​(java.util.Collection<T> collection)  
      static <T> java.util.ArrayList<T> newArrayList​(T[] entries)  
      static <T> java.util.concurrent.ConcurrentLinkedDeque<T> newConcurrentLinkedDeque()  
      static <T> java.util.concurrent.ConcurrentLinkedDeque<T> newConcurrentLinkedDeque​(java.util.Collection<T> collection)  
      static <T> java.util.concurrent.ConcurrentLinkedQueue<T> newConcurrentLinkedQueue()  
      static <T> java.util.concurrent.ConcurrentLinkedQueue<T> newConcurrentLinkedQueue​(java.util.Collection<T> collection)  
      static <T> java.util.concurrent.CopyOnWriteArrayList<T> newCopyOnWriteArrayList()  
      static <T> java.util.concurrent.CopyOnWriteArrayList<T> newCopyOnWriteArrayList​(java.util.Collection<T> collection)  
      static <T> java.util.HashSet<T> newHashSet()  
      static <T> java.util.HashSet<T> newHashSet​(int capacity)  
      static <T> java.util.HashSet<T> newHashSet​(java.util.Collection<T> collection)  
      static <T> java.util.concurrent.LinkedBlockingDeque<T> newLinkedBlockingDeque()  
      static <T> java.util.concurrent.LinkedBlockingDeque<T> newLinkedBlockingDeque​(java.util.Collection<T> collection)  
      static <T> java.util.concurrent.LinkedBlockingQueue<T> newLinkedBlockingQueue()  
      static <T> java.util.concurrent.LinkedBlockingQueue<T> newLinkedBlockingQueue​(java.util.Collection<T> collection)  
      static <T> java.util.LinkedList<T> newLinkedList()  
      static <T> java.util.LinkedList<T> newLinkedList​(java.util.Collection<T> collection)  
      static <K,​T>
      T
      reduce​(java.util.Collection<K> collection, java.util.function.BiFunction<T,​K,​T> function, T t)  
      static <K,​T>
      T
      reduce​(K[] array, java.util.function.BiFunction<T,​K,​T> function, T t)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Iterables

        private Iterables()
    • Method Detail

      • newArrayList

        public static <T> java.util.ArrayList<T> newArrayList()
      • newArrayList

        public static <T> java.util.ArrayList<T> newArrayList​(java.util.Collection<T> collection)
      • newArrayList

        public static <T> java.util.ArrayList<T> newArrayList​(int capacity)
      • newArrayList

        public static <T> java.util.ArrayList<T> newArrayList​(T[] entries)
      • newHashSet

        public static <T> java.util.HashSet<T> newHashSet()
      • newHashSet

        public static <T> java.util.HashSet<T> newHashSet​(java.util.Collection<T> collection)
      • newHashSet

        public static <T> java.util.HashSet<T> newHashSet​(int capacity)
      • newLinkedList

        public static <T> java.util.LinkedList<T> newLinkedList()
      • newLinkedList

        public static <T> java.util.LinkedList<T> newLinkedList​(java.util.Collection<T> collection)
      • newCopyOnWriteArrayList

        public static <T> java.util.concurrent.CopyOnWriteArrayList<T> newCopyOnWriteArrayList()
      • newCopyOnWriteArrayList

        public static <T> java.util.concurrent.CopyOnWriteArrayList<T> newCopyOnWriteArrayList​(java.util.Collection<T> collection)
      • newConcurrentLinkedQueue

        public static <T> java.util.concurrent.ConcurrentLinkedQueue<T> newConcurrentLinkedQueue()
      • newConcurrentLinkedQueue

        public static <T> java.util.concurrent.ConcurrentLinkedQueue<T> newConcurrentLinkedQueue​(java.util.Collection<T> collection)
      • newLinkedBlockingQueue

        public static <T> java.util.concurrent.LinkedBlockingQueue<T> newLinkedBlockingQueue()
      • newLinkedBlockingQueue

        public static <T> java.util.concurrent.LinkedBlockingQueue<T> newLinkedBlockingQueue​(java.util.Collection<T> collection)
      • newConcurrentLinkedDeque

        public static <T> java.util.concurrent.ConcurrentLinkedDeque<T> newConcurrentLinkedDeque()
      • newConcurrentLinkedDeque

        public static <T> java.util.concurrent.ConcurrentLinkedDeque<T> newConcurrentLinkedDeque​(java.util.Collection<T> collection)
      • newLinkedBlockingDeque

        public static <T> java.util.concurrent.LinkedBlockingDeque<T> newLinkedBlockingDeque()
      • newLinkedBlockingDeque

        public static <T> java.util.concurrent.LinkedBlockingDeque<T> newLinkedBlockingDeque​(java.util.Collection<T> collection)
      • newArrayBlockingQueue

        public static <T> java.util.concurrent.ArrayBlockingQueue<T> newArrayBlockingQueue​(int capacity)
      • newArrayBlockingQueue

        public static <T> java.util.concurrent.ArrayBlockingQueue<T> newArrayBlockingQueue​(int capacity,
                                                                                           boolean fair)
      • newArrayBlockingQueue

        public static <T> java.util.concurrent.ArrayBlockingQueue<T> newArrayBlockingQueue​(int capacity,
                                                                                           boolean fair,
                                                                                           java.util.Collection<T> collection)
      • forEach

        public static void forEach​(java.util.Properties properties,
                                   java.util.function.Consumer<java.lang.String> consumer)
        Iterates all keys in a Properties class instance.
        Parameters:
        properties - the properties which should iterate
        consumer - the handler which handle the following keys
      • forEach

        public static <T> void forEach​(java.util.Enumeration<T> enumeration,
                                       java.util.function.Consumer<T> consumer)
        Iterates all keys in a Enumeration class instance.
        Parameters:
        enumeration - the items which should iterate
        consumer - the handler which handle the following keys
      • forEach

        public static <T> void forEach​(java.util.List<T> list,
                                       java.util.function.Consumer<T> consumer)
        Iterates all keys in a List class instance.
        Parameters:
        list - the items which should iterate
        consumer - the handler which handle the following keys
      • forEach

        public static <T> void forEach​(java.util.Enumeration<T> enumeration,
                                       java.util.function.Consumer<T> consumer,
                                       java.util.function.Consumer<java.lang.Throwable> throwableConsumer)
        Iterates all keys in a Enumeration class instance.
        Parameters:
        enumeration - the items which should iterate
        consumer - the handler which handle the following keys
        throwableConsumer - will called if the consumer handler throws an Throwable
      • forEach

        public static <T> void forEach​(java.util.Iterator<T> iterator,
                                       java.util.function.Consumer<T> consumer)
        Iterates all keys in a List class instance.
        Parameters:
        iterator - the items which should iterate
        consumer - the handler which handle the following keys
      • forEach

        public static <T> void forEach​(java.util.Iterator<T> iterator,
                                       java.util.function.Consumer<T> consumer,
                                       java.util.function.Consumer<java.lang.Throwable> throwableConsumer)
        Iterates all keys in a Iterator class instance.
        Parameters:
        iterator - the items which should iterate
        consumer - the handler which handle the following keys
        throwableConsumer - will called if the consumer handler throws an Throwable
      • first

        public static <T> T first​(java.lang.Iterable<T> iterable,
                                  java.util.function.Predicate<T> predicate)
        Filters the first item in an Iterable, which the predicate returns true
      • first

        public static <T> T first​(T[] iterable,
                                  java.util.function.Predicate<T> predicate)
      • filter

        public static <T> java.util.List<T> filter​(java.lang.Iterable<T> iterable,
                                                   java.util.function.Predicate<T> predicate)
      • filter

        public static <T> void filter​(java.lang.Iterable<T> iterable,
                                      java.util.function.Predicate<T> predicate,
                                      java.util.Collection<T> out)
      • map

        public static <T,​V> java.util.List<V> map​(T[] array,
                                                        java.util.function.Function<T,​V> function)
      • map

        public static <T,​V> java.util.List<V> map​(java.util.Collection<T> coll,
                                                        java.util.function.Function<T,​V> function)
      • reduce

        public static <K,​T> T reduce​(K[] array,
                                           java.util.function.BiFunction<T,​K,​T> function,
                                           T t)
      • reduce

        public static <K,​T> T reduce​(java.util.Collection<K> collection,
                                           java.util.function.BiFunction<T,​K,​T> function,
                                           T t)
      • contains

        public static <T> boolean contains​(T t,
                                           T[] array)