Package org.apache.juneau.internal
Class CollectionUtils
java.lang.Object
org.apache.juneau.internal.CollectionUtils
Utility methods for collections.
 
See Also:
- 
Method SummaryModifier and TypeMethodDescriptionstatic <E> List<E>Adds all the specified values to the specified collection.static <E> List<E>Adds all the specified values to the specified collection.static <E> Set<E>Adds all the specified values to the specified collection.static <E> SortedSet<E>Adds all the specified values to the specified collection.static <E> Collection<E>copyOf(Collection<E> val) Creates a new collection from the specified collection.static <E> ArrayList<E>Convenience method for copying a list.static <E> List<E>Makes a deep copy of the specified list.static <E> List<E>Makes a deep copy of the specified list.static <K,V> Map<K, V> Creates a new map from the specified map.static <K,V> Map<K, V> Makes a deep copy of the specified map.static <K,V> Map<K, V> Makes a deep copy of the specified map.static <E> Set<E>Creates a new set from the specified collection.static <E> Set<E>Makes a deep copy of the specified list.static <E> Set<E>Makes a deep copy of the specified list.static <E> voidforEachReverse(E[] value, Consumer<E> action) Iterates the specified array in reverse order.static <E> voidforEachReverse(List<E> value, Consumer<E> action) Iterates the specified list in reverse order.static <E> Elast(E[] l) Returns the last entry in an array.static <E> EReturns the last entry in a list.static <E> ListBuilder<E>listBuilder(Class<E> elementType, Type... elementTypeArgs) Instantiates a new builder of the specified list type.static <E> ListBuilder<E>listBuilder(List<E> addTo) Instantiates a new builder on top of the specified list.static <E> ArrayList<E>listFrom(Collection<E> value) Creates anArrayListcopy from a collection.static <E> ArrayList<E>listFrom(Collection<E> value, boolean nullIfEmpty) Creates anArrayListcopy from a collection.static <E> List<E>Convenience method for creating anArrayList.static <K,V> LinkedHashMap<K, V> map()Convenience method for creating aLinkedHashMap.static <K,V> LinkedHashMap<K, V> map(K k1, V v1) Convenience method for creating aLinkedHashMap.static <K,V> LinkedHashMap<K, V> map(K k1, V v1, K k2, V v2) Convenience method for creating aLinkedHashMap.static <K,V> LinkedHashMap<K, V> map(K k1, V v1, K k2, V v2, K k3, V v3) Convenience method for creating aLinkedHashMap.static <K,V> MapBuilder<K, V> mapBuilder(Class<K> keyType, Class<V> valueType, Type... valueTypeArgs) Instantiates a new builder of the specified map type.static <K,V> MapBuilder<K, V> mapBuilder(Map<K, V> addTo) Instantiates a new builder on top of the specified map.static <K,V> LinkedHashMap<K, V> Creates anArrayListcopy from a collection.static <K,V> LinkedHashMap<K, V> Convenience method for creating aLinkedHashMap.static <E> List<E>prependAll(List<E> value, E... entries) Adds all the specified values to the specified collection.static <E> SetBuilder<E>setBuilder(Class<E> elementType, Type... elementTypeArgs) Instantiates a new builder of the specified set.static <E> SetBuilder<E>setBuilder(Set<E> addTo) Instantiates a new builder on top of the specified set.static <E> Set<E>setFrom(Collection<E> val) Creates a new set from the specified collection.static <E> LinkedHashSet<E>Convenience method for creating aLinkedHashSet.static <E> List<E>sortedList(E... values) Convenience method for creating anArrayListand sorting it.static <E> List<E>sortedList(Comparator<E> comparator, E[] values) Convenience method for creating anArrayListand sorting it.static <E> ArrayList<E>sortedList(Comparator<E> comparator, Collection<E> value) Convenience method for creating anArrayListand sorting it.static <K,V> TreeMap<K, V> Convenience method for creating aTreeMap.static <E> TreeSet<E>sortedSet(E... values) Convenience method for creating aTreeSet.static <E> TreeSet<E>sortedSetFrom(Collection<E> value) Creates a newTreeSetfrom the specified collection.static <E> TreeSet<E>sortedSetFrom(Collection<E> value, boolean nullIfEmpty) Creates a newTreeSetfrom the specified collection.static <E> List<E>Wraps the specified list inCollections.unmodifiableList(List).static <K,V> Map<K, V> Wraps the specified map inCollections.unmodifiableMap(Map).static <E> Set<E>Wraps the specified set inCollections.unmodifiableSet(Set).
- 
Method Details- 
setFromCreates a new set from the specified collection.- Type Parameters:
- E- The element type.
- Parameters:
- val- The value to copy from.
- Returns:
- A new LinkedHashSet, ornull if the input was null.
 
