|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbb.util.ArrayUtil
public final class ArrayUtil
Provides static utility methods that deal with arrays.
(All these methods should have been put in java's Arrays
class...)
This class is multithread safe: it is stateless.
Nested Class Summary | |
---|---|
static class |
ArrayUtil.UnitTest
See the Overview page of the project's javadocs for a general description of this unit test class. |
Constructor Summary | |
---|---|
private |
ArrayUtil()
This sole private constructor suppresses the default (public) constructor, ensuring non-instantiability outside of this class. |
Method Summary | ||
---|---|---|
static
|
concatenate(T[] a1,
T[] a2)
This method concatenates two arrays into one. |
|
static void |
shuffle(int[] a,
Random random)
Shuffles the elements of a in a random fashion. |
|
static
|
shuffle(T[] a)
Simply calls . |
|
static
|
shuffle(T[] a,
Random random)
Shuffles the elements of a in a random fashion. |
|
static void |
swap(int[] a,
int i,
int j)
Swaps elements i and j of a. |
|
static
|
swap(T[] a,
int i,
int j)
Swaps elements i and j of a. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
private ArrayUtil()
Method Detail |
---|
public static <T> T[] concatenate(T[] a1, T[] a2)
The concatenation is done is according to the following rules:
a1 == null
, then a2
is returned (which could be null as well)a2 == null
, then a1
is returneda1.length == 0
, then a2
is returned (which could be zero length as well)a2.length == 0
, then a1
is returneda1
and then a2
are copied in order onto it before it is returned;
note: the new array is created with a1's type, so a2 had better be compatible
public static <T> void shuffle(T[] a) throws IllegalArgumentException
shuffle
(a, new Random())
.
IllegalArgumentException
- if a == nullpublic static <T> void shuffle(T[] a, Random random) throws IllegalArgumentException
IllegalArgumentException
- if a == null; random == nullpublic static void shuffle(int[] a, Random random) throws IllegalArgumentException
IllegalArgumentException
- if a == null; random == nullpublic static <T> void swap(T[] a, int i, int j) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
IllegalArgumentException
- if a == null
ArrayIndexOutOfBoundsException
- if i or j is an illegal index value for apublic static void swap(int[] a, int i, int j) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
IllegalArgumentException
- if a == null
ArrayIndexOutOfBoundsException
- if i or j is an illegal index value for a
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |