Package org.basex.util
Class Array
- java.lang.Object
-
- org.basex.util.Array
-
-
Field Summary
Fields Modifier and Type Field Description static int
INITIAL_CAPACITY
Initial default size for new arrays.static int
MAX_CAPACITY
Maximum capacity for new arrays.static int
MAX_SIZE
Maximum array size (seeMAX_ARRAY_SIZE
variable inArrayList
).static byte
RESIZE_FACTOR
Default factor for resizing dynamic arrays (default: 50%).
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int[]
add(int[] array, int entry)
Adds an entry to the end of an array and returns the new array.static <T> T[]
add(T[] array, T entry)
Adds an entry to the end of an array and returns the new array.static int
checkCapacity(long size)
Raises an exception if the specified size exceeds the maximum array size.static void
copy(Object array, int index, int length, Object target, int trgIndex)
Copies first entries from one array to another array.static void
copy(Object source, int length, Object target)
Copies first entries from one array to another array.static <T> T[]
copy(T[] source, T[] target)
Copies entries from one array to another array.static void
copyFromStart(Object source, int length, Object target, int index)
Copies first entries from one array to another array.static byte[][]
copyOf(byte[][] array, int size)
Copies the specified array.static int[][]
copyOf(int[][] array, int size)
Copies the specified array.static String[]
copyOf(String[] array, int size)
Copies the specified array.static void
copyToStart(Object source, int index, int length, Object target)
Copies first entries from one array to beginning of another array.static int[]
createOrder(byte[][] values, boolean numeric, boolean ascending)
Sorts the specified tokens and returns an array with offsets to the sorted array.static int[]
createOrder(double[] values, boolean ascending)
Sorts the specified double values and returns an array with offsets to the sorted array.static int[]
createOrder(int[] values, boolean ascending)
Sorts the specified int values and returns an array with offsets to the sorted array.static int[]
createOrder(long[] values, boolean ascending)
Sorts the specified long values and returns an array with offsets to the sorted array.static boolean
equals(byte[][] tokens1, byte[][] tokens2)
Compares two token arrays for equality.static boolean
equals(Object[] arr1, Object[] arr2)
Compares two arrays for equality.static int
initialCapacity(long size)
Returns an initial array capacity, which will not exceedMAX_CAPACITY
.static void
insert(Object array, int index, int add, int length, Object entries)
Inserts entries into an array.static int
newCapacity(int size)
Returns a value for a new array size, which will always be larger than the old size.static int
newCapacity(int size, byte factor)
Returns a value for a new array size, which will always be larger than the old size.static IntList
number(int size)
Returns an enumerated integer list.static void
remove(Object array, int index, int del, int length)
Removes entries inside an array.static <T> T[]
remove(T[] array, int index)
Removes an array entry at the specified position.
-
-
-
Field Detail
-
MAX_SIZE
public static final int MAX_SIZE
Maximum array size (seeMAX_ARRAY_SIZE
variable inArrayList
).- See Also:
- Constant Field Values
-
INITIAL_CAPACITY
public static final int INITIAL_CAPACITY
Initial default size for new arrays.- See Also:
- Constant Field Values
-
MAX_CAPACITY
public static final int MAX_CAPACITY
Maximum capacity for new arrays.- See Also:
- Constant Field Values
-
RESIZE_FACTOR
public static final byte RESIZE_FACTOR
Default factor for resizing dynamic arrays (default: 50%).- See Also:
- Constant Field Values
-
-
Method Detail
-
copyOf
public static byte[][] copyOf(byte[][] array, int size)
Copies the specified array.- Parameters:
array
- array to be copiedsize
- new array size- Returns:
- new array
-
copyOf
public static int[][] copyOf(int[][] array, int size)
Copies the specified array.- Parameters:
array
- array to be copiedsize
- new array size- Returns:
- new array
-
copyOf
public static String[] copyOf(String[] array, int size)
Copies the specified array.- Parameters:
array
- array to be copiedsize
- new array size- Returns:
- new array
-
add
public static <T> T[] add(T[] array, T entry)
Adds an entry to the end of an array and returns the new array.- Type Parameters:
T
- array type- Parameters:
array
- array to be resizedentry
- entry to be added- Returns:
- array
-
add
public static int[] add(int[] array, int entry)
Adds an entry to the end of an array and returns the new array.- Parameters:
array
- array to be resizedentry
- entry to be added- Returns:
- array
-
insert
public static void insert(Object array, int index, int add, int length, Object entries)
Inserts entries into an array.- Parameters:
array
- arrayindex
- insertion indexadd
- number of entries to addlength
- number of valid array entriesentries
- entries to be inserted (can benull
)
-
remove
public static void remove(Object array, int index, int del, int length)
Removes entries inside an array.- Parameters:
array
- arrayindex
- index of first entry to be removeddel
- number of entries to removelength
- number of valid array entries
-
copy
public static void copy(Object array, int index, int length, Object target, int trgIndex)
Copies first entries from one array to another array.- Parameters:
array
- source arrayindex
- index of source arraylength
- number of array entries to be copiedtarget
- target arraytrgIndex
- index of target array
-
copy
public static void copy(Object source, int length, Object target)
Copies first entries from one array to another array.- Parameters:
source
- source arraylength
- number of array entries to be copiedtarget
- target array
-
copyFromStart
public static void copyFromStart(Object source, int length, Object target, int index)
Copies first entries from one array to another array.- Parameters:
source
- source arraylength
- number of array entries to be copiedtarget
- target arrayindex
- target index
-
copyToStart
public static void copyToStart(Object source, int index, int length, Object target)
Copies first entries from one array to beginning of another array.- Parameters:
source
- source arrayindex
- index of first entry to copylength
- number of array entries to be copiedtarget
- target array
-
copy
public static <T> T[] copy(T[] source, T[] target)
Copies entries from one array to another array.- Type Parameters:
T
- object type- Parameters:
source
- source arraytarget
- target array- Returns:
- object
-
remove
public static <T> T[] remove(T[] array, int index)
Removes an array entry at the specified position.- Type Parameters:
T
- array type- Parameters:
array
- array to be resizedindex
- index of entry- Returns:
- new array
-
createOrder
public static int[] createOrder(byte[][] values, boolean numeric, boolean ascending)
Sorts the specified tokens and returns an array with offsets to the sorted array.- Parameters:
values
- values to sort by (will be sorted as well)numeric
- numeric sortascending
- ascending- Returns:
- array containing the order
-
createOrder
public static int[] createOrder(double[] values, boolean ascending)
Sorts the specified double values and returns an array with offsets to the sorted array.- Parameters:
values
- values to sort by (will be sorted as well)ascending
- ascending- Returns:
- array containing the order
-
createOrder
public static int[] createOrder(int[] values, boolean ascending)
Sorts the specified int values and returns an array with offsets to the sorted array.- Parameters:
values
- values to sort by (will be sorted as well)ascending
- ascending- Returns:
- array containing the order
-
createOrder
public static int[] createOrder(long[] values, boolean ascending)
Sorts the specified long values and returns an array with offsets to the sorted array.- Parameters:
values
- values to sort by (will be sorted as well)ascending
- ascending- Returns:
- array containing the order
-
number
public static IntList number(int size)
Returns an enumerated integer list.- Parameters:
size
- array size- Returns:
- number list
-
initialCapacity
public static int initialCapacity(long size)
Returns an initial array capacity, which will not exceedMAX_CAPACITY
.- Parameters:
size
- size expected result size (ignored if negative)- Returns:
- capacity
-
newCapacity
public static int newCapacity(int size)
Returns a value for a new array size, which will always be larger than the old size. The returned value will not exceed the maximum allowed array size. If the maximum is reached, an exception is thrown.- Parameters:
size
- old array capacity- Returns:
- new capacity
-
newCapacity
public static int newCapacity(int size, byte factor)
Returns a value for a new array size, which will always be larger than the old size. The returned value will not exceed the maximum allowed array size. If the maximum is reached, an exception is thrown.- Parameters:
size
- old array capacityfactor
- resize factor; must be 10 or larger- Returns:
- new capacity
-
checkCapacity
public static int checkCapacity(long size)
Raises an exception if the specified size exceeds the maximum array size.- Parameters:
size
- array capacity- Returns:
- argument as integer, or
0
if the argument is negative
-
equals
public static boolean equals(byte[][] tokens1, byte[][] tokens2)
Compares two token arrays for equality.- Parameters:
tokens1
- first tokens (can benull
)tokens2
- second tokens (can benull
)- Returns:
- result of check
-
-