public class CollectionReflectionUtilImpl extends AbstractComponent implements CollectionReflectionUtil
CollectionReflectionUtil interface.getInstance()| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_MAXIMUM_LIST_GROWTH
|
private static CollectionReflectionUtilImpl |
instance |
private static org.slf4j.Logger |
LOG |
private int |
maximumListGrowth |
| Constructor and Description |
|---|
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. |
protected void |
doInitialize() |
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. |
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 |
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. |
doInitialized, getInitializationState, initializeprivate static final org.slf4j.Logger LOG
public static final int DEFAULT_MAXIMUM_LIST_GROWTH
private static CollectionReflectionUtilImpl instance
private int maximumListGrowth
public CollectionReflectionUtilImpl()
public static CollectionReflectionUtilImpl getInstance()
CollectionReflectionUtilImpl. protected void doInitialize()
doInitialize in class AbstractComponentpublic int getMaximumListGrowth()
Lists.set(Object, int, Object, GenericBean),
setMaximumListGrowth(int)public void setMaximumListGrowth(int maximumListGrowth)
maximumListGrowth.maximumListGrowth - is the maximumListGrowth to set.public boolean isArrayOrList(Object object)
CollectionReflectionUtilobject 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)
CollectionReflectionUtilarrayMapOrCollection. 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.public Object get(Object arrayOrList, int index)
CollectionReflectionUtilindex 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.CollectionReflectionUtil.get(Object, int, boolean)public Object get(Object arrayOrList, int index, boolean ignoreIndexOverflow)
CollectionReflectionUtilindex 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.List.get(int)public Object set(Object arrayOrList, int index, Object item)
CollectionReflectionUtilitem 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.CollectionReflectionUtil.set(Object, int, Object, GenericBean, int)public Object set(Object arrayOrList, int index, Object item, GenericBean<Object> arrayReceiver)
CollectionReflectionUtilitem 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.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)
CollectionReflectionUtilitem 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.List.set(int, Object)public Object add(Object arrayOrCollection, Object item)
CollectionReflectionUtilitem 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)
CollectionReflectionUtilitem 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
CollectionReflectionUtilCollection 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)
CollectionReflectionUtilCollection 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–2019 mmm-Team. All rights reserved.