Class ArrayUtil

java.lang.Object
org.eclipse.jetty.util.ArrayUtil

public class ArrayUtil extends Object
Utility methods for Array manipulation
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T[]
    add(T[] array1, T[] array2)
    Add arrays
    static <T> T[]
    addToArray(T[] array, T item, Class<?> type)
    Add element to an array
    static <E> List<E>
    asMutableList(E[] array)
     
    static byte[]
    grow(byte[] array, int addCapacity, int maxCapacity)
    Copies an existing byte array into a newly allocated, bigger one.
    static <T> T[]
    grow(T[] array, int addCapacity, int maxCapacity)
    Copies an existing object array into a newly allocated, bigger one.
    static int
    growCapacity(int currentCapacity, int addCapacity, int maxCapacity)
    Calculates a new array capacity based on existing length, required capacity and maximum capacity.
    static <T> T[]
    prependToArray(T item, T[] array, Class<?> type)
    Add element to the start of an array
    static <T> T[]
    removeFromArray(T[] array, Object item)
     
    static <T> T[]
    removeNulls(T[] array)
     

    Methods inherited from class java.lang.Object

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

    • removeFromArray

      public static <T> T[] removeFromArray(T[] array, Object item)
    • add

      public static <T> T[] add(T[] array1, T[] array2)
      Add arrays
      Type Parameters:
      T - the array entry type
      Parameters:
      array1 - An array to add to (or null)
      array2 - An array to add to (or null)
      Returns:
      new array with contents of both arrays, or null if both arrays are null
    • addToArray

      public static <T> T[] addToArray(T[] array, T item, Class<?> type)
      Add element to an array
      Type Parameters:
      T - the array entry type
      Parameters:
      array - The array to add to (or null)
      item - The item to add
      type - The type of the array (in case of null array)
      Returns:
      new array with contents of array plus item
    • prependToArray

      public static <T> T[] prependToArray(T item, T[] array, Class<?> type)
      Add element to the start of an array
      Type Parameters:
      T - the array entry type
      Parameters:
      array - The array to add to (or null)
      item - The item to add
      type - The type of the array (in case of null array)
      Returns:
      new array with contents of array plus item
    • asMutableList

      public static <E> List<E> asMutableList(E[] array)
      Type Parameters:
      E - the array entry type
      Parameters:
      array - Any array of object
      Returns:
      A new modifiable list initialised with the elements from array.
    • removeNulls

      public static <T> T[] removeNulls(T[] array)
    • growCapacity

      public static int growCapacity(int currentCapacity, int addCapacity, int maxCapacity) throws IllegalArgumentException
      Calculates a new array capacity based on existing length, required capacity and maximum capacity.
      Parameters:
      currentCapacity - the array's current capacity
      addCapacity - the extra capacity to add
      maxCapacity - the array's maximum capacity
      Returns:
      the calculated new array size
      Throws:
      IllegalArgumentException - when currentCapacity or maxCapacity is < 0, or when addCapacity is <= 0, or when it is not possible to get a new capacity using the given arguments without going over maxCapacity.
    • grow

      public static byte[] grow(byte[] array, int addCapacity, int maxCapacity) throws IllegalArgumentException
      Copies an existing byte array into a newly allocated, bigger one.
      Parameters:
      array - the existing array
      addCapacity - the extra capacity to add
      maxCapacity - the array's maximum capacity
      Returns:
      the grown array copy.
      Throws:
      IllegalArgumentException - when currentCapacity or maxCapacity is < 0, or when addCapacity is <= 0, or when it is not possible to get a bigger array without going over maxCapacity.
    • grow

      public static <T> T[] grow(T[] array, int addCapacity, int maxCapacity) throws IllegalArgumentException
      Copies an existing object array into a newly allocated, bigger one.
      Parameters:
      array - the existing array
      addCapacity - the extra capacity to add
      maxCapacity - the array's maximum capacity
      Returns:
      the grown array copy.
      Throws:
      IllegalArgumentException - when currentCapacity or maxCapacity is < 0, or when addCapacity is <= 0, or when it is not possible to get a bigger array without going over maxCapacity.