moj.util
Class ArrayTools

java.lang.Object
  extended by moj.util.ArrayTools

public final class ArrayTools
extends java.lang.Object

A small utility class that contains methods for converting between strings and arrays, as well as increasing and decreasing the size of arrays.

Version:
2007-Sept-13
Author:
Martin Hassel

Constructor Summary
ArrayTools()
           
 
Method Summary
static void addAll(java.util.Collection<java.lang.Object> collection, java.lang.Object[] array)
          Adds all objects in array to collection.
static java.lang.String join(byte[] array, java.lang.String fieldSeparator)
          Converts a array of numbers into a String.
static java.lang.String join(double[] array, java.lang.String fieldSeparator)
          Converts a array of reals into a String.
static java.lang.String join(float[] array, java.lang.String fieldSeparator)
          Converts a array of reals into a String.
static java.lang.String join(int[] array, java.lang.String fieldSeparator)
          Converts a array of numbers into a String.
static java.lang.String join(long[] array, java.lang.String fieldSeparator)
          Converts a array of numbers into a String.
static java.lang.String join(java.lang.Object[] array, java.lang.String fieldSeparator)
          Converts an array of Objects into a String.
static java.lang.String join(short[] array, java.lang.String fieldSeparator)
          Converts a array of numbers into a String.
static char[] resize(char[] a, int newSize)
          Resizes an array of chars.
static double[] resize(double[] a, int newSize)
          Resizes an array of doubles.
static float[] resize(float[] a, int newSize)
          Resizes an array of floats.
static int[] resize(int[] a, int newSize)
          Resizes an array of ints.
static long[] resize(long[] a, int newSize)
          Resizes an array of longs.
static java.lang.Object[] resize(java.lang.Object[] a, int newSize)
          Resizes an array of Objects.
static short[] resize(short[] a, int newSize)
          Resizes an array of shorts.
static byte[] setSize(byte[] a, int newSize)
          Resizes an array of bytes.
static byte[] splitBytes(java.lang.String str, java.lang.String fieldSeparator)
          Converts a string of numbers to a byte array.
static double[] splitDoubles(java.lang.String str, java.lang.String fieldSeparator)
          Convert a string of reals to a double array.
static float[] splitFloats(java.lang.String str, java.lang.String fieldSeparator)
          Convert a string of reals to a float array.
static int[] splitInts(java.lang.String str, java.lang.String fieldSeparator)
          Converts a string of numbers to an integer array
static long[] splitLongs(java.lang.String str, java.lang.String fieldSeparator)
          Converts a string of numbers to a long array
static short[] splitShorts(java.lang.String str, java.lang.String fieldSeparator)
          Converts a string of numbers to a short array
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayTools

public ArrayTools()
Method Detail

splitBytes

public static byte[] splitBytes(java.lang.String str,
                                java.lang.String fieldSeparator)
Converts a string of numbers to a byte array. Observe that a byte ranges from -127 to 127

Parameters:
str - String of numbers to convert
fieldSeparator - String that separates each number
Returns:
an array of bytes

splitShorts

public static short[] splitShorts(java.lang.String str,
                                  java.lang.String fieldSeparator)
Converts a string of numbers to a short array

Parameters:
str - String of numbers to convert
fieldSeparator - String that separates each number
Returns:
an array of shorts

splitInts

public static int[] splitInts(java.lang.String str,
                              java.lang.String fieldSeparator)
Converts a string of numbers to an integer array

Parameters:
str - String of numbers to convert
fieldSeparator - String that separates each number
Returns:
an array of integers

splitLongs

public static long[] splitLongs(java.lang.String str,
                                java.lang.String fieldSeparator)
Converts a string of numbers to a long array

Parameters:
str - String of numbers to convert
fieldSeparator - String that separates each number
Returns:
an array of shorts

splitFloats

public static float[] splitFloats(java.lang.String str,
                                  java.lang.String fieldSeparator)
Convert a string of reals to a float array.

Parameters:
str - String of numbers to convert
fieldSeparator - String that separates each number
Returns:
an array of floats

splitDoubles

