xades4j.utils
Class CollectionUtils

java.lang.Object
  extended by xades4j.utils.CollectionUtils

public class CollectionUtils
extends Object

Provides some utility methods over collections.

Author:
Luís

Nested Class Summary
static interface CollectionUtils.Predicate<T>
           
static interface CollectionUtils.Projector<T1,T2>
           
 
Constructor Summary
CollectionUtils()
           
 
Method Summary
static
<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 is null.
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> Collection<T>
newIfNull(Collection<T> c, int size)
          Get a collection with the specified initial size if the given collection is null.
static
<TK,TV> Map<TK,TV>
newIfNull(Map<TK,TV> m, int size)
          Same as newIfNull but for maps.
static
<T> boolean
nullOrEmpty(Collection<T> c)
          Indicates whether a collection is null or empty.
static
<TSrc,TDest>
Collection<TDest>
project(Collection<TSrc> c, CollectionUtils.Projector<TSrc,TDest> p)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionUtils

public CollectionUtils()
Method Detail

newIfNull

public static <T> Collection<T> newIfNull(Collection<T> c,
                                          int size)
Get a collection with the specified initial size if the given collection is null. The returned collection, if new, will support the remove operation.

Parameters:
c - the collection to be tested
size - the initial size of the returned collection, if new
Returns:
a new collection or c if it is not null

newIfNull

public static <TK,TV> Map<TK,TV> newIfNull(Map<TK,TV> m,
                                           int size)
Same as newIfNull but for maps.

Parameters:
m - the map to be tested
size - the initial size of the returned map, if new
Returns:
a new map or m if it is not null

emptyIfNull

public static <T> Collection<T> emptyIfNull(Collection<T> c)
Get an empty collection if the given collection is null. 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

public static <TK,TV> Map<TK,TV> emptyIfNull(Map<TK,TV> m)

cloneOrEmptyIfNull

public static <T> Collection<T> cloneOrEmptyIfNull(Collection<T> c)

cloneOrEmptyIfNull

public static <TK,TV> Map<TK,TV> cloneOrEmptyIfNull(Map<TK,TV> m)

nullOrEmpty

public static <T> boolean nullOrEmpty(Collection<T> c)
Indicates whether a collection is null or empty.

Parameters:
c - the collection to be tested
Returns:
true if the collection is null or empty

filter

public static <T> List<T> filter(Collection<T> c,
                                 CollectionUtils.Predicate<T> p)

project

public static <TSrc,TDest> Collection<TDest> project(Collection<TSrc> c,
                                                     CollectionUtils.Projector<TSrc,TDest> p)


Copyright © 2012. All Rights Reserved.