类 CollectionUtils
- java.lang.Object
-
- com.github.aiosign.utils.CollectionUtils
-
public abstract class CollectionUtils extends java.lang.ObjectMiscellaneous collection utility methods. Mainly for internal use within the framework.- 从以下版本开始:
- 1.1.3
- 版本:
- $Id: $Id
- 作者:
- Juergen Hoeller, Rob Harrop, Arjen Poutsma
-
-
构造器概要
构造器 构造器 说明 CollectionUtils()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static java.util.ListarrayToList(java.lang.Object source)Convert the supplied array into a List.static booleancontains(java.util.Enumeration<?> enumeration, java.lang.Object element)Check whether the given Enumeration contains the given element.static booleancontains(java.util.Iterator<?> iterator, java.lang.Object element)Check whether the given Iterator contains the given element.static booleancontainsAny(java.util.Collection<?> source, java.util.Collection<?> candidates)Returntrueif any element in 'candidates' is contained in 'source'; otherwise returnsfalse.static booleancontainsInstance(java.util.Collection<?> collection, java.lang.Object element)Check whether the given Collection contains the given element instance.static java.lang.Class<?>findCommonElementType(java.util.Collection<?> collection)Find the common element type of the given Collection, if any.static <E> EfindFirstMatch(java.util.Collection<?> source, java.util.Collection<E> candidates)Return the first element in 'candidates' that is contained in 'source'.static java.lang.ObjectfindValueOfType(java.util.Collection<?> collection, java.lang.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.static <T> TfindValueOfType(java.util.Collection<?> collection, java.lang.Class<T> type)Find a single value of the given type in the given Collection.static booleanhasUniqueObject(java.util.Collection<?> collection)Determine whether the given Collection only contains a single unique object.static booleanisEmpty(java.util.Collection<?> collection)Returntrueif the supplied Collection isnullor empty.static booleanisEmpty(java.util.Map<?,?> map)Returntrueif the supplied Map isnullor empty.static <T> TlastElement(java.util.List<T> list)Retrieve the last element of the given List, accessing the highest index.static <T> TlastElement(java.util.Set<T> set)Retrieve the last element of the given Set, usingSortedSet.last()or otherwise iterating over all elements (assuming a linked set).static <E> voidmergeArrayIntoCollection(java.lang.Object array, java.util.Collection<E> collection)Merge the given array into the given Collection.static <K,V>
voidmergePropertiesIntoMap(java.util.Properties props, java.util.Map<K,V> map)Merge the given Properties instance into the given Map, copying all properties (key-value pairs) over.static <E> java.util.Iterator<E>toIterator(java.util.Enumeration<E> enumeration)Adapt anEnumerationto anIterator.
-
-
-
方法详细资料
-
isEmpty
public static boolean isEmpty(java.util.Collection<?> collection)
Returntrueif the supplied Collection isnullor empty. Otherwise, returnfalse.- 参数:
collection- the Collection to check- 返回:
- whether the given Collection is empty
-
isEmpty
public static boolean isEmpty(java.util.Map<?,?> map)
Returntrueif the supplied Map isnullor empty. Otherwise, returnfalse.- 参数:
map- the Map to check- 返回:
- whether the given Map is empty
-
arrayToList
public static java.util.List arrayToList(java.lang.Object source)
Convert the supplied array into a List. A primitive array gets converted into a List of the appropriate wrapper type.NOTE: Generally prefer the standard
Arrays.asList(T...)method. ThisarrayToListmethod is just meant to deal with an incoming Object value that might be anObject[]or a primitive array at runtime.A
nullsource value will be converted to an empty List.- 参数:
source- the (potentially primitive) array- 返回:
- the converted List result
- 另请参阅:
ObjectUtils.toObjectArray(Object),Arrays.asList(Object[])
-
mergeArrayIntoCollection
public static <E> void mergeArrayIntoCollection(java.lang.Object array, java.util.Collection<E> collection)Merge the given array into the given Collection.- 类型参数:
E- a E object.- 参数:
array- the array to merge (may benull)collection- the target Collection to merge the array into
-
mergePropertiesIntoMap
public static <K,V> void mergePropertiesIntoMap(java.util.Properties props, java.util.Map<K,V> 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.- 类型参数:
K- a K object.V- a V object.- 参数:
props- the Properties instance to merge (may benull)map- the target Map to merge the properties into
-
contains
public static boolean contains(java.util.Iterator<?> iterator, java.lang.Object element)Check whether the given Iterator contains the given element.- 参数:
iterator- the Iterator to checkelement- the element to look for- 返回:
trueif found,falseotherwise
-
contains
public static boolean contains(java.util.Enumeration<?> enumeration, java.lang.Object element)Check whether the given Enumeration contains the given element.- 参数:
enumeration- the Enumeration to checkelement- the element to look for- 返回:
trueif found,falseotherwise
-
containsInstance
public static boolean containsInstance(java.util.Collection<?> collection, java.lang.Object element)Check whether the given Collection contains the given element instance.Enforces the given instance to be present, rather than returning
truefor an equal element as well.- 参数:
collection- the Collection to checkelement- the element to look for- 返回:
trueif found,falseotherwise
-
containsAny
public static boolean containsAny(java.util.Collection<?> source, java.util.Collection<?> candidates)Returntrueif any element in 'candidates' is contained in 'source'; otherwise returnsfalse.- 参数:
source- the source Collectioncandidates- the candidates to search for- 返回:
- whether any of the candidates has been found
-
findFirstMatch
public static <E> E findFirstMatch(java.util.Collection<?> source, java.util.Collection<E> candidates)Return the first element in 'candidates' that is contained in 'source'. If no element in 'candidates' is present in 'source' returnsnull. Iteration order isCollectionimplementation specific.- 类型参数:
E- a E object.- 参数:
source- the source Collectioncandidates- the candidates to search for- 返回:
- the first present object, or
nullif not found
-
findValueOfType
public static <T> T findValueOfType(java.util.Collection<?> collection, java.lang.Class<T> type)Find a single value of the given type in the given Collection.- 类型参数:
T- a T object.- 参数:
collection- the Collection to searchtype- the type to look for- 返回:
- a value of the given type found if there is a clear match,
or
nullif none or more than one such value found
-
findValueOfType
public static java.lang.Object findValueOfType(java.util.Collection<?> collection, java.lang.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 searchtypes- the types to look for, in prioritized order- 返回:
- a value of one of the given types found if there is a clear match,
or
nullif none or more than one such value found
-
hasUniqueObject
public static boolean hasUniqueObject(java.util.Collection<?> collection)
Determine whether the given Collection only contains a single unique object.- 参数:
collection- the Collection to check- 返回:
trueif the collection contains a single reference or multiple references to the same instance,falseotherwise
-
findCommonElementType
public static java.lang.Class<?> findCommonElementType(java.util.Collection<?> collection)
Find the common element type of the given Collection, if any.- 参数:
collection- the Collection to check- 返回:
- the common element type, or
nullif no clear common type has been found (or the collection was empty)
-
lastElement
public static <T> T lastElement(java.util.Set<T> set)
Retrieve the last element of the given Set, usingSortedSet.last()or otherwise iterating over all elements (assuming a linked set).- 类型参数:
T- a T object.- 参数:
set- the Set to check (may benullor empty)- 返回:
- the last element, or
nullif none - 从以下版本开始:
- 5.0.3
- 另请参阅:
SortedSet,LinkedHashMap.keySet(),LinkedHashSet
-
lastElement
public static <T> T lastElement(java.util.List<T> list)
Retrieve the last element of the given List, accessing the highest index.- 类型参数:
T- a T object.- 参数:
list- the List to check (may benullor empty)- 返回:
- the last element, or
nullif none - 从以下版本开始:
- 5.0.3
-
toIterator
public static <E> java.util.Iterator<E> toIterator(java.util.Enumeration<E> enumeration)
Adapt anEnumerationto anIterator.- 类型参数:
E- a E object.- 参数:
enumeration- the originalEnumeration- 返回:
- the adapted
Iterator
-
-