public static double[] splitDoubles(java.lang.String str,
                                    java.lang.String fieldSeparator)
Convert a string of reals to a double array.

Parameters:
str - String of numbers to convert
fieldSeparator - String that separates each number
Returns:
an array of doubles

setSize

public static byte[] setSize(byte[] a,
                             int newSize)
Resizes an array of bytes. If the new size is smaller only newSize elements will be copied.

Parameters:
a - the original array
newSize - the size of the new array
Returns:
a new array with the original elements in a copied to it

resize

public static char[] resize(char[] a,
                            int newSize)
Resizes an array of chars. If the new size is smaller only newSize elements will be copied.

Parameters:
a - the original array
newSize - the size of the new array
Returns:
a new array with the original elements in a copied to it

resize

public static short[] resize(short[] a,
                             int newSize)
Resizes an array of shorts. If the new size is smaller only newSize elements will be copied.

Parameters:
a - the original array
newSize - the size of the new array
Returns:
a new array with the original elements in a copied to it

resize

public static int[] resize(int[] a,
                           int newSize)
Resizes an array of ints. If the new size is smaller only newSize elements will be copied.

Parameters:
a - the original array
newSize - the size of the new array
Returns:
a new array with the original elements in a copied to it

resize

public static long[] resize(long[] a,
                            int newSize)
Resizes an array of longs. If the new size is smaller only newSize elements will be copied.

Parameters:
a - the original array
newSize - the size of the new array
Returns:
a new array with the original elements in a copied to it

resize

public static float[] resize(float[] a,
                             int newSize)
Resizes an array of floats. If the new size is smaller only newSize elements will be copied.

Parameters:
a - the original array
newSize - the size of the new array
Returns:
a new array with the original elements in a copied to it

resize

public static double[] resize(double[] a,
                              int newSize)
Resizes an array of doubles. If the new size is smaller only newSize elements will be copied.

Parameters:
a - the original array
newSize - the size of the new array
Returns:
a new array with the original elements in a copied to it

resize

public static java.lang.Object[] resize(java.lang.Object[] a,
                                        int newSize)
Resizes an array of Objects. If the new size is smaller overflowing elements will be discarded.

Parameters:
a - the original array
newSize - the size of the new array
Returns:
a new array with the original elements in a copied to it

join

public static java.lang.String join(byte[] array,
                                    java.lang.String fieldSeparator)
Converts a array of numbers into a String.

Parameters:
array - the array to convert
fieldSeparator - string that separates each element
Returns:
a String representation of the array

join

public static java.lang.String join(short[] array,
                                    java.lang.String fieldSeparator)
Converts a array of numbers into a String.

Parameters:
array - the array to convert
fieldSeparator - string that separates each element
Returns:
a String representation of the array

join

public static java.lang.String join(int[] array,
                                    java.lang.String fieldSeparator)
Converts a array of numbers into a String.

Parameters:
array - the array to convert
fieldSeparator - string that separates each element
Returns:
a String representation of the array

join

public static java.lang.String join(long[] array,
                                    java.lang.String fieldSeparator)
Converts a array of numbers into a String.

Parameters:
array - the array to convert
fieldSeparator - string that separates each element
Returns:
a String representation of the array

join

public static java.lang.String join(float[] array,
                                    java.lang.String fieldSeparator)
Converts a array of reals into a String.

Parameters:
array - the array to convert
fieldSeparator - string that separates each element
Returns:
a String representation of the array

join

public static java.lang.String join(double[] array,
                                    java.lang.String fieldSeparator)
Converts a array of reals into a String.

Parameters:
array - the array to convert
fieldSeparator - string that separates each element
Returns:
a String representation of the array

join

public static java.lang.String join(java.lang.Object[] array,
                                    java.lang.String fieldSeparator)
Converts an array of Objects into a String.

Parameters:
array - the array to convert
fieldSeparator - string that separates each element
Returns:
a String representation of the array

addAll

public static void addAll(java.util.Collection<java.lang.Object> collection,
                          java.lang.Object[] array)
Adds all objects in array to collection.

Parameters:
collection - Collection to add objects to
array - array of objects to be added