Class ArrayUtils

java.lang.Object
org.springframework.data.gemfire.util.ArrayUtils

public abstract class ArrayUtils extends Object
ArrayUtils is an abstract utility class used to work with Object arrays.
Author:
David Turanski, John Blum
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static class 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T[]
    asArray(T... elements)
    Returns the given varargs element as an array.
    static <T> T[]
    defaultIfEmpty(T[] array, T[] defaultArray)
    Returns the given array if not null or empty, otherwise returns the defaultArray.
    static <T> T
    getFirst(T[] array)
    Null-safe method to return the first element in the array or null if the array is null or empty.
    static <T> T
    getFirst(T[] array, T defaultValue)
    Null-safe method to return the first element in the array or the defaultValue if the array is null or empty.
    static Object[]
    insert(Object[] originalArray, int position, Object element)
    Insert an element into the given array at position (index).
    static boolean
    isEmpty(Object[] array)
    Determines whether the given array is empty or not.
    static boolean
    isNotEmpty(Object[] array)
    Determines whether the given array is empty or not.
    static int
    length(Object[] array)
    Null-safe operation to determine an array's length.
    static <T> T[]
    nullSafeArray(T[] array, Class<T> componentType)
    Null-safe, empty array operation returning the given object array if not null or an empty object array if the array argument is null.
    static Object[]
    remove(Object[] originalArray, int position)
    Remove an element from the given array at position (index).
    static <T extends Comparable<T>>
    T[]
    sort(T[] array)
    Sort the array of elements according to the elements natural ordering.
    static <T> Iterable<T>
    toIterable(T... array)
    Converts the given array into an Iterable object.

    Methods inherited from class java.lang.Object

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

    • ArrayUtils

      public ArrayUtils()
  • Method Details

    • asArray

      @SafeVarargs public static <T> T[] asArray(T... elements)
      Returns the given varargs element as an array.
      Type Parameters:
      T - Class type of the elements.
      Parameters:
      elements - variable list of arguments to return as an array.
      Returns:
      an arry for the given varargs elements.
    • defaultIfEmpty

      @Nullable public static <T> T[] defaultIfEmpty(@Nullable T[] array, @Nullable T[] defaultArray)
      Returns the given array if not null or empty, otherwise returns the defaultArray.
      Type Parameters:
      T - Class type of the array elements.
      Parameters:
      array - array to evaluate.
      defaultArray - array to return if the given array is null or empty.
      Returns:
      the given array if not null or empty otherwise return the defaultArray.
    • getFirst

      @Nullable public static <T> T getFirst(@Nullable T[] array)
      Null-safe method to return the first element in the array or null if the array is null or empty.
      Type Parameters:
      T - Class type of the array elements.
      Parameters:
      array - the array from which to extract the first element.
      Returns:
      the first element in the array or null if the array is null or empty.
      See Also:
    • getFirst

      @Nullable public static <T> T getFirst(@Nullable T[] array, @Nullable T defaultValue)
      Null-safe method to return the first element in the array or the defaultValue if the array is null or empty.
      Type Parameters:
      T - Class type of the array elements.
      Parameters:
      array - the array from which to extract the first element.
      defaultValue - value to return if the array is null or empty.
      Returns:
      the first element in the array or defaultValue if the array is null or empty.
      See Also:
    • insert

      @NonNull public static Object[] insert(@NonNull Object[] originalArray, int position, Object element)
      Insert an element into the given array at position (index). The element is inserted at the given position and all elements afterwards are moved to the right.
      Parameters:
      originalArray - the array in which to insert the element.
      position - an integer index (position) at which to insert the element in the array.
      element - the element to insert into the array.
      Returns:
      a new array with the element inserted at position.
      See Also:
    • isEmpty

      public static boolean isEmpty(@Nullable Object[] array)
      Determines whether the given array is empty or not.
      Parameters:
      array - the array to evaluate for emptiness.
      Returns:
      a boolean value indicating whether the given array is empty.
      See Also:
    • isNotEmpty

      public static boolean isNotEmpty(@Nullable Object[] array)
      Determines whether the given array is empty or not.
      Parameters:
      array - the array to evaluate for emptiness.
      Returns:
      a boolean value indicating whether the given array is empty.
      See Also:
    • length

      public static int length(@Nullable Object[] array)
      Null-safe operation to determine an array's length.
      Parameters:
      array - the array to determine it's length.
      Returns:
      the length of the given array or 0 if the array reference is null.
    • nullSafeArray

      public static <T> T[] nullSafeArray(@Nullable T[] array, @NonNull Class<T> componentType)
      Null-safe, empty array operation returning the given object array if not null or an empty object array if the array argument is null.
      Type Parameters:
      T - Class type of the array elements.
      Parameters:
      array - array of objects on which a null check is performed.
      componentType - Class type of the array elements.
      Returns:
      the given object array if not null, otherwise return an empty object array.
      See Also:
    • remove

      public static Object[] remove(@NonNull Object[] originalArray, int position)
      Remove an element from the given array at position (index). The element is removed at the specified position and all remaining elements are shifted to the left.
      Parameters:
      originalArray - the array from which to remove the element.
      position - the integer index (position) indicating the element to remove from the array.
      Returns:
      a new array with the element at position in the originalArray removed.
      See Also:
    • sort

      @NonNull public static <T extends Comparable<T>> T[] sort(@NonNull T[] array)
      Sort the array of elements according to the elements natural ordering.
      Type Parameters:
      T - Comparable class type of the array elements.
      Parameters:
      array - array of elements to sort.
      Returns:
      the sorted array of elements.
      See Also:
    • toIterable

      @NonNull public static <T> Iterable<T> toIterable(@NonNull T... array)
      Converts the given array into an Iterable object.
      Type Parameters:
      T - type of the array elements; mut not be null.
      Parameters:
      array - array to convert to an Iterable.
      Returns:
      an Iterable object from the given array.
      Throws:
      IllegalArgumentException - if the array is null.
      See Also: