org.planx.util
Class Array

java.lang.Object
  extended by org.planx.util.Array

public final class Array
extends Object

Author:
Kasper Bøgebjerg, Henning Niss, Thomas Ambus

Method Summary
static
<E> List<E>
asUnmodifiableList(E[] arr)
           
static int compareTo(byte[] b1, byte[] b2)
          Compare to arrays (according to the Comparable.compareTo comparison convention) lexicographically.
static byte[] ensureCapacity(byte[] arr, int size, int minCapacity)
          See ensureCapacity(int[],int,int).
static CharSequence[][] ensureCapacity(CharSequence[][] arr, int size, int minCapacity)
          See ensureCapacity(int[],int,int).
static CharSequence[] ensureCapacity(CharSequence[] arr, int size, int minCapacity)
          See ensureCapacity(int[],int,int).
static int[][] ensureCapacity(int[][] arr, int size, int minCapacity)
          See ensureCapacity(int[],int,int).
static int[] ensureCapacity(int[] arr, int size, int minCapacity)
          Takes an array as argument and returns an array containing the same elements, but where it is ensured that the array can contain the specified minimum number of elements.
static List[] ensureCapacity(List[] arr, int size, int minCapacity)
          See ensureCapacity(int[],int,int).
static Object[] ensureCapacity(Object[] arr, int size, int minCapacity)
          See ensureCapacity(int[],int,int).
static int indexOf(byte[] array, byte value, int off, int len)
          Find the first occurrence of a value in an array starting from the offset and looking no further than offset plus the length.
static byte[] setLength(byte[] arr, int length)
          See setLength(int[], int).
static int[] setLength(int[] arr, int length)
          Sets the length of the array to the specified length.
static
<E> List<E>
unmodifiableCopy(E[] arr)
           
static
<E> List<E>
unmodifiableCopy(List<E> list)
          Returns a shallow, immutable copy of the specified List.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

indexOf

public static int indexOf(byte[] array,
                          byte value,
                          int off,
                          int len)
Find the first occurrence of a value in an array starting from the offset and looking no further than offset plus the length.

Parameters:
array - the array to search in
value - the value to look for
off - the offset to start at
len - the maximal length to search through
Returns:
the index of the value if found in array[off..off+len-1], -1 otherwise.

compareTo

public static int compareTo(byte[] b1,
                            byte[] b2)
Compare to arrays (according to the Comparable.compareTo comparison convention) lexicographically.

Parameters:
b1 - first array to compare
b2 - second array to compare
Returns:
0 if the arrays are identical, a negative integer if b1 is lexicographically smaller than b2, a positive integer 1 if b2 is lexicographically larger than b2.

ensureCapacity

public static int[] ensureCapacity(int[] arr,
                                   int size,
                                   int minCapacity)
Takes an array as argument and returns an array containing the same elements, but where it is ensured that the array can contain the specified minimum number of elements. The size is the current number of used slots in the array, and minCapacity is the minimum number of slots required. If the length of the array is lower or equal to minCapacity, the same array arr is returned. Otherwise, a new array is allocated and the size first elements of arr is copied to the new array. The length of the new array is not specified, other than it is larger than minCapacity.

Typical use, given an Iterator variable it:

     int size = 0;
     int[] arr = new int[10];
     while (it.hasNext()) {
         arr = Array.ensureCapacity(arr, size, size+1);
         arr[size++] = it.next().hashCode();
     }
 


ensureCapacity

public static int[][] ensureCapacity(int[][] arr,
                                     int size,
                                     int minCapacity)
See ensureCapacity(int[],int,int).


ensureCapacity

public static byte[] ensureCapacity(byte[] arr,
                                    int size,
                                    int minCapacity)
See ensureCapacity(int[],int,int).


ensureCapacity

public static CharSequence[] ensureCapacity(CharSequence[] arr,
                                            int size,
                                            int minCapacity)
See ensureCapacity(int[],int,int).


ensureCapacity

public static CharSequence[][] ensureCapacity(CharSequence[][] arr,
                                              int size,
                                              int minCapacity)
See ensureCapacity(int[],int,int).


ensureCapacity

public static List[] ensureCapacity(List[] arr,
                                    int size,
                                    int minCapacity)
See ensureCapacity(int[],int,int).


ensureCapacity

public static Object[] ensureCapacity(Object[] arr,
                                      int size,
                                      int minCapacity)
See ensureCapacity(int[],int,int).


setLength

public static int[] setLength(int[] arr,
                              int length)
Sets the length of the array to the specified length. If the array already has this length, it is simply returned. If the array is larger than this length, the first length elements is copied into a new array with the specified length. If the array is smaller than this length, all elements are copied into the beginning of a new array with the specified length.


setLength

public static byte[] setLength(byte[] arr,
                               int length)
See setLength(int[], int).


unmodifiableCopy

public static <E> List<E> unmodifiableCopy(List<E> list)
Returns a shallow, immutable copy of the specified List.


unmodifiableCopy

public static <E> List<E> unmodifiableCopy(E[] arr)

asUnmodifiableList

public static <E> List<E> asUnmodifiableList(E[] arr)


Copyright © 2010. All Rights Reserved.