Class CollectionHelper
java.lang.Object
org.hibernate.internal.util.collections.CollectionHelper
Various helper util methods for handling collections.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final float
static final int
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ArrayList<T>
arrayList
(int expectedNumberOfElements) static Properties
asProperties
(Map<?, ?> map) static <O> List<O>
static <O> List<O>
static List
combineUntyped
(List list1, List list2) static <K,
V> ConcurrentHashMap<K, V> concurrentMap
(int expectedNumberOfElements) Create a properly sizedConcurrentHashMap
based on the given expected number of elements.static <K,
V> ConcurrentHashMap<K, V> concurrentMap
(int expectedNumberOfElements, float loadFactor) Create a properly sizedConcurrentHashMap
based on the given expected number of elements and an explicit load factorstatic int
determineProperSizing
(int numberOfElements) Determine the proper initial size for a new collection in order for it to hold the given a number of elements.static int
determineProperSizing
(Map<?, ?> original) Given a map, determine the proper initial size for a new Map to hold the same number of values.static int
determineProperSizing
(Set<?> original) Given a set, determine the proper initial size for a new set to hold the same number of values.static boolean
static boolean
isEmpty
(Collection<?> collection) static boolean
static boolean
isNotEmpty
(Object[] objects) static boolean
isNotEmpty
(Collection<?> collection) static boolean
isNotEmpty
(Map<?, ?> map) static <K,
V> LinkedHashMap<K, V> Build a linked map whose size is unknown.static <K,
V> LinkedHashMap<K, V> linkedMapOfSize
(int size) Build a properly sized linked map, especially handling load size and load factor to prevent immediate resizing.static <K> LinkedHashSet<K>
Build a linked set whose size is unknown.static <K> LinkedHashSet<K>
linkedSetOfSize
(int size) Build a properly sized linked set, especially handling load size and load factor to prevent immediate resizing.static <T> List<T>
listOf
(T value1) static <T> List<T>
listOf
(T... values) static <K,
V> HashMap<K, V> static <X,
Y> Map<X, Y> static <T> Set<T>
static <K,
V, E> Map<K, V> makeMap
(Collection<E> collection, Function<E, K> keyProducer, Function<E, V> valueProducer) static <K,
V> Map<K, V> makeMap
(Collection<V> collection, Function<V, K> keyProducer) static <K,
V> HashMap<K, V> map()
Build a map whose size is unknown.static <K,
V> HashMap<K, V> mapOfSize
(int size) Build a properly sized map, especially handling load size and load factor to prevent immediate resizing.static <E> List<E>
mutableJoin
(Collection<E> first, Collection<E> second) static <E> List<E>
mutableJoin
(Collection<E> first, Collection<E>... others) static <T> ArrayList<T>
populatedArrayList
(int expectedNumberOfElements, T value) static <K> HashSet<K>
set()
Build a set whose size is unknown.static <T> Set<T>
setOf
(Collection<T> values) static <T> Set<T>
setOf
(T... values) static <K> HashSet<K>
setOfSize
(int size) Build a properly sized set, especially handling load size and load factor to prevent immediate resizing.static int
size
(Collection<?> values) static int
static int
static <X> Set<X>
toSet
(X... values) static <V> List<V>
toSmallList
(ArrayList<V> arrayList) Use to convert ArrayList instances which will be retained for a long time, such as for the lifetime of the Hibernate ORM instance.static <K,
V> Map<K, V> toSmallMap
(Map<K, V> map) Use to convert Maps which will be retained for a long time, such as for the lifetime of the Hibernate ORM instance.static <T> Set<T>
toSmallSet
(Set<T> set) Use to convert sets which will be retained for a long time, such as for the lifetime of the Hibernate ORM instance.
-
Field Details
-
DEFAULT_LIST_CAPACITY
public static final int DEFAULT_LIST_CAPACITY- See Also:
-
MINIMUM_INITIAL_CAPACITY
public static final int MINIMUM_INITIAL_CAPACITY- See Also:
-
LOAD_FACTOR
public static final float LOAD_FACTOR- See Also:
-
-
Method Details
-
mapOfSize
Build a properly sized map, especially handling load size and load factor to prevent immediate resizing.Especially helpful for copy map contents.
- Parameters:
size
- The size to make the map.- Returns:
- The sized map.
-
linkedMapOfSize
Build a properly sized linked map, especially handling load size and load factor to prevent immediate resizing.Especially helpful for copy map contents.
- Parameters:
size
- The size to make the map.- Returns:
- The sized linked map.
-
map
Build a map whose size is unknown.- Returns:
- The map.
-
linkedMap
Build a linked map whose size is unknown.- Returns:
- The linked map.
-
setOfSize
Build a properly sized set, especially handling load size and load factor to prevent immediate resizing.Especially helpful for copy set contents.
- Parameters:
size
- The size to make the set.- Returns:
- The sized set.
-
set
Build a set whose size is unknown.- Returns:
- The set.
-
linkedSetOfSize
Build a properly sized linked set, especially handling load size and load factor to prevent immediate resizing.Especially helpful for copy set contents.
- Parameters:
size
- The size to make the set.- Returns:
- The sized linked set.
-
linkedSet
Build a linked set whose size is unknown.- Returns:
- The linked set.
-
determineProperSizing
Given a map, determine the proper initial size for a new Map to hold the same number of values. Specifically we want to account for load size and load factor to prevent immediate resizing.- Parameters:
original
- The original map- Returns:
- The proper size.
-
makeCopy
-
makeCopy
-
makeMap
-
makeMap
public static <K,V, Map<K,E> V> makeMap(Collection<E> collection, Function<E, K> keyProducer, Function<E, V> valueProducer) -
determineProperSizing
Given a set, determine the proper initial size for a new set to hold the same number of values. Specifically we want to account for load size and load factor to prevent immediate resizing.- Parameters:
original
- The original set- Returns:
- The proper size.
-
determineProperSizing
public static int determineProperSizing(int numberOfElements) Determine the proper initial size for a new collection in order for it to hold the given a number of elements. Specifically we want to account for load size and load factor to prevent immediate resizing.- Parameters:
numberOfElements
- The number of elements to be stored.- Returns:
- The proper size.
-
concurrentMap
Create a properly sizedConcurrentHashMap
based on the given expected number of elements.- Type Parameters:
K
- The map key typeV
- The map value type- Parameters:
expectedNumberOfElements
- The expected number of elements for the created map- Returns:
- The created map.
-
concurrentMap
public static <K,V> ConcurrentHashMap<K,V> concurrentMap(int expectedNumberOfElements, float loadFactor) Create a properly sizedConcurrentHashMap
based on the given expected number of elements and an explicit load factor- Type Parameters:
K
- The map key typeV
- The map value type- Parameters:
expectedNumberOfElements
- The expected number of elements for the created maploadFactor
- The collection load factor- Returns:
- The created map.
-
arrayList
-
populatedArrayList
-
makeCopy
-
isEmpty
-
isEmpty
-
isNotEmpty
-
isNotEmpty
-
isEmpty
-
isNotEmpty
-
listOf
-
listOf
-
setOf
-
setOf
-
asProperties
-
toSmallSet
Use to convert sets which will be retained for a long time, such as for the lifetime of the Hibernate ORM instance. The returned Set might be immutable, but there is no guarantee of this: consider it immutable but don't rely on this. The goal is to save memory.- Returns:
- will never return null, but might return an immutable collection.
-
toSmallMap
Use to convert Maps which will be retained for a long time, such as for the lifetime of the Hibernate ORM instance. The returned Map might be immutable, but there is no guarantee of this: consider it immutable but don't rely on this. The goal is to save memory. -
toSmallList
Use to convert ArrayList instances which will be retained for a long time, such as for the lifetime of the Hibernate ORM instance. The returned List might be immutable, but there is no guarantee of this: consider it immutable but don't rely on this. The goal is to save memory. -
combine
-
combineUntyped
-
combine
-
size
-
size
-
size
-
toSet
-
mutableJoin
-
mutableJoin
-