jimmc.util
Class ArrayUtil

java.lang.Object
  |
  +--jimmc.util.ArrayUtil

public class ArrayUtil
extends java.lang.Object

Utility methods for arrays.


Constructor Summary
ArrayUtil()
           
 
Method Summary
static int[] andNot(int[] a1, int[] a2)
          Given two sorted arrays of ints, return the list of all entries which are in the first array and not in the second.
static java.lang.String[] andNot(java.lang.String[] a1, java.lang.String[] a2)
          Given two sorted arrays of strings, return the list of all entries which are in the first array and not in the second.
static java.lang.String[] cat(java.lang.String[] a1, java.lang.String[] a2)
          Concatenate two string arrays into a new string array.
static int[] randomArray(int n)
          Get an array of randomly ordered ints.
static java.lang.Object[] shuffle(java.lang.Object[] aa)
          Shuffle an array in random order.
static void shuffle(java.lang.String[] ss)
          Shuffle an array of strings in place.
static java.lang.String[] union(java.lang.String[] a1, java.lang.String[] a2)
          Take the union of two unsorted sets of strings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayUtil

public ArrayUtil()
Method Detail

cat

public static java.lang.String[] cat(java.lang.String[] a1,
                                     java.lang.String[] a2)
Concatenate two string arrays into a new string array.

union

public static java.lang.String[] union(java.lang.String[] a1,
                                       java.lang.String[] a2)
Take the union of two unsorted sets of strings.

andNot

public static java.lang.String[] andNot(java.lang.String[] a1,
                                        java.lang.String[] a2)
Given two sorted arrays of strings, return the list of all entries which are in the first array and not in the second.
Parameters:
a1 - All returned entries are from this list.
a2 - No returned entries are in this list.
Returns:
All entries in a1 and not in a2. If a1 is null, returns null. If a2 is null, returns a1.

andNot

public static int[] andNot(int[] a1,
                           int[] a2)
Given two sorted arrays of ints, return the list of all entries which are in the first array and not in the second.
Parameters:
a1 - All returned entries are from this list.
a2 - No returned entries are in this list.
Returns:
All entries in a1 and not in a2. If a1 is null, returns null. If a2 is null, returns a1.

randomArray

public static int[] randomArray(int n)
Get an array of randomly ordered ints.
Parameters:
n - The size of the array.
Returns:
An array of length n, with entries from 0 to n-1 in random order.

shuffle

public static java.lang.Object[] shuffle(java.lang.Object[] aa)
Shuffle an array in random order.

shuffle

public static void shuffle(java.lang.String[] ss)
Shuffle an array of strings in place.