/** * <p>Reverses the order of the given array. * * <p>This method does nothing for a {@code null} input array. * * @param array the array to reverse, may be {@code null} */ public static void reverse(final long[] array) { if (array == null) { return; } reverse(array, 0, array.length); }
/** * <p>Reverses the order of the given array. * * <p>This method does nothing for a {@code null} input array. * * @param array the array to reverse, may be {@code null} */ public static void reverse(final short[] array) { if (array == null) { return; } reverse(array, 0, array.length); }
/** * <p>Reverses the order of the given array. * * <p>This method does nothing for a {@code null} input array. * * @param array the array to reverse, may be {@code null} */ public static void reverse(final double[] array) { if (array == null) { return; } reverse(array, 0, array.length); }
/** * <p>Reverses the order of the given array. * * <p>This method does nothing for a {@code null} input array. * * @param array the array to reverse, may be {@code null} */ public static void reverse(final boolean[] array) { if (array == null) { return; } reverse(array, 0, array.length); }
/** * <p>Reverses the order of the given array. * * <p>This method does nothing for a {@code null} input array. * * @param array the array to reverse, may be {@code null} */ public static void reverse(final int[] array) { if (array == null) { return; } reverse(array, 0, array.length); }
/** * <p>Reverses the order of the given array. * * <p>This method does nothing for a {@code null} input array. * * @param array the array to reverse, may be {@code null} */ public static void reverse(final byte[] array) { if (array == null) { return; } reverse(array, 0, array.length); }
/** * <p>Reverses the order of the given array. * * <p>This method does nothing for a {@code null} input array. * * @param array the array to reverse, may be {@code null} */ public static void reverse(final float[] array) { if (array == null) { return; } reverse(array, 0, array.length); }
/** * <p>Reverses the order of the given array. * * <p>This method does nothing for a {@code null} input array. * * @param array the array to reverse, may be {@code null} */ public static void reverse(final char[] array) { if (array == null) { return; } reverse(array, 0, array.length); }
/** * <p>Reverses the order of the given array. * * <p>There is no special handling for multi-dimensional arrays. * * <p>This method does nothing for a {@code null} input array. * * @param array the array to reverse, may be {@code null} */ public static void reverse(final Object[] array) { if (array == null) { return; } reverse(array, 0, array.length); }
/** * <p>Convert a {@code long[]} created by {@link EnumUtils#generateBitVectors} into the set of * enum values that it represents.</p> * * <p>If you store this value, beware any changes to the enum that would affect ordinal values.</p> * @param enumClass the class of the enum we are working with, not {@code null} * @param values the long[] bearing the representation of a set of enum values, least significant digits rightmost, not {@code null} * @param <E> the type of the enumeration * @return a set of enum values * @throws NullPointerException if {@code enumClass} is {@code null} * @throws IllegalArgumentException if {@code enumClass} is not an enum class * @since 3.2 */ public static <E extends Enum<E>> EnumSet<E> processBitVectors(final Class<E> enumClass, final long... values) { final EnumSet<E> results = EnumSet.noneOf(asEnum(enumClass)); final long[] lvalues = ArrayUtils.clone(Validate.notNull(values)); ArrayUtils.reverse(lvalues); for (final E constant : enumClass.getEnumConstants()) { final int block = constant.ordinal() / Long.SIZE; if (block < lvalues.length && (lvalues[block] & 1L << (constant.ordinal() % Long.SIZE)) != 0) { results.add(constant); } } return results; }
@Test public void testReverse() { final StringBuffer str1 = new StringBuffer("pick"); final String str2 = "a"; final String[] str3 = new String[]{"stick"}; final String str4 = "up"; Object[] array = new Object[]{str1, str2, str3}; ArrayUtils.reverse(array); assertEquals(array[0], str3); assertEquals(array[1], str2); assertEquals(array[2], str1); array = new Object[]{str1, str2, str3, str4}; ArrayUtils.reverse(array); assertEquals(array[0], str4); assertEquals(array[1], str3); assertEquals(array[2], str2); assertEquals(array[3], str1); array = null; ArrayUtils.reverse(array); assertArrayEquals(null, array); }
@Test public void testStandardTupleKeys() { TupleTypeInfo<Tuple7<String, String, String, String, String, String, String>> typeInfo = new TupleTypeInfo<>( BasicTypeInfo.STRING_TYPE_INFO,BasicTypeInfo.STRING_TYPE_INFO,BasicTypeInfo.STRING_TYPE_INFO,BasicTypeInfo.STRING_TYPE_INFO,BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO,BasicTypeInfo.STRING_TYPE_INFO); ExpressionKeys<Tuple7<String, String, String, String, String, String, String>> ek; for( int i = 1; i < 8; i++) { int[] ints = new int[i]; for( int j = 0; j < i; j++) { ints[j] = j; } int[] inInts = Arrays.copyOf(ints, ints.length); // copy, just to make sure that the code is not cheating by changing the ints. ek = new ExpressionKeys<>(inInts, typeInfo); Assert.assertArrayEquals(ints, ek.computeLogicalKeyPositions()); Assert.assertEquals(ints.length, ek.computeLogicalKeyPositions().length); ArrayUtils.reverse(ints); inInts = Arrays.copyOf(ints, ints.length); ek = new ExpressionKeys<>(inInts, typeInfo); Assert.assertArrayEquals(ints, ek.computeLogicalKeyPositions()); Assert.assertEquals(ints.length, ek.computeLogicalKeyPositions().length); } }