@Singleton @Named(value="net.sf.mmm.util.reflect.api.CollectionReflectionUtil") public class CollectionReflectionUtilImpl extends AbstractLoggableComponent implements CollectionReflectionUtil
CollectionReflectionUtil interface.getInstance()| Modifier and Type | Field and Description |
|---|---|
private CollectionFactoryManager |
collectionFactoryManager |
static int |
DEFAULT_MAXIMUM_LIST_GROWTH
|
private static CollectionReflectionUtilImpl |
instance |
private int |
maximumListGrowth |
CDI_NAME| Modifier | Constructor and Description |
|---|---|
protected |
CollectionReflectionUtilImpl()
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
Object |
add(Object arrayOrCollection,
Object item)
This method adds the given
item to the given arrayOrCollection. |
<C extends Collection> |
create(Class<C> type)
This method creates a collection implementing the given collection
type. |
protected void |
doInitialize()
This method performs the actual
initialization. |
Object |
get(Object arrayOrList,
int index)
This method gets the item at the given
index from arrayOrCollection. |
Object |
get(Object arrayOrList,
int index,
boolean ignoreIndexOverflow)
This method gets the item at the given
index from arrayOrCollection. |
CollectionFactoryManager |
getCollectionFactoryManager()
This method gets the
CollectionFactoryManager instance used by this util. |
static CollectionReflectionUtilImpl |
getInstance()
This method gets the singleton instance of this
CollectionReflectionUtilImpl. |
int |
getMaximumListGrowth()
This method gets the maximum growth for arrays or
Lists. |
int |
getSize(Object arrayMapOrCollection)
This method gets the size of the given
arrayMapOrCollection. |
boolean |
isArrayOrList(Object object)
This method determines if the given
object is an array or List. |
Object |
remove(Object arrayOrCollection,
Object item)
This method removes the given
item from the given arrayOrCollection. |
Object |
set(Object arrayOrList,
int index,
Object item)
This method sets the given
item at the given index in
arrayOrCollection. |
Object |
set(Object arrayOrList,
int index,
Object item,
GenericBean<Object> arrayReceiver)
This method sets the given
item at the given index in
arrayOrCollection. |
Object |
set(Object arrayOrList,
int index,
Object item,
GenericBean<Object> arrayReceiver,
int maximumGrowth)
This method sets the given
item at the given index in
arrayOrCollection. |
void |
setCollectionFactoryManager(CollectionFactoryManager collectionFactoryManager)
This method sets the
CollectionFactoryManager instance to use. |
void |
setMaximumListGrowth(int maximumListGrowth)
This method sets the
maximumListGrowth. |
Object |
toArray(Collection<?> collection,
Class<?> componentType)
This method converts the given
Collection to an array of the given
componentType. |
<T> T[] |
toArrayTyped(Collection<T> collection,
Class<T> componentType)
This method converts the given
Collection to an array of the given
componentType. |
createLogger, getLoggerdoInitialized, getInitializationState, initializepublic static final int DEFAULT_MAXIMUM_LIST_GROWTH
private static CollectionReflectionUtilImpl instance
getInstance()private CollectionFactoryManager collectionFactoryManager
getCollectionFactoryManager()private int maximumListGrowth
getMaximumListGrowth()protected CollectionReflectionUtilImpl()
public static CollectionReflectionUtilImpl getInstance()
CollectionReflectionUtilImpl. Cdi.GET_INSTANCE before using.protected void doInitialize()
initialization. It is called when
AbstractComponent.initialize() is invoked for the first time. super.AbstractComponent.doInitialize().doInitialize in class AbstractLoggableComponentpublic CollectionFactoryManager getCollectionFactoryManager()
CollectionFactoryManager instance used by this util.getCollectionFactoryManager in interface CollectionReflectionUtilCollectionFactoryManager instance.@Inject public void setCollectionFactoryManager(CollectionFactoryManager collectionFactoryManager)
CollectionFactoryManager instance to use.collectionFactoryManager - is the CollectionFactoryManager instance.public int getMaximumListGrowth()
Lists.set(Object, int, Object, GenericBean),
setMaximumListGrowth(int)public void setMaximumListGrowth(int maximumListGrowth)
maximumListGrowth.maximumListGrowth - is the maximumListGrowth to set.public <C extends Collection> C create(Class<C> type)
type.create in interface CollectionReflectionUtilC - is the generic type of the collection.type - is the type of collection to create. This is either an interface (List,
Set, Queue, etc.) or a non-abstract implementation of a
Collection.type.public boolean isArrayOrList(Object object)
object is an array or List.isArrayOrList in interface CollectionReflectionUtilobject - is the object to check.true if the given object is an array or List, false
otherwise.public int getSize(Object arrayMapOrCollection) throws NlsIllegalArgumentException
arrayMapOrCollection. If
arrayMapOrCollection is an array, then its length is returned. If it is a Map or Collection, its
size is returned.getSize in interface CollectionReflectionUtilarrayMapOrCollection - the array, Map or Collection.arrayMapOrCollection.NlsIllegalArgumentException - if the given arrayMapOrCollection is invalid (
null or neither array nor Map or Collection).public Object get(Object arrayOrList, int index) throws NlsIllegalArgumentException
index from arrayOrCollection. ignoreIndexOverflow to true.get in interface CollectionReflectionUtilarrayOrList - is the array or List.index - is the position of the requested item.index. May be null if the item itself is
null or the index is greater than the size or
arrayOrCollection.NlsIllegalArgumentException - if the given arrayOrList is invalid (null
or neither array nor List).CollectionReflectionUtil.get(Object, int, boolean)public Object get(Object arrayOrList, int index, boolean ignoreIndexOverflow) throws NlsIllegalArgumentException
index from arrayOrCollection.get in interface CollectionReflectionUtilarrayOrList - is the array or List.index - is the position of the requested item.ignoreIndexOverflow - - if false an the given index is greater or equal to
the size of arrayOrCollection an
IndexOutOfBoundsException will be thrown. Else if true, null is
returned in this case.index. May be null if the item itself is
null or the index is greater or equal to the size of
arrayOrCollection.NlsIllegalArgumentException - if the given arrayOrList is invalid (null
or neither array nor List).List.get(int)public Object set(Object arrayOrList, int index, Object item) throws NlsIllegalArgumentException
item at the given index in
arrayOrCollection. It uses a default value for maximumGrowth and no
arrayReceiver ( null).set in interface CollectionReflectionUtilarrayOrList - is the array or List.index - is the position where to set the item.item - is the item to set.index in arrayOrList that has been replaced by
item. This can be null. Additional if the arrayOrList has
been increased, null is returned.NlsIllegalArgumentException - if the given arrayOrList is invalid (null
or neither array nor List).CollectionReflectionUtil.set(Object, int, Object, GenericBean, int)public Object set(Object arrayOrList, int index, Object item, GenericBean<Object> arrayReceiver) throws NlsIllegalArgumentException
item at the given index in
arrayOrCollection. If a List is given that has a
size less or equal to the given index, the
size of the List will be increased to
index + 1 by adding null values so the
item can be set. It uses a default value for maximumGrowth.set in interface CollectionReflectionUtilarrayOrList - is the array or List.index - is the position where to set the item.item - is the item to set.arrayReceiver - is a GenericBean that allows to receive an
array-copy of arrayOrList
with an increased length. It can be
null to disable array-copying.index in arrayOrList that has been replaced by
item. This can be null. Additional if the arrayOrList has
been increased, null is returned.NlsIllegalArgumentException - if the given arrayOrList is invalid (null
or neither array nor List).List.set(int, Object),
CollectionReflectionUtil.set(Object, int, Object, GenericBean, int)public Object set(Object arrayOrList, int index, Object item, GenericBean<Object> arrayReceiver, int maximumGrowth) throws NlsIllegalArgumentException
item at the given index in
arrayOrCollection. If a List is given that has a
size less or equal to the given index, the
size of the List will be increased to
index + 1 by adding null values so the
item can be set. However the number of adds is limited to
maximumGrowth.set in interface CollectionReflectionUtilarrayOrList - is the array or List.index - is the position where to set the item.item - is the item to set.arrayReceiver - is a GenericBean that allows to receive an
array-copy of arrayOrList
with an increased length. It can be
null to disable array-copying.maximumGrowth - is the maximum number by which the size of
arrayOrList will be increased (with null values) to reach
index + 1 so the item can be set. Set this value to 0 to
turn off this feature (and leave the size untouched). Please always
specify a real maximum (<=65536) and do NOT use Integer.MAX_VALUE since
this might cause memory holes if something goes wrong. If arrayOrList is an array,
increasing can only happen by creating a new array. To receive such new array, you need to supply
an arrayReceiver. Otherwise (if null) this method behaves for arrays as
if maximumGrowth was 0. If an array should be increased, a new array
with the size of index + 1 is created. The original items are
copied, the given item is set
on the copy instead while the original array remains unchanged. Then the new array is
set to the arrayReceiver.index in arrayOrList that has been replaced by
item. This can be null. Additional if the arrayOrList has
been increased, null is returned.NlsIllegalArgumentException - if the given arrayOrList is invalid (null
or neither array nor List).List.set(int, Object)public Object add(Object arrayOrCollection, Object item)
item to the given arrayOrCollection.add in interface CollectionReflectionUtilarrayOrCollection - is the array or Collection.item - is the item to add.arrayOrCollection if it was a Collection. Otherwise, in case of an
array, a new array with a length increased by
1 and the elements of arrayOrCollection appended with the given
item is returned.public Object remove(Object arrayOrCollection, Object item)
item from the given arrayOrCollection.remove in interface CollectionReflectionUtilarrayOrCollection - is the array or Collection.item - is the item to remove.null if the given item was NOT contained in
arrayOrCollection, the given arrayOrCollection if it was a
Collection and the item has been removed. Otherwise, in case of an array, a
new array with a length decreased by
1 and the elements of arrayOrCollection without the first occurrence of
the given item is returned.public Object toArray(Collection<?> collection, Class<?> componentType) throws ClassCastException
Collection to an array of the given
componentType. This method also allows to create primitive arrays. If
NOT required please prefer using CollectionReflectionUtil.toArrayTyped(Collection, Class).toArray in interface CollectionReflectionUtilcollection - is the Collection to convert to an array.componentType - is the component type of the requested array. If
this type is primitive, the according collection-values with be
unboxed.componentType and with the values of the
given Collection.ClassCastException - if the values of the Collection are NOT compatible with the given
componentType.public <T> T[] toArrayTyped(Collection<T> collection, Class<T> componentType)
Collection to an array of the given
componentType.toArrayTyped in interface CollectionReflectionUtilT - is the generic type of the componentType.collection - is the Collection to convert to an array.componentType - is the component type of the requested array.componentType and with the values of the
given Collection.Copyright © 2001–2015 mmm-Team. All rights reserved.