org.exist.util
Class ArrayUtils

java.lang.Object
  extended by org.exist.util.ArrayUtils

public class ArrayUtils
extends Object

Utility methods to have indexed access for insertion and deletion of array items. Based on original code from dbXML.


Constructor Summary
ArrayUtils()
           
 
Method Summary
static int binarySearch(int[] a, int key, int size)
          Searches the specified array of ints for the specified value using the binary search algorithm.
static int[] deleteArrayInt(int[] vals, int idx)
          Delete an integer.
static long[] deleteArrayLong(long[] vals, int idx)
          Delete a long.
static short[] deleteArrayShort(short[] vals, int idx)
          Delete a short.
static int[] insertArrayInt(int[] vals, int val, int idx)
          Insert a integer.
static long[] insertArrayLong(long[] vals, long val, int idx)
          Insert a long.
static short[] insertArrayShort(short[] vals, short val, int idx)
          Insert a short.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayUtils

public ArrayUtils()
Method Detail

deleteArrayInt

public static int[] deleteArrayInt(int[] vals,
                                   int idx)
Delete an integer.

Parameters:
vals - array of integers
idx - index of integer to delete
Returns:
the array without the deleted integer

deleteArrayLong

public static long[] deleteArrayLong(long[] vals,
                                     int idx)
Delete a long.

Parameters:
vals - array of longs
idx - index of long to delete
Returns:
the array without the deleted long

deleteArrayShort

public static short[] deleteArrayShort(short[] vals,
                                       int idx)
Delete a short.

Parameters:
vals - array of shorts
idx - index of short to delete
Returns:
the array without the deleted short

insertArrayInt

public static int[] insertArrayInt(int[] vals,
                                   int val,
                                   int idx)
Insert a integer.

Parameters:
vals - array of integers
val - integer to insert
idx - index of insertion
Returns:
the array with added integer

insertArrayLong

public static long[] insertArrayLong(long[] vals,
                                     long val,
                                     int idx)
Insert a long.

Parameters:
vals - array of longs
val - long to insert
idx - index of insertion
Returns:
the array with added long

insertArrayShort

public static short[] insertArrayShort(short[] vals,
                                       short val,
                                       int idx)
Insert a short.

Parameters:
vals - array of shorts
val - short to insert
idx - index of insertion
Returns:
the array with added short

binarySearch

public static int binarySearch(int[] a,
                               int key,
                               int size)
Searches the specified array of ints for the specified value using the binary search algorithm. The array must be sorted (as by the sort method, above) prior to making this call. If it is not sorted, the results are undefined. If the array contains multiple elements with the specified value, there is no guarantee which one will be found.

Parameters:
a - the array to be searched.
key - the value to be searched for.
Returns:
index of the search key, if it is contained in the list; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the list: the index of the first element greater than the key, or list.size(), if all elements in the list are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.


Copyright (C) Wolfgang Meier. All rights reserved.