Class IterableUtils


  • public class IterableUtils
    extends Object
    Utils for iterable class
    Author:
    markr
    • Constructor Detail

      • IterableUtils

        public IterableUtils()
    • Method Detail

      • asStream

        public static <T> Stream<T> asStream​(Iterable<T> iterable)
        As non-parallel stream
        Type Parameters:
        T - type of the iterable
        Parameters:
        iterable - iterable to stream
        Returns:
        stream
      • toIterable

        public static <T> Iterable<T> toIterable​(Iterator<T> iterator)
        Get iterable from iterator
        Type Parameters:
        T - type of iterator values
        Parameters:
        iterator - to convert to iterable
        Returns:
        iterable
      • sizeOfUsingStream

        public static <T> long sizeOfUsingStream​(Iterable<T> iterable)
        Collect the number of entry edge segments of this vertex

        slow method because it requires iterating over the underlying iterable since it is not a collection we are obtain the count from

        Type Parameters:
        T - iterable type
        Parameters:
        iterable - to count number of entries on by looping over the entire iterable
        Returns:
        number of entry edge segments
      • sizeOfUsingLoop

        public static <T> long sizeOfUsingLoop​(Iterable<T> iterable)
        Collect the number of entry edge segments of this vertex

        slow method because it requires iterating over the underlying iterable since it is not a collection we are obtain the count from

        Type Parameters:
        T - iterable type
        Parameters:
        iterable - to count number of entries on by looping over the entire iterable
        Returns:
        number of entry edge segments
      • toMap

        public static <T,​K> Map<K,​T> toMap​(Iterable<T> iterable,
                                                       Function<T,​K> getKey,
                                                       Map<K,​T> mapToFill)
        Map iterable to a map with a custom key obtained from the iterable entries
        Type Parameters:
        T - type of iterable
        K - type of key
        Parameters:
        iterable - to use
        getKey - function to extract key from entries
        mapToFill - to fill
        Returns:
        populated map
      • toList

        public static <T> List<T> toList​(Iterable<T> iterable)
        Convert iterable to list of same type
        Type Parameters:
        T - type of entries
        Parameters:
        iterable - to convert
        Returns:
        list of entries
      • toTypeCastList

        public static <U extends T,​T> List<U> toTypeCastList​(Iterable<T> iterable)
        Convert iterable to list of derived concrete type by type casting the entries
        Type Parameters:
        U - to be converted to this
        T - original type of iterable
        Parameters:
        iterable - to convert
        Returns:
        list of U
      • nullOrEmpty

        public static boolean nullOrEmpty​(Iterable<?> iterable)
        Check if iterable is null or empty
        Parameters:
        iterable - to check
        Returns:
        true when null or empty, false otherwise