rulebook-core/src/main/java/com/deliveredtechnologies/rulebook/util/ArrayUtils.java
@SuppressWarnings("unchecked")
  public static <T> T[] combine(T[] array1, T[] array2, int maxElements) {
    if (array1.length == maxElements) {
      return array1;
    } else if (array1.length > maxElements) {
      T[] combinedArray = (T[])Array.newInstance(array1.getClass().getComponentType(), maxElements);
      System.arraycopy(array1, 0, combinedArray, 0, maxElements);
      return combinedArray;
    }

    maxElements = array1.length + array2.length >= maxElements ? maxElements : array1.length + array2.length;
    T[] combinedArray = (T[])Array.newInstance(array1.getClass().getComponentType(), maxElements);
    System.arraycopy(array1, 0, combinedArray, 0, array1.length);
    System.arraycopy(array2, 0, combinedArray, array1.length, maxElements - array1.length);
    return combinedArray;
  }
@SuppressWarnings("unchecked")
  public static <T> T[] combine(T[] array1, T[] array2, int maxElements) {
    if (array1.length == maxElements) {
      return array1;
    } else if (array1.length > maxElements) {
      T[] combinedArray = (T[])Array.newInstance(array1.getClass().getComponentType(), maxElements);
      System.arraycopy(array1, 0, combinedArray, 0, maxElements);
      return combinedArray;
    }

    maxElements = array1.length + array2.length >= maxElements ? maxElements : array1.length + array2.length;
    T[] combinedArray = (T[])Array.newInstance(array1.getClass().getComponentType(), maxElements);
    System.arraycopy(array1, 0, combinedArray, 0, array1.length);
    System.arraycopy(array2, 0, combinedArray, array1.length, maxElements - array1.length);
    return combinedArray;
  }
@ SuppressWarnings ( "unchecked" ) public static < T > T [ ] combine ( T [ ] array1 , T [ ] array2 , int maxElements ) { if ( array1 . length == maxElements ) { return array1 ; } else if ( array1 . length > maxElements ) { T [ ] combinedArray = ( T [ ] ) Array . newInstance ( array1 . getClass ( ) . getComponentType ( ) , maxElements ) ; System . arraycopy ( array1 , 0 , combinedArray , 0 , maxElements ) ; return combinedArray ; } maxElements = array1 . length + array2 . length >= maxElements ? maxElements : array1 . length + array2 . length ; T [ ] combinedArray = ( T [ ] ) Array . newInstance ( array1 . getClass ( ) . getComponentType ( ) , maxElements ) ; System . arraycopy ( array1 , 0 , combinedArray , 0 , array1 . length ) ; System . arraycopy ( array2 , 0 , combinedArray , array1 . length , maxElements - array1 . length ) ; return combinedArray ; }
The combine() static method combines the contents of two arrays into a single array of the same type that contains
no more than the maxElements number of elements.
@param array1      the array to be concatenated on the left
@param array2      the array to be concatenated on the right
@param maxElements the maximum number of elements in the resulting array
@param <T>         the type of array
@return            a concatenation of array1 and array2
The combine () static method combines the contents of two arrays into a single array of the same type that contains no more than the maxElements number of elements .