Package org.goplanit.utils.misc
Class IterableUtils
- java.lang.Object
-
- org.goplanit.utils.misc.IterableUtils
-
public class IterableUtils extends Object
Utils for iterable class- Author:
- markr
-
-
Constructor Summary
Constructors Constructor Description IterableUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Stream<T>
asStream(Iterable<T> iterable)
As non-parallel streamstatic boolean
nullOrEmpty(Iterable<?> iterable)
Check if iterable is null or emptystatic <T> long
sizeOfUsingLoop(Iterable<T> iterable)
Collect the number of entry edge segments of this vertexstatic <T> long
sizeOfUsingStream(Iterable<T> iterable)
Collect the number of entry edge segments of this vertexstatic <T> Iterable<T>
toIterable(Iterator<T> iterator)
Get iterable from iteratorstatic <T> List<T>
toList(Iterable<T> iterable)
Convert iterable to list of same typestatic <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 entriesstatic <U extends T,T>
List<U>toTypeCastList(Iterable<T> iterable)
Convert iterable to list of derived concrete type by type casting the entries
-
-
-
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 vertexslow 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 vertexslow 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 iterableK
- type of key- Parameters:
iterable
- to usegetKey
- function to extract key from entriesmapToFill
- 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 thisT
- 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
-
-