org.sandev.basics.util
Class ArrayUtils

java.lang.Object
  extended byorg.sandev.basics.util.ArrayUtils

public class ArrayUtils
extends java.lang.Object

Simple array management utilities to fill gaps in common use.


Constructor Summary
ArrayUtils()
           
 
Method Summary
static long[] append(long[] oldarray, long newelem)
          The language supports an overloaded '+' operator for Strings, but you can't do the same thing with an array.
static SandMessage[] append(SandMessage[] oldarray, SandMessage newelem)
          The language supports an overloaded '+' operator for Strings, but you can't do the same thing with an array.
static java.lang.String[] append(java.lang.String[] oldarray, java.lang.String newelem)
          The language supports an overloaded '+' operator for Strings, but you can't do the same thing with an array.
static SandMessage[] conc(SandMessage[] first, SandMessage[] second)
          Concatenate the two arrays, returning a new array.
static boolean contains(int[] arr, int val)
          Return true if the array contains the specified value, false otherwise.
static boolean contains(long[] arr, long val)
          Return true if the array contains the specified value, false otherwise.
static boolean contains(SandMessage[] arr, SandMessage val)
          Return true if the array contains the specified value, false otherwise.
static boolean contains(java.lang.String[] arr, java.lang.String val)
          Return true if the array contains the specified value, false otherwise.
static long[] diff(long[] newvals, long[] oldvals)
          Returns an array of all values in newvals that are not found in oldvals.
static int indexOf(int[] arr, int val)
          Return the index of the specified value, or -1 if not found.
static int indexOf(long[] arr, long val)
          Return the index of the specified value, or -1 if not found.
static int indexOf(SandMessage[] arr, SandMessage val)
          Return the index of the specified value, or -1 if not found.
static int indexOf(java.lang.String[] arr, java.lang.String val)
          Return the index of the specified value, or -1 if not found.
static long[] intersect(long[] array1, long[] array2)
          Return only the values that occur in both array1 and array2
static java.lang.String[] longToString(long[] vals)
          Convert the given array of long values to an array of string values.
static boolean messageEqual(SandMessage sm1, SandMessage sm2)
          Returns true if the two messages refer to the same instance, false otherwise.
static int[] remove(int[] arr, int val)
          Given an int array and an int value, return an int array with the first instance of that value removed.
static int[] remove(int[] arr, int val, int[] work)
          Given an int array and an int value, return an int array with the first instance of that value removed.
static long[] remove(long[] arr, long val)
          Given a long array and a long value, return a long array with the first instance of that value removed.
static long[] remove(long[] arr, long val, long[] work)
          Given a long array and a long value, return a long array with the first instance of that value removed.
static SandMessage[] remove(SandMessage[] arr, SandMessage val, SandMessage[] work)
          Given a SandMessage array and value, return a SandMessage array with the first instance of that value removed.
static SandUpdateMessage[] remove(SandUpdateMessage[] sums, int index)
          Return a new SandUpdateMessage array with the element at the given index removed.
static java.lang.String[] remove(java.lang.String[] arr, java.lang.String val)
          Given a String array and a String value, return a String array with the first instance of that value removed.
static java.lang.String[] remove(java.lang.String[] arr, java.lang.String val, java.lang.String[] work)
          Given a String array and a String value, return a String array with the first instance of that value removed.
static java.lang.String[] removeAt(java.lang.String[] arr, int index)
          Given a String array and an index, return a String array with the element at the specified index removed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayUtils

public ArrayUtils()
Method Detail

append

public static java.lang.String[] append(java.lang.String[] oldarray,
                                        java.lang.String newelem)
The language supports an overloaded '+' operator for Strings, but you can't do the same thing with an array. Some arrays (like String[]) are used often enough to merit a separate utility.


append

public static long[] append(long[] oldarray,
                            long newelem)
The language supports an overloaded '+' operator for Strings, but you can't do the same thing with an array. Some arrays (like long[]) are used often enough to merit a separate utility.


append

