/** * <p>Checks if an array of Objects is empty or {@code null}. * * @param array the array to test * @return {@code true} if the array is empty or {@code null} * @since 2.1 */ public static boolean isEmpty(final Object[] array) { return getLength(array) == 0; }
/** * <p>Defensive programming technique to change a {@code null} * reference to an empty one. * * <p>This method returns an empty array for a {@code null} input array. * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty {@code public static} references in this class. * * @param array the array to check for {@code null} or empty * @return the same array, {@code public static} empty array if {@code null} or empty input * @since 2.5 */ public static Object[] nullToEmpty(final Object[] array) { if (isEmpty(array)) { return EMPTY_OBJECT_ARRAY; } return array; }
if (!ArrayUtils.isSameLength(classArray, toClassArray)) { return false;
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { args = ArrayUtils.nullToEmpty(args); parameterTypes = ArrayUtils.nullToEmpty(parameterTypes); final Constructor<T> ctor = getMatchingAccessibleConstructor(cls, parameterTypes); if (ctor == null) {
final Class<?> pt = ClassUtils.wrapperToPrimitive(ct); if(Integer.TYPE.equals(pt)) { return toPrimitive((Integer[]) array); return toPrimitive((Long[]) array); return toPrimitive((Short[]) array); return toPrimitive((Double[]) array); return toPrimitive((Float[]) array);
/** * <p>Returns a new instance of the specified class inferring the right constructor * from the types of the arguments.</p> * * <p>This locates and calls a constructor. * The constructor signature must match the argument types by assignment compatibility.</p> * * @param <T> the type to be constructed * @param cls the class to be constructed, not {@code null} * @param args the array of arguments, {@code null} treated as empty * @return new instance of {@code cls}, not {@code null} * * @throws NullPointerException if {@code cls} is {@code null} * @throws NoSuchMethodException if a matching constructor cannot be found * @throws IllegalAccessException if invocation is not permitted by security * @throws InvocationTargetException if an error occurs on invocation * @throws InstantiationException if an error occurs on instantiation * @see #invokeConstructor(Class, Object[], Class[]) */ public static <T> T invokeConstructor(final Class<T> cls, Object... args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { args = ArrayUtils.nullToEmpty(args); final Class<?> parameterTypes[] = ClassUtils.toClass(args); return invokeConstructor(cls, args, parameterTypes); }
varArgsArray = ArrayUtils.toPrimitive(varArgsArray);
/** * <p>Checks whether two arrays are the same length, treating * {@code null} arrays as length {@code 0}. * * <p>Any multi-dimensional aspects of the arrays are ignored. * * @param array1 the first array, may be {@code null} * @param array2 the second array, may be {@code null} * @return {@code true} if length of arrays matches, treating * {@code null} as an empty array */ public static boolean isSameLength(final Object[] array1, final Object[] array2) { return getLength(array1) == getLength(array2); }
/** * <p>Defensive programming technique to change a {@code null} * reference to an empty one. * * <p>This method returns an empty array for a {@code null} input array. * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty {@code public static} references in this class. * * @param array the array to check for {@code null} or empty * @return the same array, {@code public static} empty array if {@code null} or empty input * @since 3.2 */ public static Class<?>[] nullToEmpty(final Class<?>[] array) { if (isEmpty(array)) { return EMPTY_CLASS_ARRAY; } return array; }
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { args = ArrayUtils.nullToEmpty(args); parameterTypes = ArrayUtils.nullToEmpty(parameterTypes); final Constructor<T> ctor = getMatchingAccessibleConstructor(cls, parameterTypes); if (ctor == null) {
final Class<?> pt = ClassUtils.wrapperToPrimitive(ct); if(Integer.TYPE.equals(pt)) { return toPrimitive((Integer[]) array); return toPrimitive((Long[]) array); return toPrimitive((Short[]) array); return toPrimitive((Double[]) array); return toPrimitive((Float[]) array);
if (!ArrayUtils.isSameLength(classArray, toClassArray)) { return false;
/** * <p>Checks if an array of Objects is empty or {@code null}. * * @param array the array to test * @return {@code true} if the array is empty or {@code null} * @since 2.1 */ public static boolean isEmpty(final Object[] array) { return getLength(array) == 0; }
/** * <p>Defensive programming technique to change a {@code null} * reference to an empty one. * * <p>This method returns an empty array for a {@code null} input array. * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty {@code public static} references in this class. * * @param array the array to check for {@code null} or empty * @return the same array, {@code public static} empty array if {@code null} or empty input * @since 2.5 */ public static Object[] nullToEmpty(final Object[] array) { if (isEmpty(array)) { return EMPTY_OBJECT_ARRAY; } return array; }
/** * <p>Returns a new instance of the specified class inferring the right constructor * from the types of the arguments.</p> * * <p>This locates and calls a constructor. * The constructor signature must match the argument types by assignment compatibility.</p> * * @param <T> the type to be constructed * @param cls the class to be constructed, not {@code null} * @param args the array of arguments, {@code null} treated as empty * @return new instance of {@code cls}, not {@code null} * * @throws NullPointerException if {@code cls} is {@code null} * @throws NoSuchMethodException if a matching constructor cannot be found * @throws IllegalAccessException if invocation is not permitted by security * @throws InvocationTargetException if an error occurs on invocation * @throws InstantiationException if an error occurs on instantiation * @see #invokeConstructor(Class, Object[], Class[]) */ public static <T> T invokeConstructor(final Class<T> cls, Object... args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { args = ArrayUtils.nullToEmpty(args); final Class<?> parameterTypes[] = ClassUtils.toClass(args); return invokeConstructor(cls, args, parameterTypes); }
varArgsArray = ArrayUtils.toPrimitive(varArgsArray);
/** * <p>Checks whether two arrays are the same length, treating * {@code null} arrays as length {@code 0}. * * <p>Any multi-dimensional aspects of the arrays are ignored. * * @param array1 the first array, may be {@code null} * @param array2 the second array, may be {@code null} * @return {@code true} if length of arrays matches, treating * {@code null} as an empty array */ public static boolean isSameLength(final Object[] array1, final Object[] array2) { return getLength(array1) == getLength(array2); }
/** * <p>Defensive programming technique to change a {@code null} * reference to an empty one. * * <p>This method returns an empty array for a {@code null} input array. * * <p>As a memory optimizing technique an empty array passed in will be overridden with * the empty {@code public static} references in this class. * * @param array the array to check for {@code null} or empty * @return the same array, {@code public static} empty array if {@code null} or empty input * @since 3.2 */ public static Class<?>[] nullToEmpty(final Class<?>[] array) { if (isEmpty(array)) { return EMPTY_CLASS_ARRAY; } return array; }