类 CollectionUtils

java.lang.Object
com.walker.infrastructure.utils.CollectionUtils

public abstract class CollectionUtils extends Object
Miscellaneous collection utility methods. Mainly for internal use within the framework.
从以下版本开始:
1.1.3
作者:
Juergen Hoeller, Rob Harrop, 时克英
  • 构造器详细资料

    • CollectionUtils

      public CollectionUtils()
  • 方法详细资料

    • shuffleLittle

      public static void shuffleLittle(List<?> data, int weight)
      小规模抖动,
      参数:
      data - 原始集合
      weight - 权重,0-100,数值越大抖动越多
    • shuffle

      public static void shuffle(List<?> data)
    • isEmpty

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

      public static boolean isEmpty(Map<?,?> map)
      Return true if the supplied Map is null or empty. Otherwise, return false.
      参数:
      map - the Map to check
      返回:
      whether the given Map is empty
    • arrayToList

      public static List arrayToList(Object source)
      Convert the supplied array into a List. A primitive array gets converted into a List of the appropriate wrapper type.

      A null source value will be converted to an empty List.

      参数:
      source - the (potentially primitive) array
      返回:
      the converted List result
      另请参阅:
    • mergeArrayIntoCollection

      public static void mergeArrayIntoCollection(Object array, Collection collection)
      Merge the given array into the given Collection.
      参数:
      array - the array to merge (may be null)
      collection - the target Collection to merge the array into
    • mergePropertiesIntoMap

      public static void mergePropertiesIntoMap(Properties props, Map map)
      Merge the given Properties instance into the given Map, copying all properties (key-value pairs) over.

      Uses Properties.propertyNames() to even catch default properties linked into the original Properties instance.

      参数:
      props - the Properties instance to merge (may be null)
      map - the target Map to merge the properties into
    • contains

      public static boolean contains(Iterator iterator, Object element)
      Check whether the given Iterator contains the given element.
      参数:
      iterator - the Iterator to check
      element - the element to look for
      返回:
      true if found, false else
    • contains

      public static boolean contains(Enumeration enumeration, Object element)
      Check whether the given Enumeration contains the given element.
      参数:
      enumeration - the Enumeration to check
      element - the element to look for
      返回:
      true if found, false else
    • containsInstance

      public static boolean containsInstance(Collection collection, Object element)
      Check whether the given Collection contains the given element instance.

      Enforces the given instance to be present, rather than returning true for an equal element as well.

      参数:
      collection - the Collection to check
      element - the element to look for
      返回:
      true if found, false else
    • containsAny

      public static boolean containsAny(Collection source, Collection candidates)
      Return true if any element in 'candidates' is contained in 'source'; otherwise returns false.
      参数:
      source - the source Collection
      candidates - the candidates to search for
      返回:
      whether any of the candidates has been found
    • findFirstMatch

      public static Object findFirstMatch(Collection source, Collection candidates)
      Return the first element in 'candidates' that is contained in 'source'. If no element in 'candidates' is present in 'source' returns null. Iteration order is Collection implementation specific.
      参数:
      source - the source Collection
      candidates - the candidates to search for
      返回:
      the first present object, or null if not found
    • findValueOfType

      public static <T> T findValueOfType(Collection<?> collection, Class<T> type)
      Find a single value of the given type in the given Collection.
      参数:
      collection - the Collection to search
      type - the type to look for
      返回:
      a value of the given type found if there is a clear match, or null if none or more than one such value found
    • findValueOfType

      public static Object findValueOfType(Collection<?> collection, Class<?>[] types)
      Find a single value of one of the given types in the given Collection: searching the Collection for a value of the first type, then searching for a value of the second type, etc.
      参数:
      collection - the collection to search
      types - the types to look for, in prioritized order
      返回:
      a value of one of the given types found if there is a clear match, or null if none or more than one such value found
    • hasUniqueObject

      public static boolean hasUniqueObject(Collection collection)
      Determine whether the given Collection only contains a single unique object.
      参数:
      collection - the Collection to check
      返回:
      true if the collection contains a single reference or multiple references to the same instance, false else
    • findCommonElementType

      public static Class<?> findCommonElementType(Collection collection)
      Find the common element type of the given Collection, if any.
      参数:
      collection - the Collection to check
      返回:
      the common element type, or null if no clear common type has been found (or the collection was empty)
    • toIterator

      public static <E> Iterator<E> toIterator(Enumeration<E> enumeration)
      Adapts an enumeration to an iterator.
      参数:
      enumeration - the enumeration
      返回:
      the iterator