Top Description Fields Constructors Methods
org.hsqldb.lib

public final Class ArrayUtil

extends Object
Class Inheritance
Imports
java.lang.reflect.Array, java.util.Arrays

Collection of static methods for operations on arrays
Author
Fred Toussi (fredt@users dot sourceforge.net)
Since
1.7.2
Version
2.7.4

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
private static final IntValueHashMap<Class<T>>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
adjustArray(int
class type of the array
type
,
Object
the array
array
,
int
count of elements of array in use
usedElements
,
int
point at which to add or remove elements
index
,
int
number of elements to add or remove
count
)

Moves the contents of an array to allow both addition and removal of elements.

public static boolean

Returns:

boolean
areAllIntIndexesAsBooleanArray
(int[]
int[]
arra
,
boolean[]
boolean[]
arrb
)

Returns true if all indexes and no other positions are true in arrb.

public static boolean
areAllIntIndexesInBooleanArray(int[] arra, boolean[] arrb)

public static boolean

Returns:

boolean
areEqualSets
(int[]
int[]
arra
,
int[]
int[]
arrb
)

Returns true if arra and arrb contain the same set of integers, not necessarily in the same order.

public static int[]

Returns:

int[]
arraySlice
(int[]
int[]
source
,
int
int
start
,
int
int
count
)

Returns a range of elements of source from start to end of the array.

public static int[]

Returns:

int[]
booleanArrayToIntIndexes
(boolean[]
boolean[]
arrb
)

Set elements of arrb true if their indexes appear in arrb.

public static char[]
byteArrayToChars(byte[] bytes)

public static char[]
byteArrayToChars(byte[] bytes, int bytesLength)

public static long
byteSequenceToLong(byte[] bytes, int pos)

public static int

Returns:

int
cdiv
(int
int
a
,
int
int
b
)

a and b must be both positive returns (a / b) or (a / b) + 1 if remainder is larger than zero

public static long
cdiv(long a, long b)

public static byte[]
charArrayToBytes(char[] chars)

public static byte[]
charArrayToBytes(char[] chars, int length)

public static void
clearArray(int
int
type
,
Object
Object
data
,
int
int
from
,
int
int
to
)

Clears an area of the given array of the given type.

public static int[]

Returns:

int[] common indexes or null if there is no overlap.
commonElements
(int[]
int[] first column indexes
arra
,
int[]
int[] second column indexes
arrb
)

Returns an int[] containing elements shared between the two arrays arra and arrb.

public static int

Returns:

int
compare
(byte[]
byte[]
a
,
byte[]
byte[]
b
)

Compares two arrays.

public static int
compare(byte[] a, int aOffset, int aLength, byte[] b, int bOffset, int bLength)

public static int[]

Returns:

int[]
concat
(int[]
int[]
arra
,
int[]
int[]
arrb
)

Returns an array that contains all the elements of the two arrays.

public static boolean

Returns:

boolean
containsAll
(Object[]
Object[]
arra
,
Object[]
Object[]
arrb
)

returns true if arra contains all elements of arrb

public static boolean

Returns:

boolean
containsAll
(int[]
int[]
arra
,
int[]
int[]
arrb
)

returns true if arra contains all elements of arrb

public static boolean

Returns:

boolean
containsAllAtStart
(int[]
int[]
arra
,
int[]
int[]
arrb
)

returns true if arra contains all elements of arrb at its start

public static boolean

Returns:

boolean
containsAllTrueElements
(boolean[]
boolean[]
arra
,
boolean[]
boolean[]
arrb
)

Return true if for each true element in arrb, the corresponding element in arra is true

public static boolean

Returns:

boolean
containsAny
(Object[]
Object[]
arra
,
Object[]
Object[]
arrb
)

returns true if arra contains any element of arrb

public static boolean

Returns:

boolean
containsAt
(byte[]
byte[]
arra
,
int
int
start
,
byte[]
byte[]
arrb
)

Returns true if arra from position start contains all elements of arrb in sequential order.

public static boolean

Returns:

boolean
containsAt
(char[]
char[]
arra
,
int
int
start
,
char[]
char[]
arrb
)

Returns true if arra from position start contains all elements of arrb in sequential order.

public static void
copyAdjustArray(Object
Object
source
,
Object
Object
dest
,
Object
Object
addition
,
int
int
colindex
,
int
int
adjust
)

For arrays of Objects or primitives.

public static void
copyAdjustArray(Object[]
Object[]
source
,
Object[]
Object[]
dest
,
int[]
int[]
colindex
,
int
int
adjust
)

Similar to single slot adjusted copy, with multiple slots added or removed.

public static void
copyArray(Object
Object
source
,
Object
Object
dest
,
int
int
count
)

Convenience wrapper for System.arraycopy().

public static int

Returns:

int
copyBytes
(long
long
sourceOffset
,
byte[]
byte[]
source
,
int
int
sourceOff
,
int
int
sourceLength
,
long
long
destOffset
,
byte[]
byte[]
dest
,
int
int
destLength
)

