Top Description Inners Constructors Methods
org.hibernate.validator.internal.util

public final Class CollectionHelper

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Arrays, .Collection, .Collections, .HashMap, .HashSet, .Iterator, .List, .Map, .Map.Entry, .Set, .LinkedHashSet, java.util.concurrent.ConcurrentHashMap

Provides some methods for simplified collection instantiation.
Authors
Gunnar Morling, Kevin Pollet <[email protected]> (C) 2011 SERLI, Hardy Ferentschik, Guillaume Smet

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface
private static class
private static class

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static CollectionHelper.ArrayAccessor<?, ?>
public static <T> Set<T>
asSet(T... ts)

private static int

Returns:

the initial capacity of the collection
getInitialCapacityFromExpectedSize
(int
the expected size of the collection
expectedSize
)

As the default loadFactor is of 0.75, we need to calculate the initial capacity from the expected size to avoid resizing the collection when we populate the collection with all the initial elements.

public static Iterable<?>

Returns:

an Iterable providing iterators over the array
iterableFromArray
(Object
a given array
object
)

Builds an Iterable for a given array.

public static Iterator<?>

Returns:

an Iterator iterating over the array
iteratorFromArray
(Object
a given array
object
)

Builds an Iterator for a given array.

public static <T> ArrayList<T>
public static <T> ArrayList<T>
newArrayList(int size)

public static <T> ArrayList<T>
newArrayList(Iterable<T>... iterables)

public static <K, V> ConcurrentHashMap<K, V>
public static <K, V> HashMap<K, V>
public static <K, V> HashMap<K, V>
newHashMap(int size)

public static <K, V> HashMap<K, V>
newHashMap(Map<K, V> map)

public static <T> HashSet<T>
public static <T> HashSet<T>
newHashSet(int size)

public static <T> HashSet<T>
newHashSet(Collection<? extends T> c)

public static <T> HashSet<T>
newHashSet(Iterable<? extends T> iterable)

public static <T> LinkedHashSet<T>
public static <T> List<T>
toImmutableList(List<? extends T> list)

public static <K, V> Map<K, V>
toImmutableMap(Map<K, V> map)

public static <T> Set<T>
toImmutableSet(Set<? extends T> set)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

CollectionHelperback to summary
private CollectionHelper()

Method Detail

accessorFromArrayback to summary
private static CollectionHelper.ArrayAccessor<?, ?> accessorFromArray(Object object)
asSetback to summary
public static <T> Set<T> asSet(T... ts)
Annotations
@SafeVarargs
getInitialCapacityFromExpectedSizeback to summary
private static int getInitialCapacityFromExpectedSize(int expectedSize)

As the default loadFactor is of 0.75, we need to calculate the initial capacity from the expected size to avoid resizing the collection when we populate the collection with all the initial elements. We use a calculation similar to what is done in HashMap#putAll(Map).

Parameters
expectedSize:int

the expected size of the collection

Returns:int

the initial capacity of the collection

iterableFromArrayback to summary
public static Iterable<?> iterableFromArray(Object object)

Builds an Iterable for a given array. It is (un)necessarily ugly because we have to deal with array of primitives.

Parameters
object:Object

a given array

Returns:Iterable<?>

an Iterable providing iterators over the array

Annotations
@SuppressWarnings:unchecked, rawtypes
iteratorFromArrayback to summary
public static Iterator<?> iteratorFromArray(Object object)

Builds an Iterator for a given array. It is (un)necessarily ugly because we have to deal with array of primitives.

Parameters
object:Object

a given array

Returns:Iterator<?>

an Iterator iterating over the array

Annotations
@SuppressWarnings:unchecked, rawtypes
newArrayListback to summary
public static <T> ArrayList<T> newArrayList()
newArrayListback to summary
public static <T> ArrayList<T> newArrayList(int size)
newArrayListback to summary
public static <T> ArrayList<T> newArrayList(Iterable<T>... iterables)
Annotations
@SafeVarargs
newConcurrentHashMapback to summary
public static <K, V> ConcurrentHashMap<K, V> newConcurrentHashMap()
newHashMapback to summary
public static <K, V> HashMap<K, V> newHashMap()
newHashMapback to summary
public static <K, V> HashMap<K, V> newHashMap(int size)
newHashMapback to summary
public static <K, V> HashMap<K, V> newHashMap(Map<K, V> map)
newHashSetback to summary
public static <T> HashSet<T> newHashSet()
newHashSetback to summary
public static <T> HashSet<T> newHashSet(int size)
newHashSetback to summary
public static <T> HashSet<T> newHashSet(Collection<? extends T> c)
newHashSetback to summary
public static <T> HashSet<T> newHashSet(Iterable<? extends T> iterable)
newLinkedHashSetback to summary
public static <T> LinkedHashSet<T> newLinkedHashSet()
toImmutableListback to summary
public static <T> List<T> toImmutableList(List<? extends T> list)
toImmutableMapback to summary
public static <K, V> Map<K, V> toImmutableMap(Map<K, V> map)
toImmutableSetback to summary
public static <T> Set<T> toImmutableSet(Set<? extends T> set)
org.hibernate.validator.internal.util back to summary

