Added reverse method for Object arrays.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@2522 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
andrzej@threerings.net
2009-01-29 01:01:36 +00:00
parent 5f047c124c
commit 0a56f4f338
@@ -156,6 +156,36 @@ public class ArrayUtil
}
}
/**
* Reverses the elements in the given array.
*
* @param values the array to reverse.
*/
public static void reverse (Object[] values)
{
reverse(values, 0, values.length);
}
/**
* Reverses a subset of elements within the specified array.
*
* @param values the array containing elements to reverse.
* @param offset the index at which to start reversing elements.
* @param length the number of elements to reverse.
*/
public static void reverse (Object[] values, int offset, int length)
{
int aidx = offset;
int bidx = offset + length - 1;
while (bidx > aidx) {
Object value = values[aidx];
values[aidx] = values[bidx];
values[bidx] = value;
aidx++;
bidx--;
}
}
/**
* Shuffles the elements in the given array into a random sequence.
*