Top Description Fields Constructors Methods
org.hibernate.internal.util.collections

public final Class CollectionHelper

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Collection, .Collections, .HashMap, .HashSet, .List, .Map, .Set, java.util.concurrent.ConcurrentHashMap, java.util.function.Function

Various help for handling collections.
Authors
Gavin King, Steve Ebersole

Field Summary

Modifier and TypeField and Description
public static final Collection<E>
public static final List<E>
public static final Map<K, V>
public static final float
public static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <T> ArrayList<T>
arrayList(int anticipatedSize)

public static <
The map key type
K
,
The map value type
V
>
ConcurrentHashMap<K, V>

Returns:

The created map.
concurrentMap
(int
The expected number of elements for the created map
expectedNumberOfElements
)

Create a properly sized ConcurrentHashMap based on the given expected number of elements.

public static <
The map key type
K
,
The map value type
V
>
ConcurrentHashMap<K, V>

Returns:

The created map.
concurrentMap
(int
The expected number of elements for the created map
expectedNumberOfElements
,
float
The collection load factor
loadFactor
)

Create a properly sized ConcurrentHashMap based on the given expected number of elements and an explicit load factor

public static int

Returns:

The proper size.
determineProperSizing
(Map<K, V>
The original map
original
)

Given a map, determine the proper initial size for a new Map to hold the same number of values.

public static int

Returns:

The proper size.
determineProperSizing
(Set<E>
The original set
original
)

Given a set, determine the proper initial size for a new set to hold the same number of values.

public static int

Returns:

The proper size.
determineProperSizing
(int
The number of elements to be stored.
numberOfElements
)

Determine the proper initial size for a new collection in order for it to hold the given a number of elements.

public static boolean
isEmpty(Collection<E> collection)

public static boolean
isEmpty(Map<K, V> map)

public static boolean
isEmpty(Object[] objects)

public static boolean
isNotEmpty(Collection<E> collection)

public static boolean
isNotEmpty(Map<K, V> map)

public static <X, Y> Map<X, Y>
makeCopy(Map<X, Y> map)

public static <K, V> HashMap<K, V>
makeCopy(Map<K, V> original, Function<K, K> keyTransformer, Function<V, V> valueTransformer)

public static <T> Set<T>
makeCopy(Set<T> source)

public static <K, V> Map<K, V>
makeMap(Collection<V> collection, Function<V, K> keyProducer)

public static <K, V, E> Map<K, V>
makeMap(Collection<E> collection, Function<E, K> keyProducer, Function<E, V> valueProducer)

public static <K, V> Map<K, V>

Returns:

The sized map.
mapOfSize
(int
The size to make the map.
size
)

Build a properly sized map, especially handling load size and load factor to prevent immediate resizing.

public 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.

public static <K, V> Map<K, V>
toSmallMap(final 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.

public static <T> Set<T>

Returns:

will never return null, but might return an immutable collection.
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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTY_COLLECTIONback to summary
public static final Collection<E> EMPTY_COLLECTION
Annotations
@Deprecated
EMPTY_LISTback to summary
public static final List<E> EMPTY_LIST
Annotations
@Deprecated
EMPTY_MAPback to summary
public static final Map<K, V> EMPTY_MAP
Annotations
@Deprecated
LOAD_FACTORback to summary
public static final float LOAD_FACTOR
MINIMUM_INITIAL_CAPACITYback to summary
public static final int MINIMUM_INITIAL_CAPACITY

Constructor Detail

CollectionHelperback to summary
private CollectionHelper()

Method Detail

arrayListback to summary
public static <T> ArrayList<T> arrayList(int anticipatedSize)
concurrentMapback to summary
public static <K, V> ConcurrentHashMap<K, V> concurrentMap(int expectedNumberOfElements)

Create a properly sized ConcurrentHashMap based on the given expected number of elements.

Parameters
<K>
The map key type
<V>
The map value type
expectedNumberOfElements:int

The expected number of elements for the created map

Returns:ConcurrentHashMap<K, V>

The created map.

concurrentMapback to summary
public static <K, V> ConcurrentHashMap<K, V> concurrentMap(int expectedNumberOfElements, float loadFactor)

Create a properly sized ConcurrentHashMap based on the given expected number of elements and an explicit load factor

Parameters
<K>
The map key type
<V>
The map value type
expectedNumberOfElements:int

The expected number of elements for the created map

loadFactor:float

The collection load factor

Returns:ConcurrentHashMap<K, V>

The created map.

determineProperSizingback to summary
public static int determineProperSizing(Map<K, V> original)

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:Map<K, V>

The original map

Returns:int

The proper size.

determineProperSizingback to summary
public static int determineProperSizing(Set<E> original)

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:Set<E>

The original set

Returns:int

The proper size.

determineProperSizingback to summary
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:int

The number of elements to be stored.

Returns:int

The proper size.

isEmptyback to summary
public static boolean isEmpty(Collection<E> collection)
isEmptyback to summary
public static boolean isEmpty(Map<K, V> map)
isEmptyback to summary
public static boolean isEmpty(Object[] objects)
isNotEmptyback to summary
public static boolean isNotEmpty(Collection<E> collection)
isNotEmptyback to summary
public static boolean isNotEmpty(Map<K, V> map)
makeCopyback to summary
public static <X, Y> Map<X, Y> makeCopy(Map<X, Y> map)
makeCopyback to summary
public static <K, V> HashMap<K, V> makeCopy(Map<K, V> original, Function<K, K> keyTransformer, Function<V, V> valueTransformer)
makeCopyback to summary
public static <T> Set<T> makeCopy(Set<T> source)
makeMapback to summary
public static <K, V> Map<K, V> makeMap(Collection<V> collection, Function<V, K> keyProducer)
makeMapback to summary
public static <K, V, E> Map<K, V> makeMap(Collection<E> collection, Function<E, K> keyProducer, Function<E, V> valueProducer)
mapOfSizeback to summary
public static <K, V> Map<K, V> mapOfSize(int size)

Build a properly sized map, especially handling load size and load factor to prevent immediate resizing.

Especially helpful for copy map contents.

Parameters
size:int

The size to make the map.

Returns:Map<K, V>

The sized map.

toSmallListback to summary
public 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. 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.

toSmallMapback to summary
public static <K, V> Map<K, V> toSmallMap(final 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. 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.

toSmallSetback to summary
public 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. 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:Set<T>

will never return null, but might return an immutable collection.