Class CollectionUtils


  • public final class CollectionUtils
    extends java.lang.Object
    Contains methods for dealing with collections.
    Since:
    1.4.0
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String convertMapToString​(java.util.Map<java.lang.String,​java.lang.String> stringMap)
      Converts a map into a delimited string value.
      static java.util.Map<java.lang.String,​java.lang.String> convertStringToMap​(java.lang.String value)
      Converts a delimited string value into a map.
      static <T> boolean doesItemExistInCollection​(java.util.Collection<T> collection, java.util.function.Predicate<T> condition)
      Checks if an item exists in a Collection that matches the specified Predicate.
      static <K,​V>
      boolean
      doesItemExistInMap​(java.util.Map<K,​V> map, java.util.function.Predicate<V> condition)
      Checks if a value exists in a HashMap that matches the specified Predicate.
      static <T> java.util.Optional<T> getItemInCollection​(java.util.Collection<T> collection, java.util.function.Predicate<T> condition)
      Returns the first item in a HashSet that matches the specified Predicate.
      static <T> @NotNull java.util.Set<T> getItemsInCollection​(java.util.Collection<T> collection, java.util.function.Predicate<T> condition)
      Returns the items in a Collection that matches the specified Predicate.
      static <K,​V>
      java.util.Optional<V>
      getValueInMap​(java.util.Map<K,​V> map, java.util.function.Predicate<V> condition)
      Returns the first item found in a Map that matches the specified Predicate.
      static <K,​V>
      java.util.Set<V>
      getValuesInMap​(java.util.Map<K,​V> map, java.util.function.Predicate<V> condition)
      Returns a Set of values in a Map that match the specified Predicate.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • convertMapToString

        public static java.lang.String convertMapToString​(java.util.Map<java.lang.String,​java.lang.String> stringMap)
        Converts a map into a delimited string value. A "=" separates the keys and values and a "&" separates the key pairs.
        Parameters:
        stringMap - map to convert
        Returns:
        string representation of map
        Throws:
        java.lang.IllegalArgumentException - if StringMap is null
      • convertStringToMap

        public static java.util.Map<java.lang.String,​java.lang.String> convertStringToMap​(java.lang.String value)
        Converts a delimited string value into a map.

        Expects that "=" separates the keys and values and a "&" separates the key pairs.

        Parameters:
        value - map to convert
        Returns:
        string representation of map
        Throws:
        java.lang.IllegalArgumentException - if Value is null
        Since:
        1.5.0 now uses a stream to process the pairs
      • doesItemExistInCollection

        public static <T> boolean doesItemExistInCollection​(java.util.Collection<T> collection,
                                                            java.util.function.Predicate<T> condition)
        Checks if an item exists in a Collection that matches the specified Predicate.
        Type Parameters:
        T - the type of objects in the HashSet
        Parameters:
        collection - the Collection to check against
        condition - the Predicate to check
        Returns:
        true if condition is true
        Throws:
        java.lang.IllegalArgumentException - if Collection or Predicate is null
        Since:
        1.5.0 now uses a java Parallel Stream to allow for a large list of values
      • doesItemExistInMap

        public static <K,​V> boolean doesItemExistInMap​(java.util.Map<K,​V> map,
                                                             java.util.function.Predicate<V> condition)
        Checks if a value exists in a HashMap that matches the specified Predicate.
        Type Parameters:
        K - the type of the Key in the Map
        V - the type of the Value in the Map
        Parameters:
        map - the Map to check against
        condition - the Predicate to check
        Returns:
        true if condition is true
        Throws:
        java.lang.IllegalArgumentException - if HashMap or Predicate is null
        Since:
        1.5.0 now uses a java Parallel Stream to allow for a large list of values
      • getItemInCollection

        public static <T> java.util.Optional<T> getItemInCollection​(java.util.Collection<T> collection,
                                                                    java.util.function.Predicate<T> condition)
        Returns the first item in a HashSet that matches the specified Predicate.
        Type Parameters:
        T - the type of objects in the Collection
        Parameters:
        collection - the Collection to check against
        condition - the Predicate to check
        Returns:
        an Optional containing the matching object, Empty if not found
        Throws:
        java.lang.IllegalArgumentException - if Collection or Predicate is null
        Since:
        1.5.0 now uses a java Parallel Stream to allow for a large list of values
      • getItemsInCollection

        @NotNull
        public static <T> @NotNull java.util.Set<T> getItemsInCollection​(java.util.Collection<T> collection,
                                                                         java.util.function.Predicate<T> condition)
        Returns the items in a Collection that matches the specified Predicate.
        Type Parameters:
        T - the Object type that is stored in the Collection
        Parameters:
        collection - the Collection to check against
        condition - the Predicate to evaluate
        Returns:
        a HashSet of items that match match the Predicate
        Since:
        1.5.0 now uses a java Parallel Stream to allow for a large list of values
      • getValuesInMap

        public static <K,​V> java.util.Set<V> getValuesInMap​(java.util.Map<K,​V> map,
                                                                  java.util.function.Predicate<V> condition)
        Returns a Set of values in a Map that match the specified Predicate.
        Type Parameters:
        K - the type of the Key in the Map
        V - the type of the Value in the Map
        Parameters:
        map - the Map to check against
        condition - the Predicate to check
        Returns:
        a Set of values matching the predicate, an empty Set if no results found
        Throws:
        java.lang.IllegalArgumentException - if Map or Predicate is null
        Since:
        1.5.0 now uses a java Parallel Stream to allow for a large list of values
      • getValueInMap

        public static <K,​V> java.util.Optional<V> getValueInMap​(java.util.Map<K,​V> map,
                                                                      java.util.function.Predicate<V> condition)
        Returns the first item found in a Map that matches the specified Predicate.
        Type Parameters:
        K - the type of the Key in the Map
        V - the type of the Value in the Map
        Parameters:
        map - the Map to check against
        condition - the Predicate to check
        Returns:
        an Optional containing the matching value, Empty if no results found
        Throws:
        java.lang.IllegalArgumentException - if Map or Predicate is null
        Since:
        1.5.0 now uses a java Parallel Stream to allow for a large list of values