集合工具类

类名:CollectionUtil

isNotEmpty

/**
 * Return {@code true} if the supplied Collection is not {@code null} or empty.
 * Otherwise, return {@code false}.
 *
 * @param collection the Collection to check
 * @return whether the given Collection is not empty
 */
CollectionUtil.isNotEmpty(Collection<?> collection);

isNotEmpty

/**
 * Return {@code true} if the supplied Map is not {@code null} or empty.
 * Otherwise, return {@code false}.
 *
 * @param map the Map to check
 * @return whether the given Map is not empty
 */
CollectionUtil.isNotEmpty(Map<?,?> map);

contains

/**
 * Check whether the given Array contains the given element.
 *
 * @param array   the Array to check
 * @param element the element to look for
 * @param <T>     The generic tag
 * @return {@code true} if found, {@code false} else
 */
CollectionUtil.contains(T[] array, T element);

concat

/**
 * Concatenates 2 arrays
 *
 * @param one   数组1
 * @param other 数组2
 * @return 新数组
 */
CollectionUtil.concat(String[] one, String[] other);

concat

/**
 * Concatenates 2 arrays
 *
 * @param one   数组1
 * @param other 数组2
 * @param clazz 数组类
 * @return 新数组
 */
CollectionUtil.concat(T[] one, T[] other, Class<T> clazz);

isArray

/**
 * 对象是否为数组对象
 *
 * @param obj 对象
 * @return 是否为数组对象,如果为{@code null} 返回false
 */
CollectionUtil.isArray(Object obj);

ofImmutableSet

/**
 * 不可变 Set
 *
 * @param es  对象
 * @param <E> 泛型
 * @return 集合
 */
CollectionUtil.ofImmutableSet(E es);

ofImmutableList

/**
 * 不可变 List
 *
 * @param es  对象
 * @param <E> 泛型
 * @return 集合
 */
CollectionUtil.ofImmutableList(E es);

toList

/**
 * Iterable 转换为List集合
 *
 * @param elements Iterable
 * @param <E>      泛型
 * @return 集合
 */
CollectionUtil.toList(Iterable<E> elements);

toMap

/**
 * 将key value 数组转为 map
 *
 * @param keysValues key value 数组
 * @param <K>        key
 * @param <V>        value
 * @return map 集合
 */
CollectionUtil.toMap(Object keysValues);

isEmpty

/**
 * Return {@code true} if the supplied Collection is {@code null} or empty.
 * Otherwise, return {@code false}.
 * @param collection the Collection to check
 * @return whether the given Collection is empty
 */
CollectionUtil.isEmpty(Collection<?> collection);

isEmpty

/**
 * Return {@code true} if the supplied Map is {@code null} or empty.
 * Otherwise, return {@code false}.
 * @param map the Map to check
 * @return whether the given Map is empty
 */
CollectionUtil.isEmpty(Map<?,?> map);

arrayToList

/**
 * Convert the supplied array into a List. A primitive array gets converted
 * into a List of the appropriate wrapper type.
 * <p><b>NOTE:</b> Generally prefer the standard {@link Arrays#asList} method.
 * This {@code arrayToList} method is just meant to deal with an incoming Object
 * value that might be an {@code Object[]} or a primitive array at runtime.
 * <p>A {@code null} source value will be converted to an empty List.
 * @param source the (potentially primitive) array
 * @return the converted List result
 * @see ObjectUtils#toObjectArray(Object)
 * @see Arrays#asList(Object[])
 */
CollectionUtil.arrayToList(Object source);

mergeArrayIntoCollection

/**
 * Merge the given array into the given Collection.
 * @param array the array to merge (may be {@code null})
 * @param collection the target Collection to merge the array into
 */
CollectionUtil.mergeArrayIntoCollection(Object array, Collection<E> collection);

mergePropertiesIntoMap

/**
 * Merge the given Properties instance into the given Map,
 * copying all properties (key-value pairs) over.
 * <p>Uses {@code Properties.propertyNames()} to even catch
 * default properties linked into the original Properties instance.
 * @param props the Properties instance to merge (may be {@code null})
 * @param map the target Map to merge the properties into
 */
CollectionUtil.mergePropertiesIntoMap(Properties props, Map<K,V> map);

contains

/**
 * Check whether the given Iterator contains the given element.
 * @param iterator the Iterator to check
 * @param element the element to look for
 * @return {@code true} if found, {@code false} otherwise
 */
CollectionUtil.contains(Iterator<?> iterator, Object element);

contains

/**
 * Check whether the given Enumeration contains the given element.
 * @param enumeration the Enumeration to check
 * @param element the element to look for
 * @return {@code true} if found, {@code false} otherwise
 */
CollectionUtil.contains(Enumeration<?> enumeration, Object element);

containsInstance

/**
 * Check whether the given Collection contains the given element instance.
 * <p>Enforces the given instance to be present, rather than returning
 * {@code true} for an equal element as well.
 * @param collection the Collection to check
 * @param element the element to look for
 * @return {@code true} if found, {@code false} otherwise
 */
