public class CollectionUtil2 extends Object
Collection utilities.
| Constructor and Description |
|---|
CollectionUtil2() |
| Modifier and Type | Method and Description |
|---|---|
protected static <T,C extends Collection<T>> |
collection(Supplier<C> funcEmptyCollection,
T... elements)
Creates a new collection from any number of arguments.
|
protected static <C extends Collection<String>> |
fromCsvStringTokenizer(Supplier<C> funcEmptyCollection,
String csv)
Creates a collection containing the elements of a comma separated string, with
the caveat that the processing is done by
StringTokenizer with the
delimiter ",". |
protected static <T,C extends Collection<T>> |
fromIterable(Supplier<C> funcEmptyCollection,
Iterable<T> iterable)
Creates a collection containing the elements of the given iterable.
|
protected static <T,C extends Collection<T>> |
fromIterator(Supplier<C> funcEmptyCollection,
Iterator<T> iterator)
Creates a collection containing the elements of the given iterator.
|
protected static <T,C extends Collection<T>> |
immutableCollectionOfType(IntFunction<C> funcEmptyCollectionOfSize,
UnaryOperator<C> funcImmutableCollection,
Collection<?> coll,
Class<T> type,
boolean nullOk)
Checks that all elements of the collection are of the specified type, and
returns an unmodifiable copy of the collection, with null elements either
allowed or disallowed.
|
protected static <T,C extends Collection<T>> C collection(Supplier<C> funcEmptyCollection, T... elements)
Creates a new collection from any number of arguments.
T - The type of element contained in the collection.C - The type of collection.funcEmptyCollection - A Supplier functor returning a brand new collection.elements - A succession of elements (possibly zero).protected static <T,C extends Collection<T>> C immutableCollectionOfType(IntFunction<C> funcEmptyCollectionOfSize, UnaryOperator<C> funcImmutableCollection, Collection<?> coll, Class<T> type, boolean nullOk)
Checks that all elements of the collection are of the specified type, and returns an unmodifiable copy of the collection, with null elements either allowed or disallowed.
T - The type of element contained in the collection.C - The type of collection.funcEmptyCollectionOfSize - An IntFunction functor that accepts a size and produces an
empty collection on that size (e.g.
ArrayList.ArrayList(int), HashSet.HashSet(int)).funcImmutableCollection - A UnaryOperator functor that accepts a collection and
returns an unmodifiable view of it (e.g.
Collections.unmodifiableList(List),
Collections.unmodifiableSet(Set)).coll - The input collection.type - The class with which all items of the collection must be
assignment-compatible.nullOk - Whether null elements are allowed.NullPointerException - if the collection is null or if any element is null.ClassCastException - if an item is not of the proper type.protected static <T,C extends Collection<T>> C fromIterator(Supplier<C> funcEmptyCollection, Iterator<T> iterator)
Creates a collection containing the elements of the given iterator.
T - The type of element contained in the collection.C - The type of collection.funcEmptyCollection - A Supplier functor returning a brand new collection.iterator - An iterator.protected static <T,C extends Collection<T>> C fromIterable(Supplier<C> funcEmptyCollection, Iterable<T> iterable)
Creates a collection containing the elements of the given iterable.
T - The type of element contained in the collection.C - The type of collection.funcEmptyCollection - A Supplier functor returning a brand new collection.iterable - An iterable.protected static <C extends Collection<String>> C fromCsvStringTokenizer(Supplier<C> funcEmptyCollection, String csv)
Creates a collection containing the elements of a comma separated string, with
the caveat that the processing is done by StringTokenizer with the
delimiter ",".
StringTokenizer simplistically looks for separators without a
quoting mechanism to return tokens containing the delimiter, nor does it
trim whitespace between tokens and delimiters. It also does not return
empty tokens, so calling this method with ",,," will return an
empty collection, not a collection of four empty strings.
C - The type of collection.funcEmptyCollection - A Supplier functor that generates an empty collection.csv - A simplistic CSV string.fromCsvStringTokenizer(Supplier, String)Copyright © 2000–2018 LOCKSS Program. All rights reserved.