org.analogweb.util.ArrayUtils Maven / Gradle / Ivy
package org.analogweb.util;
import java.lang.reflect.Array;
/**
* @author snowgoose
*/
public final class ArrayUtils {
@SuppressWarnings("unchecked")
public static boolean isEmpty(T... anArray) {
return isNotEmpty(anArray) == false;
}
@SuppressWarnings("unchecked")
public static boolean isNotEmpty(T... anArray) {
return (anArray != null && anArray.length != 0);
}
@SuppressWarnings("unchecked")
public static T[] newArray(T... objects) {
return objects;
}
@SuppressWarnings("unchecked")
public static T[] clone(Class type, T... original) {
return clone(type, 0, original);
}
@SuppressWarnings("unchecked")
public static T[] clone(Class type, int additionalLength, T... original) {
if (original == null) {
return null;
}
if (type == null) {
return original;
}
T[] array = (T[]) Array.newInstance(type, original.length + additionalLength);
System.arraycopy(original, 0, array, 0, original.length);
return array;
}
@SuppressWarnings("unchecked")
public static T[] add(Class clazz, T addition, T... original) {
T[] array = clone(clazz, 1, original);
if (array != null) {
array[array.length - 1] = addition;
return array;
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy