Accumulator { public void accumulateNoNaN(float... samples) { float[] buffer = new float[samples.length]; int i = 0; for (float sample : samples) { if (!Float.isNaN(sample)) { buffer[i++] = sample; } } if (i > 0) { values = concat(values, buffer, i); } } Accumulator(); void accumulateNoNaN(float... samples); void accumulate(float... samples); float[] getValues();  }
@Test public void testAccumulateNoNaN() throws Exception { Accumulator acc = new Accumulator(); acc.accumulateNoNaN(Float.NaN, Float.NaN); assertArrayEquals(new float[0], acc.getValues(), 1E-5f); acc.accumulateNoNaN(1, Float.NaN, 2, 3); assertArrayEquals(new float[]{1, 2, 3}, acc.getValues(), 1E-5f); }