- java.lang.Object
-
- org.hsqldb.lib.ArrayUtil
-
public final class ArrayUtil extends java.lang.Object
Collection of static methods for operations on arrays- Since:
- 1.7.2
- Author:
- Fred Toussi (fredt@users dot sourceforge.net)
-
-
Field Summary
Fields Modifier and Type Field Description static int
CLASS_CODE_BOOLEAN
static int
CLASS_CODE_BYTE
static int
CLASS_CODE_CHAR
static int
CLASS_CODE_DOUBLE
static int
CLASS_CODE_FLOAT
static int
CLASS_CODE_INT
static int
CLASS_CODE_LONG
static int
CLASS_CODE_OBJECT
static int
CLASS_CODE_SHORT
-
Constructor Summary
Constructors Constructor Description ArrayUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
adjustArray(int type, java.lang.Object array, int usedElements, int index, int count)
Moves the contents of an array to allow both addition and removal of elements.static boolean
areAllIntIndexesAsBooleanArray(int[] arra, boolean[] arrb)
Returns true if all indexes and no other positions are true in arrb.static boolean
areAllIntIndexesInBooleanArray(int[] arra, boolean[] arrb)
static boolean
areEqualSets(int[] arra, int[] arrb)
Returns true if arra and arrb contain the same set of integers, not necessarily in the same order.static int[]
arraySlice(int[] source, int start, int count)
Returns a range of elements of source from start to end of the array.static int[]
booleanArrayToIntIndexes(boolean[] arrb)
Set elements of arrb true if their indexes appear in arrb.static char[]
byteArrayToChars(byte[] bytes)
static char[]
byteArrayToChars(byte[] bytes, int bytesLength)
static long
byteSequenceToLong(byte[] bytes, int pos)
static int
cdiv(int a, int b)
a and b must be both positive returns (a / b) or (a / b) + 1 if remainder is larger than zerostatic long
cdiv(long a, long b)
static byte[]
charArrayToBytes(char[] chars)
static byte[]
charArrayToBytes(char[] chars, int length)
static void
clearArray(int type, java.lang.Object data, int from, int to)
Clears an area of the given array of the given type.static int[]
commonElements(int[] arra, int[] arrb)
Returns an int[] containing elements shared between the two arrays arra and arrb.static int
compare(byte[] a, byte[] b)
Compares two arrays.static int
compare(byte[] a, int aOffset, int aLength, byte[] b, int bOffset, int bLength)
static int[]
concat(int[] arra, int[] arrb)
Returns an array that contains all the elements of the two arrays.static boolean
containsAll(int[] arra, int[] arrb)
returns true if arra contains all elements of arrbstatic boolean
containsAll(java.lang.Object[] arra, java.lang.Object[] arrb)
returns true if arra contains all elements of arrbstatic boolean
containsAllAtStart(int[] arra, int[] arrb)
returns true if arra contains all elements of arrb at its startstatic boolean
containsAllTrueElements(boolean[] arra, boolean[] arrb)
Return true if for each true element in arrb, the corresponding element in arra is truestatic boolean
containsAny(java.lang.Object[] arra, java.lang.Object[] arrb)
returns true if arra contains any element of arrbstatic boolean
containsAt(byte[] arra, int start, byte[] arrb)
Returns true if arra from position start contains all elements of arrb in sequential order.static boolean
containsAt(char[] arra, int start, char[] arrb)
Returns true if arra from position start contains all elements of arrb in sequential order.static void
copyAdjustArray(java.lang.Object[] source, java.lang.Object[] dest, int[] colindex, int adjust)
Similar to single slot adjusted copy, with multiple slots added or removed.static void
copyAdjustArray(java.lang.Object source, java.lang.Object dest, java.lang.Object addition, int colindex, int adjust)
For arrays of Objects or primitives.static void
copyArray(java.lang.Object source, java.lang.Object dest, int count)
Convenience wrapper for System.arraycopy().static byte[]
copyBytes(byte[] source, byte[] dest, int destOffset)
Copy the source to dest, returning dest or an enlarged array of result is larger than dest.static int
copyBytes(long sourceOffset, byte[] source, int sourceOff, int sourceLength, long destOffset, byte[] dest, int destLength)
Byte arrays source and dest each begin at an offset in the common space.static void
copyMoveSegment(java.lang.Object source, java.lang.Object dest, int size, int index, int segmentSize, int destIndex)
static int
countCommonElements(int[] arra, int[] arrb)
Returns the number of elements shared between the two arrays containing sets.static int
countCommonElements(java.lang.Object[] arra, int alen, java.lang.Object[] arrb)
static int
countNonStartElementsAt(byte[] arra, int start, byte[] arrb)
Returns the count of elements in arra from position start that are not among the elements of arrb.static int
countSameElements(byte[] arra, int start, byte[] arrb)
Returns the count of elements in arra from position start that are sequentially equal to the elements of arrb.static int
countSameElements(char[] arra, int start, char[] arrb)
Returns the count of elements in arra from position start that are sequentially equal to the elements of arrb.static int
countSameElements(int[] arra, int start, int[] arrb)
Returns the count of elements in arra from position start that are sequentially equal to the elements of arrb.static int
countSmallerElements(int[] arra, int value)
Returns the count of elements in arra that are smaller than the value.static int
countSmallerEqualElements(int[] arra, int value)
Returns the count of elements in arra that are smaller/equal than the value.static int
countStartElementsAt(byte[] arra, int start, byte[] arrb)
Returns the count of elements in arra from position start that are among the elements of arrb.static int
countStartIntIndexesInBooleanArray(int[] arra, boolean[] arrb)
Return array of indexes of boolean elements that are true.static int
countTrueElements(boolean[] arra)
Return count of true elements in arraystatic java.lang.Object
duplicateArray(java.lang.Object source)
Returns a duplicates of an array.static int[]
except(int[] source, int[] other)
Returns an array containing the elements of source except any element shared with the other.static void
fillArray(boolean[] array, boolean value)
Fills the int array with a valuestatic void
fillArray(byte[] array, int offset, byte value)
Fills part of the array with a value.static void
fillArray(char[] array, int offset, char value)
Fills part of the array with a value.static void
fillArray(double[] array, double value)
Fills the double array with a value.static void
fillArray(int[] array, int value)
Fills the int array with a value.static void
fillArray(java.lang.Object[] array, java.lang.Object value)
Fills the array with a value.static void
fillSequence(int[] colindex)
static int
find(byte[] arra, int start, int limit, byte[] arrb)
Returns the index of the first occurrence of arrb in arra.static int
find(byte[] arra, int start, int limit, int b, int c)
Returns the index of b or c in arra.static int
find(char[] array, int value)
static int
find(int[] array, int value)
Finds index of value in small array.static int
find(int[] array, int count, int value)
Finds index of value in the first count elements of small array.static int
find(short[] array, int value)
static int
find(short[] array, int value, int offset, int count)
static int
find(java.lang.Object[] array, java.lang.Object object)
Basic find for small arrays of Object.static int
findIn(byte[] arra, int start, int limit, byte[] byteSet)
Returns an index into arra (or -1) where the character is in the byteSet byte array.static int
findNot(int[] array, int value)
Finds the first element of the array that is not equal to the given value.static int
findNotIn(byte[] arra, int start, int limit, byte[] byteSet)
Returns an index into arra (or -1) where the character is not in the charset byte array.static long
getBinaryMultipleCeiling(long value, long unit)
uses 2**scale form and returns a multiple of unit that is larger or equal to valuestatic long
getBinaryNormalisedCeiling(long value)
returns the smallest value that is a power of 2 and larger or equal to valuestatic long
getBinaryNormalisedCeiling(long value, int scale)
uses 2**scale form and returns a multiple of this that is larger or equal to valuestatic int
getTwoPowerFloor(int n)
returns the largest value that is 0 or a power of 2 and is smaller or equal to nstatic int
getTwoPowerScale(int n)
returns the log2 of largest value that is 0 or a power of 2 and is smaller or equal to nstatic boolean
hasAllNull(java.lang.Object[] array, int[] columnMap)
static boolean
hasNull(java.lang.Object[] array, int[] columnMap)
Determines if the array has a null column for any of the positions given in the rowColMap array.static boolean
haveCommonElement(int[] arra, int[] arrb)
Returns true if arra and arrb share any element.static boolean
haveEqualArrays(int[] arra, int[] arrb, int count)
Returns true if the first count elements of arra and arrb are identical subarrays of integersstatic boolean
haveEqualArrays(java.lang.Object[] arra, java.lang.Object[] arrb, int count)
Returns true if the first count elements of arra and arrb are identical subarrays of Objectsstatic boolean
haveEqualSets(int[] arra, int[] arrb, int count)
Returns true if the first count elements of arra and arrb are identical sets of integers (not necessarily in the same order).static void
intIndexesToBooleanArray(int[] arra, boolean[] arrb)
Set elements of arrb true if their indexes appear in arrb.static boolean
isAnyIntIndexInBooleanArray(int[] arra, boolean[] arrb)
static boolean
isInSortedArray(char ch, char[] array)
Returns true if char argument is in array.static boolean
isTwoPower(int n, int max)
returns true if log2 n is in the range (0, max)static void
orBooleanArray(boolean[] source, boolean[] dest)
static void
projectMap(int[] mainMap, int[] subMap, int[] newSubMap)
static void
projectRow(int[] source, int[] columnMap, int[] target)
static void
projectRow(java.lang.Object[] source, int[] columnMap, java.lang.Object[] target)
Copies some elements of source into target by using columnMap as the list of indexes into source.static void
projectRowReverse(java.lang.Object[] target, int[] columnMap, java.lang.Object[] source)
As above but copies in reverse direction.static void
reorderMaps(int[] mainMap, int[] firstMap, int[] secondMap)
static java.lang.Object
resizeArray(java.lang.Object source, int newsize)
Returns a new array of given size, containing as many elements of the original array as it can hold.static java.lang.Object
resizeArrayIfDifferent(java.lang.Object source, int newsize)
Returns the given array if newsize is the same as existing.static void
sortArray(int[] array)
Basic sort for small arrays of int.static java.lang.Object
toAdjustedArray(java.lang.Object source, java.lang.Object addition, int colindex, int adjust)
Returns an array containing the elements of parameter source, with one element removed or added.static <T> T[]
toAdjustedArray(T[] source, T addition)
Returns a new array containing the elements of parameter source with an added element at the end.static int[]
toAdjustedColumnArray(int[] colarr, int[] colindex, int adjust)
similar to the function with single colindex, but with multiple adjustments.static int[]
toAdjustedColumnArray(int[] colarr, int colindex, int adjust)
Returns a new array with the elements in collar adjusted to reflect changes at colindex.static byte[]
toByteArray(long hi, long lo)
converts two longs to a byte[16]static int[]
union(int[] arra, int[] arrb)
Returns an array that contains all the elements of the two arrays.
-
-
-
Field Detail
-
CLASS_CODE_BYTE
public static final int CLASS_CODE_BYTE
- See Also:
- Constant Field Values
-
CLASS_CODE_CHAR
public static final int CLASS_CODE_CHAR
- See Also:
- Constant Field Values
-
CLASS_CODE_DOUBLE
public static final int CLASS_CODE_DOUBLE
- See Also:
- Constant Field Values
-
CLASS_CODE_FLOAT
public static final int CLASS_CODE_FLOAT
- See Also:
- Constant Field Values
-
CLASS_CODE_INT
public static final int CLASS_CODE_INT
- See Also:
- Constant Field Values
-
CLASS_CODE_LONG
public static final int CLASS_CODE_LONG
- See Also:
- Constant Field Values
-
CLASS_CODE_OBJECT
public static final int CLASS_CODE_OBJECT
- See Also:
- Constant Field Values
-
CLASS_CODE_SHORT
public static final int CLASS_CODE_SHORT
- See Also:
- Constant Field Values
-
CLASS_CODE_BOOLEAN
public static final int CLASS_CODE_BOOLEAN
- See Also:
- Constant Field Values
-
-
Method Detail
-
clearArray
public static void clearArray(int type, java.lang.Object data, int from, int to)
Clears an area of the given array of the given type.- Parameters:
type
- intdata
- Objectfrom
- intto
- int
-
adjustArray
public static void adjustArray(int type, java.lang.Object array, int usedElements, int index, int count)
Moves the contents of an array to allow both addition and removal of elements. Used arguments must be in range.- Parameters:
type
- class type of the arrayarray
- the arrayusedElements
- count of elements of array in useindex
- point at which to add or remove elementscount
- number of elements to add or remove
-
sortArray
public static void sortArray(int[] array)
Basic sort for small arrays of int.- Parameters:
array
- int[]
-
find
public static int find(java.lang.Object[] array, java.lang.Object object)
Basic find for small arrays of Object.- Parameters:
array
- Object[]object
- Object- Returns:
- int
-
find
public static int find(int[] array, int value)
Finds index of value in small array.- Parameters:
array
- int[]value
- int- Returns:
- int
-
find
public static int find(int[] array, int count, int value)
Finds index of value in the first count elements of small array.- Parameters:
array
- int[]count
- intvalue
- int- Returns:
- int
-
find
public static int find(short[] array, int value)
-
find
public static int find(short[] array, int value, int offset, int count)
-
find
public static int find(char[] array, int value)
-
findNot
public static int findNot(int[] array, int value)
Finds the first element of the array that is not equal to the given value.- Parameters:
array
- int[]value
- int- Returns:
- int
-
areEqualSets
public static boolean areEqualSets(int[] arra, int[] arrb)
Returns true if arra and arrb contain the same set of integers, not necessarily in the same order. This implies the arrays are of the same length.- Parameters:
arra
- int[]arrb
- int[]- Returns:
- boolean
-
haveEqualSets
public static boolean haveEqualSets(int[] arra, int[] arrb, int count)
Returns true if the first count elements of arra and arrb are identical sets of integers (not necessarily in the same order).- Parameters:
arra
- int[]arrb
- int[]count
- int- Returns:
- boolean
-
haveEqualArrays
public static boolean haveEqualArrays(int[] arra, int[] arrb, int count)
Returns true if the first count elements of arra and arrb are identical subarrays of integers- Parameters:
arra
- int[]arrb
- int[]count
- int- Returns:
- boolean
-
haveEqualArrays
public static boolean haveEqualArrays(java.lang.Object[] arra, java.lang.Object[] arrb, int count)
Returns true if the first count elements of arra and arrb are identical subarrays of Objects- Parameters:
arra
- Object[]arrb
- Object[]count
- int- Returns:
- boolean
-
haveCommonElement
public static boolean haveCommonElement(int[] arra, int[] arrb)
Returns true if arra and arrb share any element.Used for checks for any overlap between two arrays of column indexes.
- Parameters:
arra
- int[]arrb
- int[]- Returns:
- boolean
-
commonElements
public static int[] commonElements(int[] arra, int[] arrb)
Returns an int[] containing elements shared between the two arrays arra and arrb. The arrays contain sets (no value is repeated). Used to find the overlap between two arrays of column indexes. Ordering of the result arrays will be the same as in array arra. The method assumes that each index is only listed once in the two input arrays.e.g.
Example The arrays int []arra = {2,11,5,8} int []arrb = {20,8,10,11,28,12} will result in: int []arrc = {11,8} - Parameters:
arra
- int[] first column indexesarrb
- int[] second column indexes- Returns:
- int[] common indexes or
null
if there is no overlap.
-
countCommonElements
public static int countCommonElements(int[] arra, int[] arrb)
Returns the number of elements shared between the two arrays containing sets.Returns the number of elements shared by two column index arrays. This method assumes that each of these arrays contains a set (each element index is listed only once in each index array). Otherwise the returned number will NOT represent the number of unique column indexes shared by both index array.
- Parameters:
arra
- int[] first array of column indexes.arrb
- int[] second array of column indexes- Returns:
- int number of elements shared by
arra
andarrb
-
countCommonElements
public static int countCommonElements(java.lang.Object[] arra, int alen, java.lang.Object[] arrb)
-
countSameElements
public static int countSameElements(byte[] arra, int start, byte[] arrb)
Returns the count of elements in arra from position start that are sequentially equal to the elements of arrb.- Parameters:
arra
- byte[]start
- intarrb
- byte[]- Returns:
- int
-
countSameElements
public static int countSameElements(char[] arra, int start, char[] arrb)
Returns the count of elements in arra from position start that are sequentially equal to the elements of arrb.- Parameters:
arra
- char[]start
- intarrb
- char[]- Returns:
- int
-
countSameElements
public static int countSameElements(int[] arra, int start, int[] arrb)
Returns the count of elements in arra from position start that are sequentially equal to the elements of arrb.- Parameters:
arra
- int[]start
- intarrb
- int[]- Returns:
- int
-
countSmallerElements
public static int countSmallerElements(int[] arra, int value)
Returns the count of elements in arra that are smaller than the value.- Parameters:
arra
- int[]value
- int- Returns:
- int
-
countSmallerEqualElements
public static int countSmallerEqualElements(int[] arra, int value)
Returns the count of elements in arra that are smaller/equal than the value.- Parameters:
arra
- int[]value
- int- Returns:
- int
-
union
public static int[] union(int[] arra, int[] arrb)
Returns an array that contains all the elements of the two arrays. Each array contains a set.- Parameters:
arra
- int[] containing unique vlauesarrb
- int[] containing unique values- Returns:
- int[]
-
concat
public static int[] concat(int[] arra, int[] arrb)
Returns an array that contains all the elements of the two arrays.- Parameters:
arra
- int[]arrb
- int[]- Returns:
- int[]
-
find
public static int find(byte[] arra, int start, int limit, byte[] arrb)
Returns the index of the first occurrence of arrb in arra. Or -1 if not found.- Parameters:
arra
- byte[]start
- intlimit
- intarrb
- byte[]- Returns:
- int
-
findNotIn
public static int findNotIn(byte[] arra, int start, int limit, byte[] byteSet)
Returns an index into arra (or -1) where the character is not in the charset byte array.- Parameters:
arra
- byte[]start
- intlimit
- intbyteSet
- byte[]- Returns:
- int
-
findIn
public static int findIn(byte[] arra, int start, int limit, byte[] byteSet)
Returns an index into arra (or -1) where the character is in the byteSet byte array.- Parameters:
arra
- byte[]start
- intlimit
- intbyteSet
- byte[]- Returns:
- int
-
find
public static int find(byte[] arra, int start, int limit, int b, int c)
Returns the index of b or c in arra. Or -1 if not found.- Parameters:
arra
- byte[]start
- intlimit
- intb
- intc
- int- Returns:
- int
-
booleanArrayToIntIndexes
public static int[] booleanArrayToIntIndexes(boolean[] arrb)
Set elements of arrb true if their indexes appear in arrb.- Parameters:
arrb
- boolean[]- Returns:
- int[]
-
intIndexesToBooleanArray
public static void intIndexesToBooleanArray(int[] arra, boolean[] arrb)
Set elements of arrb true if their indexes appear in arrb.- Parameters:
arra
- int[]arrb
- boolean[]
-
countStartIntIndexesInBooleanArray
public static int countStartIntIndexesInBooleanArray(int[] arra, boolean[] arrb)
Return array of indexes of boolean elements that are true.- Parameters:
arra
- int[]arrb
- boolean[]- Returns:
- int
-
orBooleanArray
public static void orBooleanArray(boolean[] source, boolean[] dest)
-
areAllIntIndexesAsBooleanArray
public static boolean areAllIntIndexesAsBooleanArray(int[] arra, boolean[] arrb)
Returns true if all indexes and no other positions are true in arrb. arra must have no duplicates. arra must have no duplicates.- Parameters:
arra
- int[]arrb
- boolean[]- Returns:
- boolean
-
areAllIntIndexesInBooleanArray
public static boolean areAllIntIndexesInBooleanArray(int[] arra, boolean[] arrb)
-
isAnyIntIndexInBooleanArray
public static boolean isAnyIntIndexInBooleanArray(int[] arra, boolean[] arrb)
-
containsAllTrueElements
public static boolean containsAllTrueElements(boolean[] arra, boolean[] arrb)
Return true if for each true element in arrb, the corresponding element in arra is true- Parameters:
arra
- boolean[]arrb
- boolean[]- Returns:
- boolean
-
countTrueElements
public static int countTrueElements(boolean[] arra)
Return count of true elements in array- Parameters:
arra
- boolean[]- Returns:
- int
-
hasNull
public static boolean hasNull(java.lang.Object[] array, int[] columnMap)
Determines if the array has a null column for any of the positions given in the rowColMap array.- Parameters:
array
- Object[]columnMap
- int[]- Returns:
- boolean
-
hasAllNull
public static boolean hasAllNull(java.lang.Object[] array, int[] columnMap)
-
containsAt
public static boolean containsAt(byte[] arra, int start, byte[] arrb)
Returns true if arra from position start contains all elements of arrb in sequential order.- Parameters:
arra
- byte[]start
- intarrb
- byte[]- Returns:
- boolean
-
countStartElementsAt
public static int countStartElementsAt(byte[] arra, int start, byte[] arrb)
Returns the count of elements in arra from position start that are among the elements of arrb. Stops at any element not in arrb.- Parameters:
arra
- byte[]start
- intarrb
- byte[]- Returns:
- int
-
containsAt
public static boolean containsAt(char[] arra, int start, char[] arrb)
Returns true if arra from position start contains all elements of arrb in sequential order.- Parameters:
arra
- char[]start
- intarrb
- char[]- Returns:
- boolean
-
countNonStartElementsAt
public static int countNonStartElementsAt(byte[] arra, int start, byte[] arrb)
Returns the count of elements in arra from position start that are not among the elements of arrb.- Parameters:
arra
- byte[]start
- intarrb
- byte[]- Returns:
- int
-
copyBytes
public static int copyBytes(long sourceOffset, byte[] source, int sourceOff, int sourceLength, long destOffset, byte[] dest, int destLength)
Byte arrays source and dest each begin at an offset in the common space. If there is an overlap between dest and the first sourceLength elements of the source, the overlapping elements are copied to dest. Returns count of copied bytes.- Parameters:
sourceOffset
- longsource
- byte[]sourceOff
- intsourceLength
- intdestOffset
- longdest
- byte[]destLength
- int- Returns:
- int
-
copyBytes
public static byte[] copyBytes(byte[] source, byte[] dest, int destOffset)
Copy the source to dest, returning dest or an enlarged array of result is larger than dest.- Parameters:
source
- byte[]dest
- byte[]destOffset
- int- Returns:
- byte[]
-
copyArray
public static void copyArray(java.lang.Object source, java.lang.Object dest, int count)
Convenience wrapper for System.arraycopy().- Parameters:
source
- Objectdest
- Objectcount
- int
-
copyMoveSegment
public static void copyMoveSegment(java.lang.Object source, java.lang.Object dest, int size, int index, int segmentSize, int destIndex)
-
arraySlice
public static int[] arraySlice(int[] source, int start, int count)
Returns a range of elements of source from start to end of the array.- Parameters:
source
- int[]start
- intcount
- int- Returns:
- int[]
-
fillArray
public static void fillArray(char[] array, int offset, char value)
Fills part of the array with a value.- Parameters:
array
- char[]offset
- intvalue
- char
-
fillArray
public static void fillArray(byte[] array, int offset, byte value)
Fills part of the array with a value.- Parameters:
array
- byte[]offset
- intvalue
- byte
-
fillArray
public static void fillArray(java.lang.Object[] array, java.lang.Object value)
Fills the array with a value.- Parameters:
array
- Object[]value
- Object
-
fillArray
public static void fillArray(int[] array, int value)
Fills the int array with a value.- Parameters:
array
- int[]value
- int
-
fillArray
public static void fillArray(double[] array, double value)
Fills the double array with a value.- Parameters:
array
- double[]value
- double
-
fillArray
public static void fillArray(boolean[] array, boolean value)
Fills the int array with a value- Parameters:
array
- boolean[]value
- boolean
-
duplicateArray
public static java.lang.Object duplicateArray(java.lang.Object source)
Returns a duplicates of an array.- Parameters:
source
- Object- Returns:
- Object
-
resizeArrayIfDifferent
public static java.lang.Object resizeArrayIfDifferent(java.lang.Object source, int newsize)
Returns the given array if newsize is the same as existing. Returns a new array of given size, containing as many elements of the original array as it can hold.- Parameters:
source
- Objectnewsize
- int- Returns:
- Object
-
resizeArray
public static java.lang.Object resizeArray(java.lang.Object source, int newsize)
Returns a new array of given size, containing as many elements of the original array as it can hold. N.B. Always returns a new array even if newsize parameter is the same as the old size.- Parameters:
source
- Objectnewsize
- int- Returns:
- Object
-
toAdjustedArray
public static <T> T[] toAdjustedArray(T[] source, T addition)
Returns a new array containing the elements of parameter source with an added element at the end. Parameter addition is an Object to add.- Type Parameters:
T
- type of array element- Parameters:
source
- T[]addition
- element to append to array- Returns:
- T[]
-
toAdjustedArray
public static java.lang.Object toAdjustedArray(java.lang.Object source, java.lang.Object addition, int colindex, int adjust)
Returns an array containing the elements of parameter source, with one element removed or added. Parameter adjust {-1, +1} indicates the operation. Parameter colindex indicates the position at which an element is removed or added. Parameter addition is an Object to add when adjust is +1.- Parameters:
source
- Objectaddition
- Objectcolindex
- intadjust
- int- Returns:
- Object
-
except
public static int[] except(int[] source, int[] other)
Returns an array containing the elements of source except any element shared with the other.- Parameters:
source
- int[]other
- int[]- Returns:
- int[]
-
copyAdjustArray
public static void copyAdjustArray(java.lang.Object source, java.lang.Object dest, java.lang.Object addition, int colindex, int adjust)
For arrays of Objects or primitives. Copies array elements of source to dest. If adjust is -1 the element at colindex is not copied. If adjust is +1 that element is filled with the Object addition. All the rest of the elements in source are shifted left or right accordingly when they are copied. If adjust is 0 the addition is copied over the element at colindex. No checks are performed on array sizes and an exception is thrown if they are not consistent with the other arguments.- Parameters:
source
- Objectdest
- Objectaddition
- Objectcolindex
- intadjust
- int
-
copyAdjustArray
public static void copyAdjustArray(java.lang.Object[] source, java.lang.Object[] dest, int[] colindex, int adjust)
Similar to single slot adjusted copy, with multiple slots added or removed. The colindex array is the ordered list of the slots to be added or removed. The adjust argument can be {-1, +1} for remove or add. No checks are performed on array sizes and no exception is thrown if they are not consistent with the other arguments.- Parameters:
source
- Object[]dest
- Object[]colindex
- int[]adjust
- int
-
toAdjustedColumnArray
public static int[] toAdjustedColumnArray(int[] colarr, int colindex, int adjust)
Returns a new array with the elements in collar adjusted to reflect changes at colindex.Each element in collarr represents an index into another array otherarr.
colindex is the index at which an element is added or removed. Each element in the result array represents the new, adjusted index.
For each element of collarr that represents an index equal to colindex and adjust is -1, the result will not contain that element and will be shorter than collar by one element.
- Parameters:
colarr
- the source arraycolindex
- index at which to perform adjustmentadjust
- +1, 0 or -1- Returns:
- new, adjusted array
-
toAdjustedColumnArray
public static int[] toAdjustedColumnArray(int[] colarr, int[] colindex, int adjust)
similar to the function with single colindex, but with multiple adjustments.- Parameters:
colarr
- int[]colindex
- int[]adjust
- int- Returns:
- int[]
-
projectRow
public static void projectRow(java.lang.Object[] source, int[] columnMap, java.lang.Object[] target)
Copies some elements of source into target by using columnMap as the list of indexes into source.columnMap and target are normally of equal length and shorter than source.
- Parameters:
source
- the source arraycolumnMap
- the list of indexes into sourcetarget
- the destination array
-
projectRow
public static void projectRow(int[] source, int[] columnMap, int[] target)
-
projectRowReverse
public static void projectRowReverse(java.lang.Object[] target, int[] columnMap, java.lang.Object[] source)
As above but copies in reverse direction.- Parameters:
target
- the target arraycolumnMap
- the list of indexes into rowsource
- the source array
-
projectMap
public static void projectMap(int[] mainMap, int[] subMap, int[] newSubMap)
-
reorderMaps
public static void reorderMaps(int[] mainMap, int[] firstMap, int[] secondMap)
-
fillSequence
public static void fillSequence(int[] colindex)
-
byteArrayToChars
public static char[] byteArrayToChars(byte[] bytes)
-
byteArrayToChars
public static char[] byteArrayToChars(byte[] bytes, int bytesLength)
-
charArrayToBytes
public static byte[] charArrayToBytes(char[] chars)
-
charArrayToBytes
public static byte[] charArrayToBytes(char[] chars, int length)
-
isInSortedArray
public static boolean isInSortedArray(char ch, char[] array)
Returns true if char argument is in array.- Parameters:
ch
- chararray
- char[]- Returns:
- boolean
-
containsAll
public static boolean containsAll(java.lang.Object[] arra, java.lang.Object[] arrb)
returns true if arra contains all elements of arrb- Parameters:
arra
- Object[]arrb
- Object[]- Returns:
- boolean
-
containsAny
public static boolean containsAny(java.lang.Object[] arra, java.lang.Object[] arrb)
returns true if arra contains any element of arrb- Parameters:
arra
- Object[]arrb
- Object[]- Returns:
- boolean
-
containsAll
public static boolean containsAll(int[] arra, int[] arrb)
returns true if arra contains all elements of arrb- Parameters:
arra
- int[]arrb
- int[]- Returns:
- boolean
-
containsAllAtStart
public static boolean containsAllAtStart(int[] arra, int[] arrb)
returns true if arra contains all elements of arrb at its start- Parameters:
arra
- int[]arrb
- int[]- Returns:
- boolean
-
toByteArray
public static byte[] toByteArray(long hi, long lo)
converts two longs to a byte[16]- Parameters:
hi
- longlo
- long- Returns:
- byte[]
-
byteSequenceToLong
public static long byteSequenceToLong(byte[] bytes, int pos)
-
compare
public static int compare(byte[] a, byte[] b)
Compares two arrays. Returns -1, 0, +1. If one array is shorter and all the elements are equal to the other's elements, -1 is returned.- Parameters:
a
- byte[]b
- byte[]- Returns:
- int
-
compare
public static int compare(byte[] a, int aOffset, int aLength, byte[] b, int bOffset, int bLength)
-
getBinaryMultipleCeiling
public static long getBinaryMultipleCeiling(long value, long unit)
uses 2**scale form and returns a multiple of unit that is larger or equal to value- Parameters:
value
- longunit
- long- Returns:
- long
-
getBinaryNormalisedCeiling
public static long getBinaryNormalisedCeiling(long value, int scale)
uses 2**scale form and returns a multiple of this that is larger or equal to value- Parameters:
value
- longscale
- int- Returns:
- long
-
getBinaryNormalisedCeiling
public static long getBinaryNormalisedCeiling(long value)
returns the smallest value that is a power of 2 and larger or equal to value- Parameters:
value
- long- Returns:
- long
-
isTwoPower
public static boolean isTwoPower(int n, int max)
returns true if log2 n is in the range (0, max)- Parameters:
n
- intmax
- int- Returns:
- boolean
-
getTwoPowerFloor
public static int getTwoPowerFloor(int n)
returns the largest value that is 0 or a power of 2 and is smaller or equal to n- Parameters:
n
- int- Returns:
- int
-
getTwoPowerScale
public static int getTwoPowerScale(int n)
returns the log2 of largest value that is 0 or a power of 2 and is smaller or equal to n- Parameters:
n
- int- Returns:
- int
-
cdiv
public static int cdiv(int a, int b)
a and b must be both positive returns (a / b) or (a / b) + 1 if remainder is larger than zero- Parameters:
a
- intb
- int- Returns:
- int
-
cdiv
public static long cdiv(long a, long b)
-
-