- 
copyOfCreates a new set from the specified collection.- Type Parameters:
- E- The element type.
- Parameters:
- val- The value to copy from.
- Returns:
- A new LinkedHashSet, ornull if the input was null.
 
- 
copyOfCreates a new collection from the specified collection.- Type Parameters:
- E- The element type.
- Parameters:
- val- The value to copy from.
- Returns:
- A new LinkedHashSet, ornull if the input was null.
 
- 
copyOfCreates a new map from the specified map.- Type Parameters:
- K- The key type.
- V- The value type.
- Parameters:
- val- The value to copy from.
- Returns:
- A new LinkedHashMap, ornull if the input was null.
 
- 
mapBuilderInstantiates a new builder on top of the specified map.- Type Parameters:
- K- The key type.
- V- The value type.
- Parameters:
- addTo- The map to add to.
- Returns:
- A new builder on top of the specified map.
 
- 
mapBuilderpublic static <K,V> MapBuilder<K,V> mapBuilder(Class<K> keyType, Class<V> valueType, Type... valueTypeArgs) Instantiates a new builder of the specified map type.- Type Parameters:
- K- The key type.
- V- The value type.
- Parameters:
- keyType- The key type.
- valueType- The value type.
- valueTypeArgs- The value type args.
- Returns:
- A new builder on top of the specified map.
 
- 
listBuilderInstantiates a new builder on top of the specified list.- Type Parameters:
- E- The element type.
- Parameters:
- addTo- The list to add to.
- Returns:
- A new builder on top of the specified list.
 
- 
listBuilderInstantiates a new builder of the specified list type.- Type Parameters:
- E- The element type.
- Parameters:
- elementType- The element type.
- elementTypeArgs- The element type args.
- Returns:
- A new builder on top of the specified list.
 
- 
setBuilderInstantiates a new builder on top of the specified set.- Type Parameters:
- E- The element type.
- Parameters:
- addTo- The set to add to.
- Returns:
- A new builder on top of the specified set.
 
- 
setBuilderInstantiates a new builder of the specified set.- Type Parameters:
- E- The element type.
- Parameters:
- elementType- The element type.
- elementTypeArgs- The element type args.
- Returns:
- A new builder on top of the specified set.
 
- 
listOfConvenience method for creating anArrayList.- Type Parameters:
- E- The element type.
- Parameters:
- elementType- The element type.
- values- The values to initialize the list with.
- Returns:
- A new modifiable list.
 
- 
listFromCreates anArrayListcopy from a collection.- Type Parameters:
- E- The element type.
- Parameters:
- value- The collection to copy from.
- Returns:
- A new modifiable list.
 
- 
mapFromCreates anArrayListcopy from a collection.- Type Parameters:
- K- The key type.
- V- The value type.
- Parameters:
- value- The collection to copy from.
- Returns:
- A new modifiable list.
 
- 
listFromCreates anArrayListcopy from a collection.- Type Parameters:
- E- The element type.
- Parameters:
- value- The collection to copy from.
- nullIfEmpty- If- true will return- null if the collection is empty.
- Returns:
- A new modifiable list.
 
- 
setOfConvenience method for creating aLinkedHashSet.- Type Parameters:
- E- The element type.
- Parameters:
- elementType- The element type.
- values- The values to initialize the set with.
- Returns:
- A new modifiable set.
 
