edu.stanford.nlp.util
Class ArrayUtils

java.lang.Object
  extended by edu.stanford.nlp.util.ArrayUtils

public class ArrayUtils
extends Object

Static utility methods for operating on arrays.

Author:
Huy Nguyen (htnguyen@cs.stanford.edu)

Constructor Summary
protected ArrayUtils()
          Should not be instantiated
 
Method Summary
static
<T> Set<T>
asSet(T[] a)
          Return a set containing the same elements as the specified array.
static
<T> boolean
contains(T[] a, T o)
          Returns true iff object o equals (not ==) some element of array a.
static boolean equalContents(int[][] xs, int[][] ys)
          Tests two int[][] arrays for having equal contents.
static boolean equalContents(int[] xs, int[] ys)
          tests two int[] arrays for having equal contents
static boolean equals(boolean[][] xs, boolean[][] ys)
          Tests two boolean[][] arrays for having equal contents.
static double[] flatten(double[][] array)
           
static void main(String[] args)
          For internal debugging purposes only
static double[] removeAt(double[] array, int index)
          Removes the element at the specified index from the array, and returns a new array containing the remaining elements.
static Object[] removeAt(Object[] array, int index)
          Removes the element at the specified index from the array, and returns a new array containing the remaining elements.
static double[][] to2D(double[] array, int dim1Size)
           
static double[][] to2D(double[] array, int dim1Size, int dim2Size)
           
static String toString(boolean[][] b)
           
static String toString(int[][] a)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayUtils

protected ArrayUtils()
Should not be instantiated

Method Detail

flatten

public static double[] flatten(double[][] array)

to2D

public static double[][] to2D(double[] array,
                              int dim1Size)

to2D

public static double[][] to2D(double[] array,
                              int dim1Size,
                              int dim2Size)

removeAt

public static double[] removeAt(double[] array,
                                int index)
Removes the element at the specified index from the array, and returns a new array containing the remaining elements. If index is invalid, returns array unchanged.


removeAt

public static Object[] removeAt(Object[] array,
                                int index)
Removes the element at the specified index from the array, and returns a new array containing the remaining elements. If index is invalid, returns array unchanged. Uses reflection to determine the type of the array and returns an array of the appropriate type.


toString

public static String toString(int[][] a)

equalContents

public static boolean equalContents(int[][] xs,
                                    int[][] ys)
Tests two int[][] arrays for having equal contents.

Parameters:
xs -
ys -
Returns:
true iff for each i, equalContents(xs[i],ys[i]) is true

equalContents

public static boolean equalContents(int[] xs,
                                    int[] ys)
tests two int[] arrays for having equal contents

Parameters:
xs -
ys -
Returns:
true iff xs and ys have equal length, and for each i, xs[i]==ys[i]

equals

public static boolean equals(boolean[][] xs,
                             boolean[][] ys)
Tests two boolean[][] arrays for having equal contents.

Parameters:
xs -
ys -
Returns:
true iff for each i, Arrays.equals(xs[i],ys[i]) is true

contains

public static <T> boolean contains(T[] a,
                                   T o)
Returns true iff object o equals (not ==) some element of array a.


asSet

public static <T> Set<T> asSet(T[] a)
Return a set containing the same elements as the specified array.


main

public static void main(String[] args)
For internal debugging purposes only


toString

public static String toString(boolean[][] b)


Stanford NLP Group