public class CollectionUtils
extends java.lang.Object
Utility methods for working with Collection
types
Constructor and Description |
---|
CollectionUtils() |
Modifier and Type | Method and Description |
---|---|
static <T> java.util.Optional<java.lang.Iterable<T>> |
convertCollection(java.lang.Class<? extends java.lang.Iterable<T>> iterableType,
java.util.Collection<T> collection)
Attempts to convert a collection to the given iterabable type
|
static <T> java.lang.Iterable<T> |
enumerationToIterable(java.util.Enumeration<T> enumeration)
Convert an
Enumeration to a Iterable . |
static <T> java.util.Set<T> |
enumerationToSet(java.util.Enumeration<T> enumeration)
Convert an
Enumeration to a Set . |
static boolean |
isEmpty(java.util.Collection collection)
Null safe empty check.
|
static boolean |
isEmpty(java.util.Map map)
Null safe empty check.
|
static boolean |
isIterableOrMap(java.lang.Class<?> type)
Is the given type an iterable or map type.
|
static boolean |
isNotEmpty(java.util.Collection collection)
Null safe not empty check.
|
static boolean |
isNotEmpty(java.util.Map map)
Null safe not empty check.
|
static <T> java.util.List<T> |
iterableToList(java.lang.Iterable<T> iterable)
Converts an
Iterable to a List . |
static <T> java.util.Set<T> |
iterableToSet(java.lang.Iterable<T> iterable)
Converts an
Iterable to a Set . |
static <T> java.util.Set<T> |
iteratorToSet(java.util.Iterator<T> iterator)
Convert an
Iterator to a Set . |
static <T> T |
last(java.util.Collection<T> collection)
Returns the last element of a collection.
|
static java.util.Map |
mapOf(java.lang.Object... values)
Create a
LinkedHashMap from an array of values. |
static <T> java.util.Set<T> |
setOf(T... objects)
Creates a set of the given objects.
|
static java.lang.String |
toString(java.lang.Iterable<?> iterable)
Produce a string representation of the given iterable.
|
static java.lang.String |
toString(java.lang.String delimiter,
java.lang.Iterable<?> iterable)
Produce a string representation of the given iterable.
|
static <T> java.util.List<T> |
unmodifiableList(java.util.List<T> list)
Null safe version of
Collections.unmodifiableList(List) . |
public static boolean isIterableOrMap(java.lang.Class<?> type)
type
- The typepublic static boolean isEmpty(@Nullable java.util.Map map)
map
- The mappublic static boolean isNotEmpty(@Nullable java.util.Map map)
map
- The ,appublic static boolean isEmpty(@Nullable java.util.Collection collection)
collection
- The collectionpublic static boolean isNotEmpty(@Nullable java.util.Collection collection)
collection
- The collectionpublic static <T> java.util.Optional<java.lang.Iterable<T>> convertCollection(java.lang.Class<? extends java.lang.Iterable<T>> iterableType, java.util.Collection<T> collection)
Attempts to convert a collection to the given iterabable type
.T
- The collection generic typeiterableType
- The iterable typecollection
- The collectionOptional
of the converted typepublic static java.util.Map mapOf(java.lang.Object... values)
LinkedHashMap
from an array of values.values
- The valuespublic static <T> java.util.Set<T> iteratorToSet(java.util.Iterator<T> iterator)
Iterator
to a Set
.T
- The typeiterator
- The iteratorpublic static <T> java.util.Set<T> enumerationToSet(java.util.Enumeration<T> enumeration)
Enumeration
to a Set
.T
- The typeenumeration
- The iterator@NonNull public static <T> java.lang.Iterable<T> enumerationToIterable(@Nullable java.util.Enumeration<T> enumeration)
Enumeration
to a Iterable
.T
- The typeenumeration
- The iteratorpublic static <T> java.util.Set<T> setOf(T... objects)
T
- The typeobjects
- The objectspublic static java.lang.String toString(java.lang.Iterable<?> iterable)
iterable
- The iterablepublic static java.lang.String toString(java.lang.String delimiter, java.lang.Iterable<?> iterable)
delimiter
- The delimiteriterable
- The iterablepublic static <T> java.util.List<T> iterableToList(java.lang.Iterable<T> iterable)
Iterable
to a List
.T
- The generic typeiterable
- The iterablepublic static <T> java.util.Set<T> iterableToSet(java.lang.Iterable<T> iterable)
Iterable
to a Set
.T
- The generic typeiterable
- The iterable@NonNull public static <T> java.util.List<T> unmodifiableList(@Nullable java.util.List<T> list)
Collections.unmodifiableList(List)
.T
- The generic typelist
- The list@Nullable public static <T> T last(@NonNull java.util.Collection<T> collection)
T
- The generic typecollection
- The collection