Package com.gengoai.collection
Class Collect
- java.lang.Object
-
- com.gengoai.collection.Collect
-
public final class Collect extends Object
Convenience methods for manipulating Collections.
- Author:
- David B. Bracewell
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Collection<T>
addAll(@NonNull Collection<T> collection, @NonNull Iterable<? extends T> iterable)
Adds all elements in the iterable to the given collectionstatic <T> Collection<T>
addAll(@NonNull Collection<T> collection, @NonNull Iterator<? extends T> iterator)
Adds all elements in the iterator to the given collectionstatic <T> Collection<T>
addAll(@NonNull Collection<T> collection, @NonNull Stream<? extends T> stream)
Adds all elements in the stream to the given collectionstatic <T> Collection<T>
asCollection(@NonNull Iterable<? extends T> iterable)
Wraps an iterable as a collection.static <T extends Collection>
TnewCollection(Class<T> collectionClass)
Creates a default instance of a collection type.
-
-
-
Method Detail
-
addAll
public static <T> Collection<T> addAll(@NonNull @NonNull Collection<T> collection, @NonNull @NonNull Iterable<? extends T> iterable)
Adds all elements in the iterable to the given collection- Type Parameters:
T
- the element type parameter- Parameters:
collection
- the collection to add values toiterable
- the iterable of elements to add- Returns:
- the collection with new elements added
-
addAll
public static <T> Collection<T> addAll(@NonNull @NonNull Collection<T> collection, @NonNull @NonNull Iterator<? extends T> iterator)
Adds all elements in the iterator to the given collection- Type Parameters:
T
- the element type parameter- Parameters:
collection
- the collection to add values toiterator
- the iterator of elements to add- Returns:
- the collection with new elements added
-
addAll
public static <T> Collection<T> addAll(@NonNull @NonNull Collection<T> collection, @NonNull @NonNull Stream<? extends T> stream)
Adds all elements in the stream to the given collection- Type Parameters:
T
- the element type parameter- Parameters:
collection
- the collection to add values tostream
- the stream of elements to add- Returns:
- the collection with new elements added
-
asCollection
public static <T> Collection<T> asCollection(@NonNull @NonNull Iterable<? extends T> iterable)
Wraps an iterable as a collection.- Type Parameters:
T
- the element type parameter- Parameters:
iterable
- the iterable to wrap- Returns:
- the wrapped iterable
-
newCollection
public static <T extends Collection> T newCollection(Class<T> collectionClass)
Creates a default instance of a collection type. If the passed in class is an implementation then that implementation is created using the no-arg constructor. Interfaces (e.g. Set and List) have default implementations assigned and returned.
- Type Parameters:
T
- the type parameter- Parameters:
collectionClass
- the collection class- Returns:
- t t
-
-