Package xades4j.utils

Class CollectionUtils

java.lang.Object
xades4j.utils.CollectionUtils

public class CollectionUtils extends Object
Provides some utility methods over collections.
Author:
Luís
  • Constructor Details

    • CollectionUtils

      public CollectionUtils()
  • Method Details

    • 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> List<TDest> project(Collection<TSrc> c, CollectionUtils.Projector<TSrc,TDest> p)
    • filterByType

      public static <T, T1 extends T> List<T1> filterByType(Collection<T> c, Class<T1> clazz)