RecordAggregator implements RecordTransformer { private Number aggregate(int[] values, int[] maskValues) { if (values.length == 1) { return isGoodPixel(maskValues, 0) ? values[0] : null; } float[] floats = new float[values.length]; for (int i = 0; i < floats.length; i++) { floats[i] = values[i]; } return aggregate(floats, maskValues); } RecordAggregator(int maskAttributeIndex, double filteredMeanCoeff); static RecordTransformer create(Header header, double filteredMeanCoeff); @Override Iterable<Record> transform(Iterable<Record> recordIterable); Record transform(Record record);  }
@Test public void testAggregate() throws Exception { int maskAttributeIndex = -1; Record aggregatedRecord = new RecordAggregator(maskAttributeIndex, 1.5).transform( createDataRecord(new float[]{0.2F, 1.2F, 1.2F, 1.4F, 1.8F}, new int[]{13, 10, 11, 32, 14}, new int[]{1, 0, 1, 1, 0})); assertNotNull(aggregatedRecord); testFirst4Values(aggregatedRecord); Object v5 = aggregatedRecord.getAttributeValues()[4]; assertEquals(AggregatedNumber.class, v5.getClass()); AggregatedNumber a5 = (AggregatedNumber) v5; assertEquals(5, a5.nT); assertEquals(4, a5.n); assertEquals(1, a5.nF); assertEquals(1.2, a5.min, 1E-6); assertEquals(1.8, a5.max, 1E-6); assertEquals(1.4, a5.mean, 1E-6); assertEquals(0.28284266, a5.sigma, 1E-6); assertEquals(a5.mean, a5.doubleValue(), 1E-6); assertArrayEquals(new float[]{0.2F, 1.2F, 1.2F, 1.4F, 1.8F}, a5.data, 1E-6F); Object v6 = aggregatedRecord.getAttributeValues()[5]; assertEquals(AggregatedNumber.class, v6.getClass()); AggregatedNumber a6 = (AggregatedNumber) v6; assertEquals(5, a6.nT); assertEquals(4, a6.n); assertEquals(1, a6.nF); assertEquals(10.0, a6.min, 1E-6); assertEquals(14.0, a6.max, 1E-6); assertEquals(12.0, a6.mean, 1E-6); assertEquals(1.825742, a6.sigma, 1E-6); assertEquals(a6.mean, a6.doubleValue(), 1E-6); assertArrayEquals(new float[]{13, 10, 11, 32, 14}, a6.data, 1E-6F); Object v7 = aggregatedRecord.getAttributeValues()[6]; assertEquals(AggregatedNumber.class, v7.getClass()); AggregatedNumber a7 = (AggregatedNumber) v7; assertEquals(5, a7.n); assertEquals(5, a7.nT); assertEquals(0.0, a7.min, 1E-6); assertEquals(1.0, a7.max, 1E-6); assertEquals(0.6, a7.mean, 1E-6); assertEquals(a7.mean, a7.doubleValue(), 1E-6); assertArrayEquals(new float[]{1, 0, 1, 1, 0}, a7.data, 1E-6F); }