Class CollectionUtil
- java.lang.Object
-
- gov.nist.secauto.metaschema.core.util.CollectionUtil
-
public final class CollectionUtil extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Iterator<T>
descendingIterator(List<T> list)
static <T> List<T>
emptyList()
static <K,V>
Map<K,V>emptyMap()
static <T> Set<T>
emptySet()
static <T> List<T>
listOrEmpty(List<T> list)
static <T> List<T>
listOrEmpty(T... array)
static <T extends Collection<A>,A>
TrequireNonEmpty(T collection)
static <T extends Collection<A>,A>
TrequireNonEmpty(T collection, String message)
static <T> Set<T>
singleton(T value)
static <T> List<T>
singletonList(T instance)
static <K,V>
Map<K,V>singletonMap(K key, V value)
static <T> Iterable<T>
toDescendingIterable(List<T> list)
static <T> Iterable<T>
toIterable(Iterator<T> iterator)
static <T> Iterable<T>
toIterable(Stream<T> stream)
static <T> List<T>
toList(Iterable<T> iterable)
Convert the providedIterable
to a list of the same generic type.static <T> List<T>
toList(Iterator<T> iterator)
Convert the providedIterator
to a list of the same generic type.static <T> Stream<T>
toStream(Iterator<T> iterator)
static <T> Collection<T>
unmodifiableCollection(Collection<T> collection)
A wrapper of theCollections.unmodifiableCollection(Collection)
method that ensure aNonNull
result is returned.static <T> List<T>
unmodifiableList(List<T> list)
static <K,V>
Map<K,V>unmodifiableMap(Map<K,V> map)
static <T> Set<T>
unmodifiableSet(Set<T> set)
-
-
-
Method Detail
-
toStream
public static <T> Stream<T> toStream(@NonNull Iterator<T> iterator)
- Type Parameters:
T
- the type to iterate on- Parameters:
iterator
- the iterator- Returns:
- the stream
-
toIterable
@NonNull public static <T> Iterable<T> toIterable(@NonNull Stream<T> stream)
- Type Parameters:
T
- the type to iterate on- Parameters:
stream
- the stream to iterate over- Returns:
- the resulting iterable instance
-
toIterable
@NonNull public static <T> Iterable<T> toIterable(@NonNull Iterator<T> iterator)
- Type Parameters:
T
- the type to iterate on- Parameters:
iterator
- the iterator- Returns:
- the resulting iterable instance
-
toDescendingIterable
@NonNull public static <T> Iterable<T> toDescendingIterable(@NonNull List<T> list)
- Type Parameters:
T
- the type to iterate on- Parameters:
list
- the list of items to iterate over- Returns:
- the resulting iterable instance
-
toList
@NonNull public static <T> List<T> toList(Iterable<T> iterable)
Convert the providedIterable
to a list of the same generic type.- Type Parameters:
T
- the collection item's generic type- Parameters:
iterable
- the Iterable to convert to a list- Returns:
- the list
-
toList
@NonNull public static <T> List<T> toList(Iterator<T> iterator)
Convert the providedIterator
to a list of the same generic type.- Type Parameters:
T
- the collection item's generic type- Parameters:
iterator
- the Iterator to convert to a list- Returns:
- the list
-
descendingIterator
@NonNull public static <T> Iterator<T> descendingIterator(@NonNull List<T> list)
- Type Parameters:
T
- the type to iterate on- Parameters:
list
- the list of items to iterate over- Returns:
- the resulting Iterator instance
-
requireNonEmpty
@NonNull public static <T extends Collection<A>,A> T requireNonEmpty(@NonNull T collection)
-
requireNonEmpty
@NonNull public static <T extends Collection<A>,A> T requireNonEmpty(@NonNull T collection, @NonNull String message)
-
unmodifiableCollection
@NonNull public static <T> Collection<T> unmodifiableCollection(@NonNull Collection<T> collection)
A wrapper of theCollections.unmodifiableCollection(Collection)
method that ensure aNonNull
result is returned.- Type Parameters:
T
- the collection's item type- Parameters:
collection
- the collection- Returns:
- a non-null unmodifiable instance of the provided collection
-
unmodifiableSet
@NonNull public static <T> Set<T> unmodifiableSet(@NonNull Set<T> set)
-
listOrEmpty
@NonNull public static <T> List<T> listOrEmpty(@Nullable List<T> list)
-
listOrEmpty
@SafeVarargs @NonNull public static <T> List<T> listOrEmpty(@Nullable T... array)
-
unmodifiableList
@NonNull public static <T> List<T> unmodifiableList(@NonNull List<T> list)
-
singletonList
@NonNull public static <T> List<T> singletonList(@NonNull T instance)
-
singletonMap
@NonNull public static <K,V> Map<K,V> singletonMap(@NonNull K key, @NonNull V value)
-
unmodifiableMap
@NonNull public static <K,V> Map<K,V> unmodifiableMap(@NonNull Map<K,V> map)
-
-