Class BLCCollectionUtils

java.lang.Object
org.broadleafcommerce.common.util.BLCCollectionUtils

public class BLCCollectionUtils extends Object
Convenience methods for interacting with collections.
Author:
Andre Azzolini (apazzolini)
  • Constructor Details

    • BLCCollectionUtils

      public BLCCollectionUtils()
  • Method Details

    • collect

      public static <T> Collection<T> collect(Collection inputCollection, TypedTransformer<T> transformer)
      Delegates to CollectionUtils.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

      public static <T> List<T> collectList(Collection inputCollection, TypedTransformer<T> transformer)
      The same as collect(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 as collect(Collection, TypedTransformer) but returns an array
      Parameters:
      inputCollection -
      transformer -
      Returns:
    • selectList

      public static <T> List<T> selectList(Collection<T> inputCollection, TypedPredicate<T> predicate)
      Delegates to CollectionUtils.select(Collection, org.apache.commons.collections.Predicate), but will force the return type to be a List.
      Parameters:
      inputCollection -
      predicate -
      Returns:
    • createIfNull

      public static <T> List<T> createIfNull(List<T> list)
      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 modification
      original - the original collection to make change aware
      Returns:
      the proxied collection