fulmine.util.array
Class ArrayUtils

java.lang.Object
  extended by fulmine.util.array.ArrayUtils

public abstract class ArrayUtils
extends Object

A utility class exposing utility methods for handling arrays.

Author:
Ramon Servadei

Constructor Summary
ArrayUtils()
           
 
Method Summary
static int indexOf(byte[] subArray, byte[] array)
          Find the index of a sub-array within another array
static byte[] merge(byte[] first, byte[] second)
          Merge two arrays to form one.
static void resize(byte[][] array, int extraSize)
          Resize array[0] to allow space for extraSize more elements.
static void resize(int[][] array, int extraSize)
          Resize array[0] to allow space for extraSize more elements.
static void resize(String[][] array, int extraSize)
          Resize array[0] to allow space for extraSize more elements.
static void resizeIfNeeded(byte[][] array, int requiredSize)
          If array[0] does not have requiredSize elements, then resize array[0] to allow requiredSize elements.
static void resizeIfNeeded(int[][] array, int requiredSize)
          If array[0] does not have requiredSize elements, then resize array[0] to allow requiredSize elements.
static void resizeIfNeeded(String[][] array, int requiredSize)
          If array[0] does not have requiredSize elements, then resize array[0] to allow requiredSize elements.
static boolean startsWith(byte[] subArray, byte[] array)
          Determine if the array starts with the sub-array
static void trim(byte[][] array, int length)
          Trim the array[0] to the given length.
static void trim(int[][] array, int length)
          Trim the array[0] to the given length.
static void trim(String[][] array, int length)
          Trim the array[0] to the given length.
 
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

resize

public static void resize(byte[][] array,
                          int extraSize)
Resize array[0] to allow space for extraSize more elements. All data in array[0] is retained.

Parameters:
array - array[0] to resize
extraSize - the extra space to add to array[0]

resize

public static void resize(String[][] array,
                          int extraSize)
Resize array[0] to allow space for extraSize more elements. All data in array[0] is retained.

Parameters:
array - array[0] to resize
extraSize - the extra space to add to array[0]

trim

public static void trim(byte[][] array,
                        int length)
Trim the array[0] to the given length. All data upto length, exclusive, is retained in array[0]

Parameters:
array - array[0] to trim
length - the new length for array[0]

trim

public static void trim(String[][] array,
                        int length)
Trim the array[0] to the given length. All data upto length, exclusive, is retained in array[0]

Parameters:
array - array[0] to trim
length - the new length for array[0]

resize

public static void resize(int[][] array,
                          int extraSize)
Resize array[0] to allow space for extraSize more elements. All data in array[0] is retained.

Parameters:
array - array[0] to resize
extraSize - the extra space to add to array[0]

trim

public static void trim(int[][] array,
                        int length)
Trim the array[0] to the given length. All data upto length, exclusive, is retained in array[0]

Parameters:
array - array[0] to trim
length - the new length for array[0]

resizeIfNeeded

public static void resizeIfNeeded(byte[][] array,
                                  int requiredSize)
If array[0] does not have requiredSize elements, then resize array[0] to allow requiredSize elements. Existing data is preserved.

Parameters:
array - array[0] to check
requiredSize - the number of elements that array[0] must contain

resizeIfNeeded

public static void resizeIfNeeded(String[][] array,
                                  int requiredSize)
If array[0] does not have requiredSize elements, then resize array[0] to allow requiredSize elements. Existing data is preserved.

Parameters:
array - array[0] to check
requiredSize - the number of elements that array[0] must contain

resizeIfNeeded

public static void resizeIfNeeded(int[][] array,
                                  int requiredSize)
If array[0] does not have requiredSize elements, then resize array[0] to allow requiredSize elements. Existing data is preserved.

Parameters:
array - array[0] to check
requiredSize - the number of elements that array[0] must contain

startsWith

public static boolean startsWith(byte[] subArray,
                                 byte[] array)
Determine if the array starts with the sub-array

Parameters:
subArray - the sub-array to find in the array
array - the array to examine
Returns:
true if array starts with subArray

indexOf

public static int indexOf(byte[] subArray,
                          byte[] array)
Find the index of a sub-array within another array

Parameters:
subArray - the sub-array to find in the array
array - the array to search
Returns:
the index in array where subArray starts, or -1

merge

public static byte[] merge(byte[] first,
                           byte[] second)
Merge two arrays to form one. The returned array contains the two arrays merged together in order.

Parameters:
first - the first array
second - the second array
Returns:
the merged array with the first array contents followed by the second array contents


Copyright © 2007-2009. All Rights Reserved.