### Question:
Utils { public static void mergeSortedInto( long[] values, long[] into, int intoLengthBefore ) { int v = values.length - 1; int i = intoLengthBefore - 1; int t = i + values.length; while ( v >= 0 || i >= 0 ) { if ( i == -1 ) { into[t--] = values[v--]; } else if ( v == -1 ) { into[t--] = into[i--]; } else if ( values[v] >= into[i] ) { into[t--] = values[v--]; } else { into[t--] = into[i--]; } } } private  Utils(); static boolean unsignedCompare( long dataA, long dataB, CompareType compareType ); static CompareType unsignedDifference( long dataA, long dataB ); static boolean anyIdCollides( long[] first, int firstLength, long[] other, int otherLength ); static void mergeSortedInto( long[] values, long[] into, int intoLengthBefore );  }### Answer:
@Test public void shouldMergeIdsInto() { long[] values = new long[]{2, 4, 10, 11, 14}; long[] into = new long[]{1, 5, 6, 11, 25}; int intoLengthBefore = into.length; into = Arrays.copyOf( into, into.length + values.length ); Utils.mergeSortedInto( values, into, intoLengthBefore ); assertArrayEquals( new long[] {1, 2, 4, 5, 6, 10, 11, 11, 14, 25}, into ); }
@Test public void shouldMergeSomeRandomIdsInto() { Random random = ThreadLocalRandom.current(); int batchSize = 10_000; for ( int i = 0; i < 100; i++ ) { long[] values = randomBatch( batchSize, random, 100_000_000 ); long[] into = randomBatch( batchSize, random, 100_000_000 ); long[] expectedMergedArray = manuallyMerge( values, into ); into = Arrays.copyOf( into, batchSize * 2 ); Utils.mergeSortedInto( values, into, batchSize ); assertArrayEquals( expectedMergedArray, into ); } }