RecordAggregator implements RecordTransformer { @Override public Iterable<Record> transform(Iterable<Record> recordIterable) { return new Iterable<Record>() { @Override public Iterator<Record> iterator() { return new RecIt(recordIterable.iterator()); } }; } 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 testAggregateWithMask() throws Exception { int maskAttributeIndex = 6; Record aggregatedRecord = new RecordAggregator(maskAttributeIndex, 1.5).transform( createDataRecord(new float[]{1.1F, 1.2F, Float.NaN, 1.8F}, new int[]{64, 32, 16, 8}, new int[]{1, 1, 1, 0})); assertNotNull(aggregatedRecord); testFirst4Values(aggregatedRecord); Object v5 = aggregatedRecord.getAttributeValues()[4]; assertEquals(AggregatedNumber.class, v5.getClass()); AggregatedNumber a5 = (AggregatedNumber) v5; assertEquals(2, a5.n); assertEquals(3, a5.nT); assertEquals(0, a5.nF); assertEquals((1.1F + 1.2F) / 2, a5.floatValue(), 1E-5F); Object v6 = aggregatedRecord.getAttributeValues()[5]; assertEquals(AggregatedNumber.class, v6.getClass()); AggregatedNumber a6 = (AggregatedNumber) v6; assertEquals(3, a6.n); assertEquals(4, a6.nT); assertEquals(0, a6.nF); assertEquals((64F + 32F + 16F) / 3, a6.floatValue(), 1E-5F); Object v7 = aggregatedRecord.getAttributeValues()[6]; assertEquals(AggregatedNumber.class, v7.getClass()); AggregatedNumber a7 = (AggregatedNumber) v7; assertEquals(4, a7.n); assertEquals(4, a7.nT); assertEquals(0, a7.nF); assertEquals((1F + 1F + 1F) / 4, a7.floatValue(), 1E-5F); }
@Test public void testOneElementAggregationAllValid() throws Exception { int maskAttributeIndex = 6; Record aggregatedRecord = new RecordAggregator(maskAttributeIndex, 1.5).transform( createDataRecord(new float[]{1.1F}, new int[]{64}, new int[]{1})); assertNotNull(aggregatedRecord); testFirst4Values(aggregatedRecord); Object v5 = aggregatedRecord.getAttributeValues()[4]; assertEquals(Float.class, v5.getClass()); Float a5 = (Float) v5; assertEquals(1.1F, a5, 1E-5F); Object v6 = aggregatedRecord.getAttributeValues()[5]; assertEquals(Integer.class, v6.getClass()); assertEquals(64, v6); Object v7 = aggregatedRecord.getAttributeValues()[6]; assertEquals(Integer.class, v7.getClass()); assertEquals(1, v7); }
@Test public void testOneElementAggregationAllInvalid() throws Exception { int maskAttributeIndex = 6; float[] value5 = {1.1F}; int[] value6 = {64}; int[] mask = {0}; Record aggregatedRecord = new RecordAggregator(maskAttributeIndex, 1.5).transform( createDataRecord(value5, value6, mask)); assertNotNull(aggregatedRecord); testFirst4Values(aggregatedRecord); Object v5 = aggregatedRecord.getAttributeValues()[4]; assertEquals(Float.class, v5.getClass()); Float a5 = (Float) v5; assertTrue(Float.isNaN(a5)); Object v6 = aggregatedRecord.getAttributeValues()[5]; assertEquals(null, v6); Object v7 = aggregatedRecord.getAttributeValues()[6]; assertEquals(Integer.class, v7.getClass()); assertEquals(0, v7); }