Class Array

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

public final class Array extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Initial default size for new arrays.
    static final int
    Maximum capacity for new arrays.
    static final int
    Maximum array size (see MAX_ARRAY_SIZE variable in ArrayList).
    static final double
    Default factor for resizing dynamic arrays.
  • Method Summary

    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 exceed MAX_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, double 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAX_SIZE

      public static final int MAX_SIZE
      Maximum array size (see MAX_ARRAY_SIZE variable in ArrayList).
      See Also:
    • INITIAL_CAPACITY

      public static final int INITIAL_CAPACITY
      Initial default size for new arrays.
      See Also:
    • MAX_CAPACITY

      public static final int MAX_CAPACITY
      Maximum capacity for new arrays.
      See Also:
    • RESIZE_CAPACITY

      public static final double RESIZE_CAPACITY
      Default 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 copied
      size - new array size
      Returns:
      new array
    • copyOf

      public static int[][] copyOf(int[][] array, int size)
      Copies the specified array.
      Parameters:
      array - array to be copied
      size - new array size
      Returns:
      new array
    • copyOf

      public static String[] copyOf(String[] array, int size)
      Copies the specified array.
      Parameters:
      array - array to be copied
      size - 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 resized
      entry - 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 resized
      entry - 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 - array
      index - insertion index
      add - number of entries to add
      length - number of valid array entries
      entries - entries to be inserted (can be null)
    • remove

      public static void remove(Object array, int index, int del, int length)
      Removes entries inside an array.
      Parameters:
      array - array
      index - index of first entry to be removed
      del - number of entries to remove
      length - 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 array
      index - index of source array
      length - number of array entries to be copied
      target - target array
      trgIndex - 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 array
      length - number of array entries to be copied
      target - 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 array
      length - number of array entries to be copied
      target - target array
      index - 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 array
      index - index of first entry to copy
      length - number of array entries to be copied
      target - 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 array
      target - 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 resized
      index - 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 sort
      ascending - 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 exceed MAX_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 capacity
      factor - 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 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 be null)
      tokens2 - second tokens (can be null)
      Returns:
      result of check
    • equals

      public static boolean equals(Object[] arr1, Object[] arr2)
      Compares two arrays for equality.
      Parameters:
      arr1 - first array (can be null)
      arr2 - second array (can be null)
      Returns:
      result of check