- 
sortedSetConvenience method for creating aTreeSet.- Type Parameters:
- E- The element type.
- Parameters:
- values- The values to initialize the set with.
- Returns:
- A new modifiable set.
 
- 
sortedSetFromCreates a newTreeSetfrom the specified collection.- Type Parameters:
- E- The element type.
- Parameters:
- value- The value to copy from.
- Returns:
- A new TreeSet, ornull if the input was null.
 
- 
sortedSetFromCreates a newTreeSetfrom the specified collection.- Type Parameters:
- E- The element type.
- Parameters:
- value- The value to copy from.
- nullIfEmpty- If- true returns- null if the collection is empty.
- Returns:
- A new TreeSet, ornull if the input was null.
 
- 
mapConvenience method for creating aLinkedHashMap.- Type Parameters:
- K- The key type.
- V- The value type.
- Returns:
- A new modifiable map.
 
- 
mapOfConvenience method for creating aLinkedHashMap.- Type Parameters:
- K- The key type.
- V- The value type.
- Parameters:
- keyType- The key type.
- valueType- The value type.
- Returns:
- A new modifiable map.
 
- 
mapConvenience method for creating aLinkedHashMap.- Type Parameters:
- K- The key type.
- V- The value type.
- Parameters:
- k1- Key 1.
- v1- Value 1.
- Returns:
- A new modifiable map.
 
- 
mapConvenience method for creating aLinkedHashMap.- Type Parameters:
- K- The key type.
- V- The value type.
- Parameters:
- k1- Key 1.
- v1- Value 1.
- k2- Key 2.
- v2- Value 2.
- Returns:
- A new modifiable map.
 
- 
mapConvenience method for creating aLinkedHashMap.- Type Parameters:
- K- The key type.
- V- The value type.
- Parameters:
- k1- Key 1.
- v1- Value 1.
- k2- Key 2.
- v2- Value 2.
- k3- Key 3.
- v3- Value 3.
- Returns:
- A new modifiable map.
 
- 
sortedMapConvenience method for creating aTreeMap.- Type Parameters:
- K- The key type.
- V- The value type.
- Returns:
- A new modifiable set.
 
- 
copyOfConvenience method for copying a list.- Type Parameters:
- E- The element type.
- Parameters:
- value- The list to copy.
- Returns:
- A new modifiable list.
 
- 
sortedListConvenience method for creating anArrayListand sorting it.- Type Parameters:
- E- The element type.
- Parameters:
- values- The values to initialize the list with.
- Returns:
- A new modifiable list.
 
- 
sortedListConvenience method for creating anArrayListand sorting it.- Type Parameters:
- E- The element type.
- Parameters:
- comparator- The comparator to use to sort the list.
- values- The values to initialize the list with.
- Returns:
- A new modifiable list.
 
- 
sortedListConvenience method for creating anArrayListand sorting it.- Type Parameters:
- E- The element type.
- Parameters:
- comparator- The comparator to use to sort the list.
- value- The values to initialize the list with.
- Returns:
- A new modifiable list.
 
- 
syncedWraps the specified list inCollections.unmodifiableList(List).- Type Parameters:
- E- The element type.
- Parameters:
- value- The list to wrap.
- Returns:
- The wrapped list.
 
- 
syncedWraps the specified set inCollections.unmodifiableSet(Set).- Type Parameters:
- E- The element type.
- Parameters:
- value- The set to wrap.
- Returns:
- The wrapped set.
 
- 
syncedWraps the specified map inCollections.unmodifiableMap(Map).- Type Parameters:
- K- The key type.
- V- The value type.
- Parameters:
- value- The map to wrap.
- Returns:
- The wrapped map.
 
- 
forEachReverseIterates the specified list in reverse order.- Type Parameters:
- E- The element type.
- Parameters:
- value- The list to iterate.
- action- The action to perform.
 
- 
forEachReverseIterates the specified array in reverse order.- Type Parameters:
- E- The element type.
- Parameters:
- value- The array to iterate.
- action- The action to perform.
 
