Package org.apache.juneau.internal
Class CollectionUtils
java.lang.Object
org.apache.juneau.internal.CollectionUtils
Utility methods for collections.
See Also:
-
Method Summary
Modifier 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> void
forEachReverse
(E[] value, Consumer<E> action) Iterates the specified array in reverse order.static <E> void
forEachReverse
(List<E> value, Consumer<E> action) Iterates the specified list in reverse order.static <E> E
last
(E[] l) Returns the last entry in an array.static <E> E
Returns 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 anArrayList
copy from a collection.static <E> ArrayList<E>
listFrom
(Collection<E> value, boolean nullIfEmpty) Creates anArrayList
copy 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 anArrayList
copy 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 anArrayList
and sorting it.static <E> List<E>
sortedList
(Comparator<E> comparator, E[] values) Convenience method for creating anArrayList
and sorting it.static <E> ArrayList<E>
sortedList
(Comparator<E> comparator, Collection<E> value) Convenience method for creating anArrayList
and 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 newTreeSet
from the specified collection.static <E> TreeSet<E>
sortedSetFrom
(Collection<E> value, boolean nullIfEmpty) Creates a newTreeSet
from 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
-
setFrom
Creates 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.
-
copyOf
Creates 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.
-
copyOf
Creates 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.
-
copyOf
Creates 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.
-
mapBuilder
Instantiates 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.
-
mapBuilder
public 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.
-
listBuilder
Instantiates 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.
-
listBuilder
Instantiates 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.
-
setBuilder
Instantiates 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.
-
setBuilder
Instantiates 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.
-
listOf
Convenience 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.
-
listFrom
Creates anArrayList
copy from a collection.- Type Parameters:
E
- The element type.- Parameters:
value
- The collection to copy from.- Returns:
- A new modifiable list.
-
mapFrom
Creates anArrayList
copy 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.
-
listFrom
Creates anArrayList
copy from a collection.- Type Parameters:
E
- The element type.- Parameters:
value
- The collection to copy from.nullIfEmpty
- Iftrue will returnnull if the collection is empty.- Returns:
- A new modifiable list.
-
setOf
Convenience 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.
-
sortedSet
Convenience method for creating aTreeSet
.- Type Parameters:
E
- The element type.- Parameters:
values
- The values to initialize the set with.- Returns:
- A new modifiable set.
-
sortedSetFrom
Creates a newTreeSet
from 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.
-
sortedSetFrom
Creates a newTreeSet
from the specified collection.- Type Parameters:
E
- The element type.- Parameters:
value
- The value to copy from.nullIfEmpty
- Iftrue returnsnull if the collection is empty.- Returns:
- A new
TreeSet
, ornull if the input was null.
-
map
Convenience method for creating aLinkedHashMap
.- Type Parameters:
K
- The key type.V
- The value type.- Returns:
- A new modifiable map.
-
mapOf
Convenience 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.
-
map
Convenience 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.
-
map
Convenience 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.
-
map
Convenience 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.
-
sortedMap
Convenience method for creating aTreeMap
.- Type Parameters:
K
- The key type.V
- The value type.- Returns:
- A new modifiable set.
-
copyOf
Convenience method for copying a list.- Type Parameters:
E
- The element type.- Parameters:
value
- The list to copy.- Returns:
- A new modifiable list.
-
sortedList
Convenience method for creating anArrayList
and sorting it.- Type Parameters:
E
- The element type.- Parameters:
values
- The values to initialize the list with.- Returns:
- A new modifiable list.
-
sortedList
Convenience method for creating anArrayList
and 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.
-
sortedList
Convenience method for creating anArrayList
and 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.
-
synced
Wraps the specified list inCollections.unmodifiableList(List)
.- Type Parameters:
E
- The element type.- Parameters:
value
- The list to wrap.- Returns:
- The wrapped list.
-
synced
Wraps the specified set inCollections.unmodifiableSet(Set)
.- Type Parameters:
E
- The element type.- Parameters:
value
- The set to wrap.- Returns:
- The wrapped set.
-
synced
Wraps 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.
-
forEachReverse
Iterates the specified list in reverse order.- Type Parameters:
E
- The element type.- Parameters:
value
- The list to iterate.action
- The action to perform.
-
forEachReverse
Iterates the specified array in reverse order.- Type Parameters:
E
- The element type.- Parameters:
value
- The array to iterate.action
- The action to perform.
-
addAll
Adds 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.
-
addAll
Adds 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.
-
addAll
Adds 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.
-
addAll
Adds 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.
-
prependAll
Adds 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.
-
last
Returns 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.
-
last
Returns 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.
-
copyOf
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.- 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.
-
copyOf
public 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.
-
copyOf
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.- 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.
-
copyOf
public 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.
-
copyOf
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.- 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.
-
copyOf
public 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.
-