Class BLCCollectionUtils
java.lang.Object
org.broadleafcommerce.common.util.BLCCollectionUtils
Convenience methods for interacting with collections.
- Author:
- Andre Azzolini (apazzolini)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Collection<T>
collect
(Collection inputCollection, TypedTransformer<T> transformer) Delegates toCollectionUtils.collect(Collection, Transformer)
, but performs the necessary type coercion to allow the returned collection to be correctly casted based on the TypedTransformer.static <T> T[]
collectArray
(Collection inputCollection, TypedTransformer<T> transformer, Class<T> clazz) The same ascollect(Collection, TypedTransformer)
but returns an arraystatic <T> List<T>
collectList
(Collection inputCollection, TypedTransformer<T> transformer) The same ascollect(Collection, TypedTransformer)
but returns an ArrayListstatic <T extends Collection>
TcreateChangeAwareCollection
(WorkOnChange work, Collection original) Create a collection proxy that will perform some piece of work whenever modification methods are called on the proxy.static <T> List<T>
createIfNull
(List<T> list) It is common to want to make sure that a collection you receive is not null.static <T> List<T>
selectList
(Collection<T> inputCollection, TypedPredicate<T> predicate) Delegates toCollectionUtils.select(Collection, org.apache.commons.collections.Predicate)
, but will force the return type to be a List.
-
Constructor Details
-
BLCCollectionUtils
public BLCCollectionUtils()
-
-
Method Details
-
collect
public static <T> Collection<T> collect(Collection inputCollection, TypedTransformer<T> transformer) Delegates toCollectionUtils.collect(Collection, Transformer)
, but performs the necessary type coercion to allow the returned collection to be correctly casted based on the TypedTransformer.- Parameters:
inputCollection
-transformer
-- Returns:
- the typed, collected Collection
-
collectList
The same ascollect(Collection, TypedTransformer)
but returns an ArrayList- Parameters:
inputCollection
-transformer
-- Returns:
-
collectArray
public static <T> T[] collectArray(Collection inputCollection, TypedTransformer<T> transformer, Class<T> clazz) The same ascollect(Collection, TypedTransformer)
but returns an array- Parameters:
inputCollection
-transformer
-- Returns:
-
selectList
Delegates toCollectionUtils.select(Collection, org.apache.commons.collections.Predicate)
, but will force the return type to be a List. - Parameters:
inputCollection
-predicate
-- Returns:
-
createIfNull
It is common to want to make sure that a collection you receive is not null. Instead, we'd rather have an empty list.- Parameters:
list
-- Returns:
- the passed in list if not null, otherwise a new ArrayList of the same type
-
createChangeAwareCollection
public static <T extends Collection> T createChangeAwareCollection(WorkOnChange work, Collection original) Create a collection proxy that will perform some piece of work whenever modification methods are called on the proxy. This includes the add, allAll, remove, removeAll, clear methods. Additionally, calling remove on an iterator created from this collection is also covered.- Type Parameters:
T
- the collection type (e.g. List, Set, etc...)- Parameters:
work
- the work to perform on collection modificationoriginal
- the original collection to make change aware- Returns:
- the proxied collection
-