etomica.util
Class Arrays

java.lang.Object
  extended by etomica.util.Arrays

public final class Arrays
extends Object

Non-instantiable class with static utility methods for working with arrays.


Method Summary
static Object[] addObject(Object[] objects, Object newObject)
          Returns an array formed from adding the newObject to the elements in the given array.
static Object[] removeObject(Object[] array, Object object)
          Returns an array formed by removing the given object from the given array.
static boolean[] resizeArray(boolean[] oldArray, int newSize)
          Returns a new array holding the values in the given array, but adjusted to the given size.
static double[] resizeArray(double[] oldArray, int newSize)
          Returns a new array holding the values in the given array, but adjusted to the given size.
static int[] resizeArray(int[] oldArray, int newSize)
          Returns a new array holding the values in the given array, but adjusted to the given size.
static Object[] resizeArray(Object[] oldArray, int newSize)
          Returns a new array holding the objects in the given array, but adjusted to the given size.
static LinkedList toList(Object[] obj)
          Creates a new LinkedList filled with the elements of the given array, in the same order.
static String toString(boolean[] array)
          Converts the given array of booleans into a string with a comma-separated list of the booleans enclosed by braces.
static String toString(double[] array)
          Converts the given array of doubles into a string with a comma-separated list of the doubles enclosed by braces.
static String toString(float[] array)
          Converts the given array of floats into a string with a comma-separated list of the floats enclosed by braces.
static String toString(int[] array)
          Converts the given array of integers into a string with a comma-separated list of the integers enclosed by braces.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

resizeArray

public static Object[] resizeArray(Object[] oldArray,
                                   int newSize)
Returns a new array holding the objects in the given array, but adjusted to the given size. If the new size is greater than the given array, all elements of the array are copied to the new array, starting from index 0 (with unfilled elements of new array left as null); if the new size is smaller than the given array, elements of the old array (starting from 0) will be copied to fill the new array. New array is of the same type as the old one (returned array must be cast before assigning to a field of the same type as the old array).

Parameters:
oldArray - array with elements to be copied to the new array
newSize - size of the new array
Returns:
the new array

resizeArray

public static double[] resizeArray(double[] oldArray,
                                   int newSize)
Returns a new array holding the values in the given array, but adjusted to the given size. If the new size is greater than the given array, all elements of the array are copied to the new array, starting from index 0 (with unfilled elements of new array left as zero); if the new size is smaller than the given array, elements of the old array (starting from 0) will be copied to fill the new array.

Parameters:
oldArray - array with elements to be copied to the new array
newSize - size of the new array
Returns:
the new array

resizeArray

public static int[] resizeArray(int[] oldArray,
                                int newSize)
Returns a new array holding the values in the given array, but adjusted to the given size. If the new size is greater than the given array, all elements of the array are copied to the new array, starting from index 0 (with unfilled elements of new array left as zero); if the new size is smaller than the given array, elements of the old array (starting from 0) will be copied to fill the new array.

Parameters:
oldArray - array with elements to be copied to the new array
newSize - size of the new array
Returns:
the new array

resizeArray

public static boolean[] resizeArray(boolean[] oldArray,
                                    int newSize)
Returns a new array holding the values in the given array, but adjusted to the given size. If the new size is greater than the given array, all elements of the array are copied to the new array, starting from index 0 (with unfilled elements of new array left as false); if the new size is smaller than the given array, elements of the old array (starting from 0) will be copied to fill the new array.

Parameters:
oldArray - array with elements to be copied to the new array
newSize - size of the new array
Returns:
the new array

addObject

public static Object[] addObject(Object[] objects,
                                 Object newObject)
Returns an array formed from adding the newObject to the elements in the given array. New array is one element larger than given array, and is of same type as given array. newObject is placed at the end of the new array.

Parameters:
objects - array with objects to be put in new array
newObject - object placed at end of new array
Returns:
new array

removeObject

public static Object[] removeObject(Object[] array,
                                    Object object)
Returns an array formed by removing the given object from the given array. New array is one element smaller than given array, and is of same type as given array. Order of objects in the new array is unchanged from their order in the original array. If object is not in the given array, method returns original array without performing any action.

Parameters:
array - array with the objects
newObject - object being removed
Returns:
new array with the object removed

toString

public static String toString(int[] array)
Converts the given array of integers into a string with a comma-separated list of the integers enclosed by braces. Null argument or empty array are converted to the string "{}".


toString

public static String toString(double[] array)
Converts the given array of doubles into a string with a comma-separated list of the doubles enclosed by braces. Null argument or empty array are converted to the string "{}".


toString

public static String toString(float[] array)
Converts the given array of floats into a string with a comma-separated list of the floats enclosed by braces. Null argument or empty array are converted to the string "{}".


toString

public static String toString(boolean[] array)
Converts the given array of booleans into a string with a comma-separated list of the booleans enclosed by braces. Null argument or empty array are converted to the string "{}".


toList

public static LinkedList toList(Object[] obj)
Creates a new LinkedList filled with the elements of the given array, in the same order.