CoderUtil { static <T> int[] getValidIndexes(T[] inputs) { int[] validIndexes = new int[inputs.length]; int idx = 0; for (int i = 0; i < inputs.length; i++) { if (inputs[i] != null) { validIndexes[idx++] = i; } } return Arrays.copyOf(validIndexes, idx); } private  CoderUtil();   }
@Test public void testGetValidIndexes() { byte[][] inputs = new byte[numInputs][]; inputs[0] = new byte[chunkSize]; inputs[1] = new byte[chunkSize]; inputs[7] = new byte[chunkSize]; inputs[8] = new byte[chunkSize]; int[] validIndexes = CoderUtil.getValidIndexes(inputs); assertEquals(4, validIndexes.length); assertEquals(0, validIndexes[0]); assertEquals(1, validIndexes[1]); assertEquals(7, validIndexes[2]); assertEquals(8, validIndexes[3]); }
@Test public void testNoValidIndexes() { byte[][] inputs = new byte[numInputs][]; for (int i = 0; i < numInputs; i++) { inputs[i] = null; } int[] validIndexes = CoderUtil.getValidIndexes(inputs); assertEquals(0, validIndexes.length); }