- 
addAllAdds all the specified values to the specified collection. Creates a new set if the value isnull .- Type Parameters:
- E- The element type.
- Parameters:
- value- The collection to add to.
- entries- The entries to add.
- Returns:
- The set.
 
- 
addAllAdds all the specified values to the specified collection. Creates a new set if the value isnull .- Type Parameters:
- E- The element type.
- Parameters:
- value- The collection to add to.
- entries- The entries to add.
- Returns:
- The set.
 
- 
addAllAdds all the specified values to the specified collection. Creates a new set if the value isnull .- Type Parameters:
- E- The element type.
- Parameters:
- value- The collection to add to.
- entries- The entries to add.
- Returns:
- The set.
 
- 
addAllAdds all the specified values to the specified collection. Creates a new set if the value isnull .- Type Parameters:
- E- The element type.
- Parameters:
- value- The collection to add to.
- entries- The entries to add.
- Returns:
- The set.
 
- 
prependAllAdds all the specified values to the specified collection. Creates a new set if the value isnull .- Type Parameters:
- E- The element type.
- Parameters:
- value- The collection to add to.
- entries- The entries to add.
- Returns:
- The set.
 
- 
lastReturns the last entry in a list.- Type Parameters:
- E- The element type.
- Parameters:
- l- The list.
- Returns:
- The last element, or null if the list isnull or empty.
 
- 
lastReturns the last entry in an array.- Type Parameters:
- E- The element type.
- Parameters:
- l- The array.
- Returns:
- The last element, or null if the array isnull or empty.
 
- 
copyOfMakes a deep copy of the specified map.- Type Parameters:
- K- The key type.
- V- The value type.
- Parameters:
- m- The map to copy.
- valueMapper- The function to apply to each value in the map.
- Returns:
- A new map with the same keys as the specified map, but with values transformed by the specified function. Null if the map being copied was null.
 
- 
copyOfpublic static <K,V> Map<K,V> copyOf(Map<K, V> m, Function<? super V, ? extends V> valueMapper, Supplier<Map<K, V>> mapFactory) Makes a deep copy of the specified map.- Type Parameters:
- K- The key type.
- V- The value type.
- Parameters:
- m- The map to copy.
- valueMapper- The function to apply to each value in the map.
- mapFactory- The factory for creating the map.
- Returns:
- A new map with the same keys as the specified map, but with values transformed by the specified function. Null if the map being copied was null.
 
- 
copyOfMakes a deep copy of the specified list.- Type Parameters:
- E- The entry type.
- Parameters:
- l- The list to copy.
- valueMapper- The function to apply to each value in the list.
- Returns:
- A new list with the same values as the specified list, but with values transformed by the specified function. Null if the list being copied was null.
 
- 
copyOfpublic static <E> List<E> copyOf(List<E> l, Function<? super E, ? extends E> valueMapper, Supplier<List<E>> listFactory) Makes a deep copy of the specified list.- Type Parameters:
- E- The entry type.
- Parameters:
- l- The list to copy.
- valueMapper- The function to apply to each value in the list.
- listFactory- The factory for creating the list.
- Returns:
- A new list with the same values as the specified list, but with values transformed by the specified function. Null if the list being copied was null.
 
- 
copyOfMakes a deep copy of the specified list.- Type Parameters:
- E- The entry type.
- Parameters:
- l- The list to copy.
- valueMapper- The function to apply to each value in the list.
- Returns:
- A new list with the same values as the specified list, but with values transformed by the specified function. Null if the list being copied was null.
 
- 
copyOfpublic static <E> Set<E> copyOf(Set<E> l, Function<? super E, ? extends E> valueMapper, Supplier<Set<E>> setFactory) Makes a deep copy of the specified list.- Type Parameters:
- E- The entry type.
- Parameters:
- l- The list to copy.
- valueMapper- The function to apply to each value in the list.
- setFactory- The factory for creating sets.
- Returns:
- A new list with the same values as the specified list, but with values transformed by the specified function. Null if the list being copied was null.
 
 
-