Package org.basex.util
Class Array
java.lang.Object
org.basex.util.Array
Convenience functions for handling arrays; serves as an extension to Java's
Arrays class.- Author:
- BaseX Team 2005-21, BSD License, Christian Gruen
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intInitial default size for new arrays.static final intMaximum capacity for new arrays.static final intMaximum array size (seeMAX_ARRAY_SIZEvariable inArrayList).static final doubleDefault factor for resizing dynamic arrays. -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 intcheckCapacity(long size) Raises an exception if the specified size exceeds the maximum array size.static voidCopies first entries from one array to another array.static voidCopies 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 voidcopyFromStart(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[]Copies the specified array.static voidcopyToStart(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 booleanequals(byte[][] tokens1, byte[][] tokens2) Compares two token arrays for equality.static booleanCompares two arrays for equality.static intinitialCapacity(long size) Returns an initial array capacity, which will not exceedMAX_CAPACITY.static voidInserts entries into an array.static intnewCapacity(int size) Returns a value for a new array size, which will always be larger than the old size.static intnewCapacity(int size, double factor) Returns a value for a new array size, which will always be larger than the old size.static IntListnumber(int size) Returns an enumerated integer list.static voidRemoves entries inside an array.static <T> T[]remove(T[] array, int index) Removes an array entry at the specified position.
-
Field Details
-
MAX_SIZE
public static final int MAX_SIZEMaximum array size (seeMAX_ARRAY_SIZEvariable inArrayList).- See Also:
-
INITIAL_CAPACITY
public static final int INITIAL_CAPACITYInitial default size for new arrays.- See Also:
-
MAX_CAPACITY
public static final int MAX_CAPACITYMaximum capacity for new arrays.- See Also:
-
RESIZE_CAPACITY
public static final double RESIZE_CAPACITYDefault factor for resizing dynamic arrays.- See Also:
-
-
Method Details
-
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
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
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
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
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
Copies first entries from one array to another array.- Parameters:
source- source arraylength- number of array entries to be copiedtarget- target array
-
copyFromStart
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
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
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, double 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 larger than or equal to 1- 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
0if 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
-
equals
Compares two arrays for equality.- Parameters:
arr1- first array (can benull)arr2- second array (can benull)- Returns:
- result of check
-