Class CollectionUtil


  • public class CollectionUtil
    extends Object
    • Constructor Detail

      • CollectionUtil

        public CollectionUtil()
    • Method Detail

      • list

        public static <T> List<T> list​(T a,
                                       T b)
      • combinations

        public static List combinations​(List original,
                                        int maxCombinationSize)
        Returns a List of Lists: all combinations of the elements of the given List.
        Parameters:
        maxCombinationSize - combinations larger than this value are discarded
      • inverse

        public static <U,​V> Map<V,​U> inverse​(Map<U,​V> map)
      • combinations

        public static <T> List<List<T>> combinations​(List<T> original,
                                                     int maxCombinationSize,
                                                     T mandatoryItem)
        Returns a List of Lists: all combinations of the elements of the given List.
        Parameters:
        maxCombinationSize - combinations larger than this value are discarded
        mandatoryItem - an item that all returned combinations must contain, or null to leave unspecified
      • combinations

        public static <T> List<List<T>> combinations​(List<T> original)
        Returns a List of Lists: all combinations of the elements of the given List.
      • removeKeys

        public static <U,​V> void removeKeys​(Collection<U> keys,
                                                  Map<U,​V> map)
      • keysAndCorrespondingValues

        public static List[] keysAndCorrespondingValues​(Map map)
        The nth key corresponds to the nth value
      • randomElement

        public static Object randomElement​(List list)
      • reverseSortedSet

        public static SortedSet<Integer> reverseSortedSet​(int[] ints)
      • reverse

        public static List reverse​(List list)
      • stretch

        public static <T> Collection stretch​(Collection<T> source,
                                             Collection<T> destination,
                                             int destinationSize)
        Data is evenly discarded or duplicated to attain the new size
      • setIfNull

        public static void setIfNull​(int i,
                                     List<String> list,
                                     String value)
      • resize

        public static void resize​(List list,
                                  int newSize)
      • containsReference

        public static boolean containsReference​(Object[] objects,
                                                Object o)
      • indexOf

        public static int indexOf​(Object o,
                                  Object[] objects)
      • removeDuplicates

        public static <T> Collection<T> removeDuplicates​(Collection<T> original)
        Brute force, for when HashSet and TreeSet won't work (e.g. #hashCode implementation isn't appropriate). The original Collection is not modified.
      • addIfNotNull

        public static void addIfNotNull​(Object item,
                                        Collection collection)
      • filterByClass

        public static Collection filterByClass​(Collection collection,
                                               Class c)
        Modifies and returns the collection.
      • createMap

        public static Map createMap​(Object[] alternatingKeysAndValues)
      • collect

        public static <T,​R> Collection<R> collect​(Collection<T> collection,
                                                        Block block)
        The Smalltalk #collect method.
      • get

        public static Object get​(Class<?> c,
                                 Map<Class<?>,​? extends Object> map)
        Search an object associated to the class c or one of its parent in the associative map
        Parameters:
        c - the class used as a key
        map - the associative map in which the research is made
        Returns:
        an object or null if no object is associated to class c or one of its parent