public static SandMessage[] append(SandMessage[] oldarray,
                                   SandMessage newelem)
The language supports an overloaded '+' operator for Strings, but you can't do the same thing with an array. Some arrays (like SandMessage[]) are used often enough to merit a separate utility.


conc

public static SandMessage[] conc(SandMessage[] first,
                                 SandMessage[] second)
Concatenate the two arrays, returning a new array.


diff

public static long[] diff(long[] newvals,
                          long[] oldvals)
Returns an array of all values in newvals that are not found in oldvals.


intersect

public static long[] intersect(long[] array1,
                               long[] array2)
Return only the values that occur in both array1 and array2


contains

public static boolean contains(int[] arr,
                               int val)
Return true if the array contains the specified value, false otherwise.


contains

public static boolean contains(long[] arr,
                               long val)
Return true if the array contains the specified value, false otherwise.


contains

public static boolean contains(java.lang.String[] arr,
                               java.lang.String val)
Return true if the array contains the specified value, false otherwise.


contains

public static boolean contains(SandMessage[] arr,
                               SandMessage val)
Return true if the array contains the specified value, false otherwise. Uses the messageEqual method.


indexOf

public static int indexOf(int[] arr,
                          int val)
Return the index of the specified value, or -1 if not found.


indexOf

public static int indexOf(long[] arr,
                          long val)
Return the index of the specified value, or -1 if not found.


indexOf

public static int indexOf(java.lang.String[] arr,
                          java.lang.String val)
Return the index of the specified value, or -1 if not found.


indexOf

public static int indexOf(SandMessage[] arr,
                          SandMessage val)
Return the index of the specified value, or -1 if not found.


remove

public static int[] remove(int[] arr,
                           int val)
Given an int array and an int value, return an int array with the first instance of that value removed.


remove

public static int[] remove(int[] arr,
                           int val,
                           int[] work)
Given an int array and an int value, return an int array with the first instance of that value removed. The work array is an int[] whose length is one element shorter than the original array, which will be used for returned values.


remove

public static long[] remove(long[] arr,
                            long val)
Given a long array and a long value, return a long array with the first instance of that value removed.


remove

public static long[] remove(long[] arr,
                            long val,
                            long[] work)
Given a long array and a long value, return a long array with the first instance of that value removed. The work array is a long[] whose length is one element shorter than the original array, which will be used for returned values.


removeAt

public static java.lang.String[] removeAt(java.lang.String[] arr,
                                          int index)
Given a String array and an index, return a String array with the element at the specified index removed.


remove

public static java.lang.String[] remove(java.lang.String[] arr,
                                        java.lang.String val)
Given a String array and a String value, return a String array with the first instance of that value removed.


remove

public static java.lang.String[] remove(java.lang.String[] arr,
                                        java.lang.String val,
                                        java.lang.String[] work)
Given a String array and a String value, return a String array with the first instance of that value removed. The work array is a String[] whose length is one element shorter than the original array, which will be used for returned values.


remove

public static SandMessage[] remove(SandMessage[] arr,
                                   SandMessage val,
                                   SandMessage[] work)
Given a SandMessage array and value, return a SandMessage array with the first instance of that value removed. The work array is an array of the appropriate object type whose length is one less than the source array. This method will either return the original array (if it does not contain the specified value), or it will return the work array containing the values of the original array but with without the first instance of the value.


remove

public static SandUpdateMessage[] remove(SandUpdateMessage[] sums,
                                         int index)
Return a new SandUpdateMessage array with the element at the given index removed.


longToString

public static java.lang.String[] longToString(long[] vals)
Convert the given array of long values to an array of string values.


messageEqual

public static boolean messageEqual(SandMessage sm1,
                                   SandMessage sm2)
Returns true if the two messages refer to the same instance, false otherwise. If both instances are null, then this returns true. Otherwise if the two instances are both SandPersistMessages, and their uniqueIDs are the same, then this returns true. Otherwise if sm1.isEquivalent(sm2), then this method returns true. Otherwise this method returns false.