Byte arrays source and dest each begin at an offset in the common space.

public static byte[]

Returns:

byte[]
copyBytes
(byte[]
byte[]
source
,
byte[]
byte[]
dest
,
int
int
destOffset
)

Copy the source to dest, returning dest or an enlarged array of result is larger than dest.

public static void
copyMoveSegment(Object source, Object dest, int size, int index, int segmentSize, int destIndex)

public static int

Returns:

int number of elements shared by arra and arrb
countCommonElements
(int[]
int[] first array of column indexes.
arra
,
int[]
int[] second array of column indexes
arrb
)

Returns the number of elements shared between the two arrays containing sets.

public static int
countCommonElements(Object[] arra, int alen, Object[] arrb)

public static int

Returns:

int
countNonStartElementsAt
(byte[]
byte[]
arra
,
int
int
start
,
byte[]
byte[]
arrb
)

Returns the count of elements in arra from position start that are not among the elements of arrb.

public static int

Returns:

int
countSameElements
(byte[]
byte[]
arra
,
int
int
start
,
byte[]
byte[]
arrb
)

Returns the count of elements in arra from position start that are sequentially equal to the elements of arrb.

public static int

Returns:

int
countSameElements
(char[]
char[]
arra
,
int
int
start
,
char[]
char[]
arrb
)

Returns the count of elements in arra from position start that are sequentially equal to the elements of arrb.

public static int

Returns:

int
countSameElements
(int[]
int[]
arra
,
int
int
start
,
int[]
int[]
arrb
)

Returns the count of elements in arra from position start that are sequentially equal to the elements of arrb.

public static int

Returns:

int
countSmallerElements
(int[]
int[]
arra
,
int
int
value
)

Returns the count of elements in arra that are smaller than the value.

public static int

Returns:

int
countSmallerEqualElements
(int[]
int[]
arra
,
int
int
value
)

Returns the count of elements in arra that are smaller/equal than the value.

public static int

Returns:

int
countStartElementsAt
(byte[]
byte[]
arra
,
int
int
start
,
byte[]
byte[]
arrb
)

Returns the count of elements in arra from position start that are among the elements of arrb.

public static int

Returns:

int
countStartIntIndexesInBooleanArray
(int[]
int[]
arra
,
boolean[]
boolean[]
arrb
)

Return array of indexes of boolean elements that are true.

public static int

Returns:

int
countTrueElements
(boolean[]
boolean[]
arra
)

Return count of true elements in array

public static Object

Returns:

Object
duplicateArray
(Object
Object
source
)

Returns a duplicates of an array.

public static int[]

Returns:

int[]
except
(int[]
int[]
source
,
int[]
int[]
other
)

Returns an array containing the elements of source except any element shared with the other.

public static void
fillArray(char[]
char[]
array
,
int
int
offset
,
char
char
value
)

Fills part of the array with a value.

public static void
fillArray(byte[]
byte[]
array
,
int
int
offset
,
byte
byte
value
)

Fills part of the array with a value.

public static void
fillArray(Object[]
Object[]
array
,
Object
Object
value
)

Fills the array with a value.

public static void
fillArray(int[]
int[]
array
,
int
int
value
)

Fills the int array with a value.

public static void
fillArray(double[]
double[]
array
,
double
double
value
)

Fills the double array with a value.

public static void
fillArray(boolean[]
boolean[]
array
,
boolean
boolean
value
)

Fills the int array with a value

public static void
fillSequence(int[] colindex)

public static int

Returns:

int
find
(Object[]
Object[]
array
,
Object
Object
object
)

Basic find for small arrays of Object.

public static int

Returns:

int
find
(int[]
int[]
array
,
int
int
value
)

Finds index of value in small array.

public static int

Returns:

int
find
(int[]
int[]
array
,
int
int
count
,
int
int
value
)

Finds index of value in the first count elements of small array.

public static int
find(short[] array, int value)

public static int
find(short[] array, int value, int offset, int count)

public static int
find(char[] array, int value)

public static int

Returns:

int
find
(byte[]
byte[]
arra
,
int
int
start
,
int
int
limit
,
byte[]
byte[]
arrb
)

Returns the index of the first occurrence of arrb in arra.

public static int

Returns:

int
find
(byte[]
byte[]
arra
,
int
int
start
,
int
int
limit
,
int
int
b
,
int
int
c
)

Returns the index of b or c in arra.

public static int

Returns:

int
findIn
(byte[]
byte[]
arra
,
int
int
start
,
int
int
limit
,
byte[]
byte[]
byteSet
)

Returns an index into arra (or -1) where the character is in the byteSet byte array.

public static int

Returns:

int
findNot
(int[]
int[]
array
,
int
int
value
)

Finds the first element of the array that is not equal to the given value.

public static int

Returns:

int
findNotIn
(byte[]
byte[]
arra
,
int
int
start
,
int
int
limit
,
byte[]
byte[]
byteSet
)

Returns an index into arra (or -1) where the character is not in the charset byte array.

public static long

Returns:

long
getBinaryMultipleCeiling
(long
long
value
,
long
long
unit
)

uses 2**scale form and returns a multiple of unit that is larger or equal to value

public static long

Returns:

long
getBinaryNormalisedCeiling
(long
long
value
,
int
int
scale
)

uses 2**scale form and returns a multiple of this that is larger or equal to value

public static long

Returns:

long
getBinaryNormalisedCeiling
(long
long
value
)

returns the smallest value that is a power of 2 and larger or equal to value

pack-priv static int

Returns:

int
getClassCode
(Class<T>
Class
cla
)

Returns a distinct int code for each primitive type and for all Object types.

public static int

Returns:

int
getTwoPowerFloor
(int
int
n
)

returns the largest value that is 0 or a power of 2 and is smaller or equal to n

public static int

Returns:

int
getTwoPowerScale
(int
int
n
)

returns the log2 of largest value that is 0 or a power of 2 and is smaller or equal to n

public static boolean
hasAllNull(Object[] array, int[] columnMap)

public static boolean

Returns:

boolean
hasNull
(Object[]
Object[]
array
,
int[]
int[]
columnMap
)

Determines if the array has a null column for any of the positions given in the rowColMap array.

public static boolean

Returns:

boolean
haveCommonElement
(int[]
int[]
arra
,
int[]
int[]
arrb
)

Returns true if arra and arrb share any element.

public static boolean

Returns:

boolean
haveEqualArrays
(int[]
int[]
arra
,
int[]
int[]
arrb
,
int
int
count
)

Returns true if the first count elements of arra and arrb are identical subarrays of integers

public static boolean

Returns:

boolean
haveEqualArrays
(Object[]
Object[]
arra
,
Object[]
Object[]
arrb
,
int
int
count
)

Returns true if the first count elements of arra and arrb are identical subarrays of Objects

public static boolean

Returns:

boolean
haveEqualSets
(int[]
int[]
arra
,
int[]
int[]
arrb
,
int
int
count
)

Returns true if the first count elements of arra and arrb are identical sets of integers (not necessarily in the same order).

public static void
intIndexesToBooleanArray(int[]
int[]
arra
,
boolean[]
boolean[]
arrb
)

Set elements of arrb true if their indexes appear in arrb.

public static boolean
isAnyIntIndexInBooleanArray(int[] arra, boolean[] arrb)

public static boolean

Returns:

boolean
isInSortedArray
(char
char
ch
,
char[]
char[]
array
)

Returns true if char argument is in array.

public static boolean

Returns:

boolean
isTwoPower
(int
int
n
,
int
int
max
)

returns true if log2 n is in the range (0, max)

public static void
orBooleanArray(boolean[] source, boolean[] dest)

public static void
projectMap(int[] mainMap, int[] subMap, int[] newSubMap)

public static void
projectRow(Object[]
the source array
source
,
int[]
the list of indexes into source
columnMap
,
Object[]
the destination array
target
)

Copies some elements of source into target by using columnMap as the list of indexes into source.

public static void
projectRow(int[] source, int[] columnMap, int[] target)

public static void
projectRowReverse(Object[]
the target array
target
,
int[]
the list of indexes into row
columnMap
,
Object[]
the source array
source
)

As above but copies in reverse direction.

public static void
reorderMaps(int[] mainMap, int[] firstMap, int[] secondMap)

public static Object

Returns:

Object
resizeArray
(Object
Object
source
,
int
int
newsize
)

Returns a new array of given size, containing as many elements of the original array as it can hold.

public static Object

Returns:

Object
resizeArrayIfDifferent
(Object
Object
source
,
int
int
newsize
)

Returns the given array if newsize is the same as existing.

public static void
sortArray(int[]
int[]
array
)

Basic sort for small arrays of int.

public static <
type of array element
T
>
T[]

Returns:

T[]
toAdjustedArray
(T[]
T[]
source
,
T
element to append to array
addition
)

Returns a new array containing the elements of parameter source with an added element at the end.

public static Object

Returns:

Object
toAdjustedArray
(Object
Object
source
,
Object
Object
addition
,
int
int
colindex
,
int
int
adjust
)

Returns an array containing the elements of parameter source, with one element removed or added.

public static int[]

Returns:

new, adjusted array
toAdjustedColumnArray
(int[]
the source array
colarr
,
int
index at which to perform adjustment
colindex
,
int
+1, 0 or -1
adjust
)

Returns a new array with the elements in collar adjusted to reflect changes at colindex.

public static int[]

Returns:

int[]
toAdjustedColumnArray
(int[]
int[]
colarr
,
int[]
int[]
colindex
,
int
int
adjust
)

similar to the function with single colindex, but with multiple adjustments.

public static byte[]

Returns:

byte[]
toByteArray
(long
long
hi
,
long
long
lo
)

converts two longs to a byte[16]

public static int[]

Returns:

int[]
union
(int[]
int[] containing unique vlaues
arra
,
int[]
int[] containing unique values
arrb
)

Returns an array that contains all the elements of the two arrays.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait