Package xades4j.utils
Class CollectionUtils
java.lang.Object
xades4j.utils.CollectionUtils
Provides some utility methods over collections.
- Author:
- Luís
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
static interface
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Collection<T>
cloneOrEmptyIfNull
(Collection<T> c) static <TK,
TV> Map<TK, TV> cloneOrEmptyIfNull
(Map<TK, TV> m) static <T> Collection<T>
emptyIfNull
(Collection<T> c) Get an empty collection if the given collection isnull
.static <TK,
TV> Map<TK, TV> emptyIfNull
(Map<TK, TV> m) static <T> List<T>
filter
(Collection<T> c, CollectionUtils.Predicate<T> p) static <T,
T1 extends T>
List<T1>filterByType
(Collection<T> c, Class<T1> clazz) static <T> Collection<T>
newIfNull
(Collection<T> c, int size) Get a collection with the specified initial size if the given collection isnull
.static <TK,
TV> Map<TK, TV> Same asnewIfNull
but for maps.static <T> boolean
nullOrEmpty
(Collection<T> c) Indicates whether a collection isnull
or empty.static <TSrc,
TDest>
List<TDest>project
(Collection<TSrc> c, CollectionUtils.Projector<TSrc, TDest> p)
-
Constructor Details
-
CollectionUtils
public CollectionUtils()
-
-
Method Details
-
newIfNull
Get a collection with the specified initial size if the given collection isnull
. The returned collection, if new, will support theremove
operation.- Parameters:
c
- the collection to be testedsize
- the initial size of the returned collection, if new- Returns:
- a new collection or
c
if it is notnull
-
newIfNull
Same asnewIfNull
but for maps.- Parameters:
m
- the map to be testedsize
- the initial size of the returned map, if new- Returns:
- a new map or
m
if it is notnull
-
emptyIfNull
Get an empty collection if the given collection isnull
. The returned collection, if new, is immutable.- Parameters:
c
- the collection to be tested- Returns:
- a new empty collection or
c
if it is not null
-
emptyIfNull
-
cloneOrEmptyIfNull
-
cloneOrEmptyIfNull
-
nullOrEmpty
Indicates whether a collection isnull
or empty.- Parameters:
c
- the collection to be tested- Returns:
true
if the collection isnull
or empty
-
filter
-
project
public static <TSrc,TDest> List<TDest> project(Collection<TSrc> c, CollectionUtils.Projector<TSrc, TDest> p) -
filterByType
-