Class VarargsUtil

java.lang.Object
org.javagi.interop.VarargsUtil

@NullMarked public class VarargsUtil extends Object
Utility functions to split an array of variadic arguments into a first argument and a null-terminated array of remaining arguments.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> @Nullable T
    first(@Nullable T @Nullable [] array)
    Return the first array element.
    static <T> @Nullable T @Nullable []
    rest(@Nullable T @Nullable [] array)
    Return all but the first array elements, terminated with a null.

    Methods inherited from class Object

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

    • VarargsUtil

      public VarargsUtil()
  • Method Details

    • first

      public static <T> @Nullable T first(@Nullable T @Nullable [] array)
      Return the first array element.
      Type Parameters:
      T - array element type
      Parameters:
      array - input array, can be null
      Returns:
      the first element, or null if the input array is null or empty
    • rest

      public static <T> @Nullable T @Nullable [] rest(@Nullable T @Nullable [] array)
      Return all but the first array elements, terminated with a null. For example, [1, 2, 3] returns [2, 3, null].
      Type Parameters:
      T - array element type
      Parameters:
      array - input array, can be null
      Returns:
      a new array of all elements except the first, terminated with a null, or null if the input array is null or empty