CollectionUtil.containsInstance(Collection<?> collection, Object element);

containsAny

/**
 * Return {@code true} if any element in '{@code candidates}' is
 * contained in '{@code source}'; otherwise returns {@code false}.
 * @param source the source Collection
 * @param candidates the candidates to search for
 * @return whether any of the candidates has been found
 */
CollectionUtil.containsAny(Collection<?> source, Collection<?> candidates);

findFirstMatch

/**
 * Return the first element in '{@code candidates}' that is contained in
 * '{@code source}'. If no element in '{@code candidates}' is present in
 * '{@code source}' returns {@code null}. Iteration order is
 * {@link Collection} implementation specific.
 * @param source the source Collection
 * @param candidates the candidates to search for
 * @return the first present object, or {@code null} if not found
 */
CollectionUtil.findFirstMatch(Collection<?> source, Collection<E> candidates);

findValueOfType

/**
 * Find a single value of the given type in the given Collection.
 * @param collection the Collection to search
 * @param type the type to look for
 * @return a value of the given type found if there is a clear match,
 * or {@code null} if none or more than one such value found
 */
CollectionUtil.findValueOfType(Collection<?> collection, Class<T> type);

findValueOfType

/**
 * 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.
 * @param collection the collection to search
 * @param types the types to look for, in prioritized order
 * @return a value of one of the given types found if there is a clear match,
 * or {@code null} if none or more than one such value found
 */
CollectionUtil.findValueOfType(Collection<?> collection, Class<?>[] types);

hasUniqueObject

/**
 * Determine whether the given Collection only contains a single unique object.
 * @param collection the Collection to check
 * @return {@code true} if the collection contains a single reference or
 * multiple references to the same instance, {@code false} otherwise
 */
CollectionUtil.hasUniqueObject(Collection<?> collection);

findCommonElementType

/**
 * Find the common element type of the given Collection, if any.
 * @param collection the Collection to check
 * @return the common element type, or {@code null} if no clear
 * common type has been found (or the collection was empty)
 */
CollectionUtil.findCommonElementType(Collection<?> collection);

lastElement

/**
 * Retrieve the last element of the given Set, using {@link SortedSet#last()}
 * or otherwise iterating over all elements (assuming a linked set).
 * @param set the Set to check (may be {@code null} or empty)
 * @return the last element, or {@code null} if none
 * @since 5.0.3
 * @see SortedSet
 * @see LinkedHashMap#keySet()
 * @see java.util.LinkedHashSet
 */
CollectionUtil.lastElement(Set<T> set);

lastElement

/**
 * Retrieve the last element of the given List, accessing the highest index.
 * @param list the List to check (may be {@code null} or empty)
 * @return the last element, or {@code null} if none
 * @since 5.0.3
 */
CollectionUtil.lastElement(List<T> list);

toArray

/**
 * Marshal the elements from the given enumeration into an array of the given type.
 * Enumeration elements must be assignable to the type of the given array. The array
 * returned will be a different instance than the array given.
 */
CollectionUtil.toArray(Enumeration<E> enumeration, A[] array);

toIterator

/**
 * Adapt an {@link Enumeration} to an {@link Iterator}.
 * @param enumeration the original {@code Enumeration}
 * @return the adapted {@code Iterator}
 */
CollectionUtil.toIterator(Enumeration<E> enumeration);

toMultiValueMap

/**
 * Adapt a {@code Map<K, List<V>>} to an {@code MultiValueMap<K, V>}.
 * @param map the original map
 * @return the multi-value map
 * @since 3.1
 */
CollectionUtil.toMultiValueMap(Map<K,List<V>> map);

unmodifiableMultiValueMap

/**
 * Return an unmodifiable view of the specified multi-value map.
 * @param  map the map for which an unmodifiable view is to be returned.
 * @return an unmodifiable view of the specified multi-value map.
 * @since 3.1
 */
CollectionUtil.unmodifiableMultiValueMap(MultiValueMap<? extends K,? extends V> map);

hasNext

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.hasNext();

next

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.next();

remove

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.remove();

getFirst

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.getFirst(K key);

add

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.add(K key, V value);

addAll

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.addAll(K key, List<? extends V> values);

addAll

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.addAll(MultiValueMap<K,V> values);

set

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.set(K key, V value);

setAll

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.setAll(Map<K,V> values);

toSingleValueMap

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.toSingleValueMap();

size

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.size();

isEmpty

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.isEmpty();

containsKey

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.containsKey(Object key);

containsValue

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.containsValue(Object value);

get

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.get(Object key);

put

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.put(K key, List<V> value);

remove

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.remove(Object key);

putAll

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.putAll(Map<? extends K,? extends List<V>> map);

clear

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.clear();

keySet

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.keySet();

values

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.values();

entrySet

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.entrySet();

equals

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.equals(Object other);

hashCode

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.hashCode();

toString

/**
 */
CollectionUtil collectionUtil = new CollectionUtil();
collectionUtil.toString();