Class CollectionHelper

java.lang.Object
net.sf.colossus.util.CollectionHelper

public class CollectionHelper extends Object
A collection of static methods to help with using java.util.Collection derivates. This is an addition to Collections.
  • Constructor Details

    • CollectionHelper

      public CollectionHelper()
  • Method Details

    • copySelective

      public static <T> void copySelective(Collection<? extends T> source, Collection<? super T> target, Predicate<T> filter)
      Copies all elements that match a predicate. Every element of the first collection for which the predicate holds (i.e. returns true) is added to the second collection.
    • selectAsList

      public static <T> List<T> selectAsList(Collection<? extends T> source, Predicate<T> filter)
      Retrieves all elements from a collection that match a predicate. The result will be all elements of the source collection for which the predicate is true, retrieved in normal iteration order.
      Type Parameters:
      T - The type of elements we are interested in.
      Parameters:
      source - A collection containing elements we are interested in. Not null. Can be empty.
      filter - The predicate determining if an element is to be retrieved. Not null.
      Returns:
      A list containing all matching elements in iteration order. Never null. Can be empty.
    • selectFirst

      public static <T> T selectFirst(Collection<? extends T> source, Predicate<T> filter)
      Retrieves the first element from a collection that matches a predicate.
      Type Parameters:
      T - The type of elements we are interested in.
      Parameters:
      source - A collection containing elements we are interested in. Not null. Can be empty.
      filter - The predicate determining if an element is to be retrieved. Not null.
      Returns:
      The first matching element or null if no element matches.