content: package io.github.tapcard.emvnfccard.parser;
  
  /**
   * Part of Apache commons ArrayUtils
   */
  
  @SuppressWarnings("SameParameterValue")
  class ArrayUtils {
  
      /**
       * An empty immutable {@code String} array.
       */
      static final String[] EMPTY_STRING_ARRAY = new String[0];
  
      /**
       * <p>Clones an array returning a typecast result and handling
       * {@code null}.</p>
       *
       * <p>This method returns {@code null} for a {@code null} input array.</p>
       *
       * @param array  the array to clone, may be {@code null}
       * @return the cloned array, {@code null} if {@code null} input
       */
      private static byte[] clone(byte[] array) {
          if (array == null) {
              return null;
          }
          return array.clone();
      }
  
      /**
       * <p>Adds all the elements of the given arrays into a new array.</p>
       * <p>The new array contains all of the element of {@code array1} followed
       * by all of the elements {@code array2}. When an array is returned, it is always
       * a new array.</p>
       *
       * <pre>
       * ArrayUtils.addAll(array1, null)   = cloned copy of array1
       * ArrayUtils.addAll(null, array2)   = cloned copy of array2
       * ArrayUtils.addAll([], [])         = []
       * </pre>
       *
       * @param array1  the first array whose elements are added to the new array.
       * @param array2  the second array whose elements are added to the new array.
       * @return The new byte[] array.
       * @since 2.1
       */
      static byte[] addAll(byte[] array1, byte... array2) {
          if (array1 == null) {
              return clone(array2);
          } else if (array2 == null) {
              return clone(array1);
          }
          byte[] joinedArray = new byte[array1.length + array2.length];
          System.arraycopy(array1, 0, joinedArray, 0, array1.length);
          System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
          return joinedArray;
      }
  
      /**
       * An empty immutable {@code byte} array.
       */
      private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
  
      /**
       * <p>Produces a new {@code byte} array containing the elements
       * between the start and end indices.</p>
       *
       * <p>The start index is inclusive, the end index exclusive.
       * Null array input produces null output.</p>
       *
       * @param array  the array
       * @param startIndexInclusive  the starting index. Undervalue (&lt;0)
       *      is promoted to 0, overvalue (&gt;array.length) results
       *      in an empty array.
       * @param endIndexExclusive  elements up to endIndex-1 are present in the
       *      returned subarray. Undervalue (&lt; startIndex) produces
       *      empty array, overvalue (&gt;array.length) is demoted to
       *      array length.
       * @return a new array containing the elements between
       *      the start and end indices.
       * @since 2.1
       */
      static byte[] subarray(byte[] array, int startIndexInclusive, int endIndexExclusive) {
          if (array == null) {
              return null;
          }
          if (startIndexInclusive < 0) {
              startIndexInclusive = 0;
          }
          if (endIndexExclusive > array.length) {
              endIndexExclusive = array.length;
          }
          int newSize = endIndexExclusive - startIndexInclusive;
          if (newSize <= 0) {
              return EMPTY_BYTE_ARRAY;
          }
  
          byte[] subarray = new byte[newSize];
          System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
          return subarray;
      }
  
  }
  