Class CollectionUtils

java.lang.Object
org.apache.dubbo.common.utils.CollectionUtils

public class CollectionUtils extends Object
Miscellaneous collection utility methods. Mainly for internal use within the framework.
Since:
2.0.7
  • Method Details

    • sort

      public static <T> List<T> sort(List<T> list)
    • sortSimpleName

      public static List<String> sortSimpleName(List<String> list)
    • flip

      public static <K, V> Map<V,K> flip(Map<K,V> map)
      Flip the specified Map
      Type Parameters:
      K - The key type of specified Map
      V - The value type of specified Map
      Parameters:
      map - The specified Map,Its value must be unique
      Returns:
      Map
    • splitAll

      public static Map<String,Map<String,String>> splitAll(Map<String,List<String>> list, String separator)
    • joinAll

      public static Map<String,List<String>> joinAll(Map<String,Map<String,String>> map, String separator)
    • split

      public static Map<String,String> split(List<String> list, String separator)
    • join

      public static List<String> join(Map<String,String> map, String separator)
    • join

      public static String join(List<String> list, String separator)
    • mapEquals

      public static boolean mapEquals(Map<?,?> map1, Map<?,?> map2)
    • toStringMap

      public static Map<String,String> toStringMap(String... pairs)
    • toMap

      public static <K, V> Map<K,V> toMap(Object... pairs)
    • objToMap

      public static <K, V> Map<K,V> objToMap(Object object) throws IllegalAccessException
      Throws:
      IllegalAccessException
    • isEmpty

      public static boolean isEmpty(Collection<?> collection)
      Return true if the supplied Collection is null or empty. Otherwise, return false.
      Parameters:
      collection - the Collection to check
      Returns:
      whether the given Collection is empty
    • isNotEmpty

      public static boolean isNotEmpty(Collection<?> collection)
      Return true if the supplied Collection is not null or not empty. Otherwise, return false.
      Parameters:
      collection - the Collection to check
      Returns:
      whether the given Collection is not empty
    • isEmptyMap

      public static boolean isEmptyMap(Map map)
      Return true if the supplied Map is null or empty. Otherwise, return false.
      Parameters:
      map - the Map to check
      Returns:
      whether the given Map is empty
    • isNotEmptyMap

      public static boolean isNotEmptyMap(Map map)
      Return true if the supplied Map is not null or not empty. Otherwise, return false.
      Parameters:
      map - the Map to check
      Returns:
      whether the given Map is not empty
    • ofSet

      public static <T> Set<T> ofSet(T... values)
      Convert to multiple values to be LinkedHashSet
      Type Parameters:
      T - the type of values
      Parameters:
      values - one or more values
      Returns:
      read-only Set
    • size

      public static int size(Collection<?> collection)
      Get the size of the specified Collection
      Parameters:
      collection - the specified Collection
      Returns:
      must be positive number
      Since:
      2.7.6
    • equals

      public static boolean equals(Collection<?> one, Collection<?> another)
      Compares the specified collection with another, the main implementation references AbstractSet
      Parameters:
      one - Collection
      another - Collection
      Returns:
      if equals, return true, or false
      Since:
      2.7.6
    • addAll

      public static <T> int addAll(Collection<T> collection, T... values)
      Add the multiple values into the specified collection
      Type Parameters:
      T - the type of values
      Parameters:
      collection - the specified collection
      values - the multiple values
      Returns:
      the effected count after added
      Since:
      2.7.6
    • first

      public static <T> T first(Collection<T> values)
      Take the first element from the specified collection
      Type Parameters:
      T - the type of element of collection
      Parameters:
      values - the collection object
      Returns:
      if found, return the first one, or null
      Since:
      2.7.6
    • toTreeSet

      public static <T> Set<T> toTreeSet(Set<T> set)