org.basex.util
Class Array

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

public final class Array
extends java.lang.Object

This class provides convenience methods for handling arrays and serves as an extension to the Arrays class of Java.

Author:
BaseX Team 2005-12, BSD License, Christian Gruen

Field Summary
static int CAPACITY
          Initial default size for new arrays.
static double RESIZE
          Default factor for resizing dynamic arrays.
 
Method Summary
static int[] add(int[] ar, int e)
          Adds an entry to the end of an array and returns the new array.
static
<T> T[]
add(T[] ar, T e)
          Adds an entry to the end of an array and returns the new array.
static
<T> T[]
copy(java.lang.Object[] source, T[] target)
          Copies entries from one array to another.
static byte[][] copyOf(byte[][] a, int s)
          Copies the specified array.
static int[][] copyOf(int[][] a, int s)
          Copies the specified array.
static java.lang.String[] copyOf(java.lang.String[] a, int s)
          Copies the specified array.
static int[] createOrder(byte[][] vals, boolean num, boolean asc)
          Sorts the specified tokens and returns an integer array with offsets to the sorted tokens.
static int[] createOrder(double[] vals, boolean asc)
          Sorts the specified doubles and returns an integer array with offsets to the sorted doubles.
static int[] createOrder(int[] vals, boolean asc)
          Sorts the specified integers and returns an integer array with offsets to the sorted integers.
static
<T> T[]
delete(T[] ar, int p)
          Removes an array entry at the specified position.
static void move(java.lang.Object ar, int pos, int off, int l)
          Moves entries inside an array.
static int newSize(int old)
          Returns a value for a new array size, which will always be larger than the specified value.
static int newSize(int old, double factor)
          Returns a value for a new array size, which will always be larger than the specified value.
static void reverse(byte[] arr)
          Reverses the order of the elements in the given array.
static void reverse(java.lang.Object[] arr, int pos, int len)
          Reverses the order of all elements in the given interval.
static void swap(int[] arr, int a, int b)
          Swaps two entries of the given int array.
static void swap(int[] arr, int a, int b, int n)
          Swaps arr[a ..
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CAPACITY

public static final int CAPACITY
Initial default size for new arrays.

See Also:
Constant Field Values

RESIZE

public static final double RESIZE
Default factor for resizing dynamic arrays.

See Also:
Constant Field Values
Method Detail

copyOf

public static byte[][] copyOf(byte[][] a,
                              int s)
Copies the specified array.

Parameters:
a - array to be copied
s - new array size
Returns:
new array

copyOf

public static int[][] copyOf(int[][] a,
                             int s)
Copies the specified array.

Parameters:
a - array to be copied
s - new array size
Returns:
new array

copyOf

public static java.lang.String[] copyOf(java.lang.String[] a,
                                        int s)
Copies the specified array.

Parameters:
a - array to be copied
s - new array size
Returns:
new array

add

public static <T> T[] add(T[] ar,
                          T e)
Adds an entry to the end of an array and returns the new array.

Type Parameters:
T - array type
Parameters:
ar - array to be resized
e - entry to be added
Returns:
array

add

public static int[] add(int[] ar,
                        int e)
Adds an entry to the end of an array and returns the new array.

Parameters:
ar - array to be resized
e - entry to be added
Returns:
array

move

public static void move(java.lang.Object ar,
                        int pos,
                        int off,
                        int l)
Moves entries inside an array.

Parameters:
ar - array
pos - position
off - move offset
l - length

copy

public static <T> T[] copy(java.lang.Object[] source,
                           T[] target)
Copies entries from one array to another.

Type Parameters:
T - object type
Parameters:
source - source array
target - target array
Returns:
object

delete

public static <T> T[] delete(T[] ar,
                             int p)
Removes an array entry at the specified position.

Type Parameters:
T - array type
Parameters:
ar - array to be resized
p - position
Returns:
array

createOrder

public static int[] createOrder(byte[][] vals,
                                boolean num,
                                boolean asc)
Sorts the specified tokens and returns an integer array with offsets to the sorted tokens.

Parameters:
vals - values to sort by
num - numeric sort
asc - ascending
Returns:
array containing the order

createOrder

public static int[] createOrder(double[] vals,
                                boolean asc)
Sorts the specified doubles and returns an integer array with offsets to the sorted doubles.

Parameters:
vals - values to sort by
asc - ascending
Returns:
array containing the order

createOrder

public static int[] createOrder(int[] vals,
                                boolean asc)
Sorts the specified integers and returns an integer array with offsets to the sorted integers.

Parameters:
vals - values to sort by
asc - ascending
Returns:
array containing the order

reverse

public static void reverse(byte[] arr)
Reverses the order of the elements in the given array.

Parameters:
arr - array

reverse

public static void reverse(java.lang.Object[] arr,
                           int pos,
                           int len)
Reverses the order of all elements in the given interval.

Parameters:
arr - array
pos - position of first element of the interval
len - length of the interval

newSize

public static int newSize(int old)
Returns a value for a new array size, which will always be larger than the specified value.

Parameters:
old - old size
Returns:
resulting size

newSize

public static int newSize(int old,
                          double factor)
Returns a value for a new array size, which will always be larger than the specified value.

Parameters:
old - old size
factor - resize factor; must be larger than or equal to 1
Returns:
resulting size

swap

public static void swap(int[] arr,
                        int a,
                        int b)
Swaps two entries of the given int array.

Parameters:
arr - array
a - first position
b - second position

swap

public static void swap(int[] arr,
                        int a,
                        int b,
                        int n)
Swaps arr[a .. (a+n-1)] with arr[b .. (b+n-1)].

Parameters:
arr - order array
a - first offset
b - second offset
n - number of values