mckay.utilities.staticlibraries
Class ArrayMethods

java.lang.Object
  extended by mckay.utilities.staticlibraries.ArrayMethods

public class ArrayMethods
extends java.lang.Object

A holder class for general static methods that can be used for processing arrays.


Constructor Summary
ArrayMethods()
           
 
Method Summary
static java.lang.String[] castArrayAsStrings(java.lang.Object[] to_cast)
          Returns the given array of Objects as an array of Strings.
static java.lang.Object[] concatenateArray(java.lang.Object[] array_1, java.lang.Object[] array_2)
          Returns a new array whose first part consists of the elements of array_1 and whose second part consists of the elements of array_2.
static java.lang.Object[] getCopyOfArray(java.lang.Object[] given_array)
          Returns a copy of the given array.
static java.lang.Object[] insertIntoArray(java.lang.Object[] original, java.lang.Object[] to_insert, int index_to_insert_at, boolean delete_index_inserted_at)
          Take the given original array and return a copy of it with the elements of to_insert inserted at the index_to_insert_at index of the original array.
static java.lang.Object[] removeNullEntriesFromArray(java.lang.Object[] array)
          Returns a shortened array, with all entries that were set to null removed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayMethods

public ArrayMethods()
Method Detail

removeNullEntriesFromArray

public static java.lang.Object[] removeNullEntriesFromArray(java.lang.Object[] array)
Returns a shortened array, with all entries that were set to null removed. Returns null if the resulting array has no valid entries or if the given array has no valid entries.

Parameters:
array - The array to remove null entries from.
Returns:
A shortened array with all null entries removed, or null.

getCopyOfArray

public static java.lang.Object[] getCopyOfArray(java.lang.Object[] given_array)
Returns a copy of the given array. Note that the entries are copied by reference.

Parameters:
given_array - The array to copy
Returns:
A copy of the given array.

concatenateArray

public static java.lang.Object[] concatenateArray(java.lang.Object[] array_1,
                                                  java.lang.Object[] array_2)
Returns a new array whose first part consists of the elements of array_1 and whose second part consists of the elements of array_2.

Parameters:
array_1 - The first array to concatenate.
array_2 - The second array to concatenate.
Returns:
array_1 and array_2 combined into 1 array.

insertIntoArray

public static java.lang.Object[] insertIntoArray(java.lang.Object[] original,
                                                 java.lang.Object[] to_insert,
                                                 int index_to_insert_at,
                                                 boolean delete_index_inserted_at)
Take the given original array and return a copy of it with the elements of to_insert inserted at the index_to_insert_at index of the original array. The element originally present at original[index_to_insert_at] is deleted if delete_index_inserted_at is true. The returned array thus has size original.length + index_to_insert_at.length (- 1 if delete_index_inserted_at is true).

Parameters:
original - The array to insert elements into.
to_insert - The array whose elements are to be inserted.
index_to_insert_at - The index of original to begin inserting the elements of to_insert at.
delete_index_inserted_at - Whether to delete the element originally at the index_to_insert_at index of original.
Returns:
A copy of original of a larger size with the elements inserted.

castArrayAsStrings

public static java.lang.String[] castArrayAsStrings(java.lang.Object[] to_cast)
Returns the given array of Objects as an array of Strings.

Parameters:
to_cast - The array to cast.
Returns:
The String[] version of to_cast.