private Interface CollectionHelper.ArrayAccessor<A, T>


Field Summary

Modifier and TypeField and Description
public static final CollectionHelper.ArrayAccessor<boolean[], Boolean>
public static final CollectionHelper.ArrayAccessor<byte[], Byte>
public static final CollectionHelper.ArrayAccessor<char[], Character>
public static final CollectionHelper.ArrayAccessor<double[], Double>
public static final CollectionHelper.ArrayAccessor<float[], Float>
public static final CollectionHelper.ArrayAccessor<int[], Integer>
public static final CollectionHelper.ArrayAccessor<long[], Long>
public static final CollectionHelper.ArrayAccessor<Object[], Object>
public static final CollectionHelper.ArrayAccessor<short[], Short>

Method Summary

Modifier and TypeMethod and Description
public T
get(A array, int index)

public int
size(A array)

Field Detail

BOOLEANback to summary
public static final CollectionHelper.ArrayAccessor<boolean[], Boolean> BOOLEAN
BYTEback to summary
public static final CollectionHelper.ArrayAccessor<byte[], Byte> BYTE
CHARback to summary
public static final CollectionHelper.ArrayAccessor<char[], Character> CHAR
DOUBLEback to summary
public static final CollectionHelper.ArrayAccessor<double[], Double> DOUBLE
FLOATback to summary
public static final CollectionHelper.ArrayAccessor<float[], Float> FLOAT
INTback to summary
public static final CollectionHelper.ArrayAccessor<int[], Integer> INT
LONGback to summary
public static final CollectionHelper.ArrayAccessor<long[], Long> LONG
OBJECTback to summary
public static final CollectionHelper.ArrayAccessor<Object[], Object> OBJECT
SHORTback to summary
public static final CollectionHelper.ArrayAccessor<short[], Short> SHORT

Method Detail

getback to summary
public T get(A array, int index)
sizeback to summary
public int size(A array)
org.hibernate.validator.internal.util back to summary

private Class CollectionHelper.ArrayIterable<A, T>

extends Object
implements Iterable<T>
Class Inheritance
  • java.lang.Object
  • org.hibernate.validator.internal.util.CollectionHelper.ArrayIterable
All Implemented Interfaces
java.lang.Iterable

Field Summary

Modifier and TypeField and Description
private final CollectionHelper.ArrayAccessor<A, T>
private final A

Constructor Summary

AccessConstructor and Description
public
ArrayIterable(CollectionHelper.ArrayAccessor<A, T> accessor, A values)

Method Summary

Modifier and TypeMethod and Description
public final Iterator<T>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

accessorback to summary
private final CollectionHelper.ArrayAccessor<A, T> accessor
valuesback to summary
private final A values

Constructor Detail

ArrayIterableback to summary
public ArrayIterable(CollectionHelper.ArrayAccessor<A, T> accessor, A values)

Method Detail

iteratorback to summary
public final Iterator<T> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

Returns:Iterator<T>

an Iterator.

Annotations
@Override
org.hibernate.validator.internal.util back to summary

private Class CollectionHelper.ArrayIterator<A, T>

extends Object
implements Iterator<T>
Class Inheritance
  • java.lang.Object
  • org.hibernate.validator.internal.util.CollectionHelper.ArrayIterator
All Implemented Interfaces
java.util.Iterator

Field Summary

Modifier and TypeField and Description
private final CollectionHelper.ArrayAccessor<A, T>
private int
private final A

Constructor Summary

AccessConstructor and Description
public
ArrayIterator(CollectionHelper.ArrayAccessor<A, T> accessor, A values)

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.
public T
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

accessorback to summary
private final CollectionHelper.ArrayAccessor<A, T> accessor
currentback to summary
private int current
valuesback to summary
private final A values

Constructor Detail

ArrayIteratorback to summary
public ArrayIterator(CollectionHelper.ArrayAccessor<A, T> accessor, A values)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public T next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:T

the next element in the iteration

Annotations
@Override