public final class ArrayHandler extends Object
| Constructor and Description |
|---|
ArrayHandler() |
| Modifier and Type | Method and Description |
|---|---|
static <S> S[] |
cast(Class<? extends S> c,
Object[] o)
This method returns an array of a user-specified class with all elements in the given array
o. |
static Object[] |
cast(Object[] o)
This method creates a new array of the superclass of all elements of the
given array and copies the elements.
|
static <T extends Cloneable> |
clone(T... t)
This method returns a deep copy of a (multi-dimensional) array of
Cloneables or primitives. |
static <T extends Cloneable> |
createArrayOf(T t,
int l)
This method returns an array of length
l that has at each position a clone of t. |
static <T> Class |
getSuperClassOf(T... o)
This method returns the deepest class in the class hierarchy that is the
class or a superclass of all instances in the array.
|
public static <T> Class getSuperClassOf(T... o)
T - the type of the array elementso - the arraypublic static Object[] cast(Object[] o)
Object[] o = { new UniformTrainSM( alphabetContainer ), new UniformTrainSM( alphabetContainer ) };
AbstractTrainableStatisticalModel[] a = (AbstractTrainableStatisticalModel[]) ArrayHandler.cast( o );
AbstractTrainableStatisticalModel[] a = (AbstractTrainableStatisticalModel[]) o;o - the arraygetSuperClassOf(Object[]),
cast(Class, Object[])public static <S> S[] cast(Class<? extends S> c, Object[] o)
o.
If the given array is already from the correct class it is directly returned, otherwise a new array is created
and filled with the elements of o. In both cases, the order of the elements is not changed.
Object[] o = { new UniformTrainSM( alphabetContainer ), new UniformTrainSM( alphabetContainer ) };
AbstractTrainableStatisticalModel[] a = ArrayHandler.cast( AbstractTrainableStatisticalModel.class, o );
AbstractTrainableStatisticalModel[] a = (AbstractTrainableStatisticalModel[]) o;S - the type of the array elementsc - the class of the array itemso - the arraygetSuperClassOf(Object[])public static <T extends Cloneable> T[] clone(T... t) throws CloneNotSupportedException
Cloneables or primitives. For arrays of Cloneables, each element of the
array is cloned using its clone()-method.T - the type of the array elementst - the arrayCloneNotSupportedException - if an element could not be clonedCloneablepublic static <T extends Cloneable> T[] createArrayOf(T t, int l) throws CloneNotSupportedException
l that has at each position a clone of t.T - the type of the array elements that implements
Cloneablet - the original elementl - the dimension of the new arrayl that has at each position a clone of tCloneNotSupportedException - if t could not be clonedCloneable