RecordMerger { void processHeader(String[] insituAttributeNames, Iterable<IndexedRecordWritable> records) throws IOException { List<Object> attributeNameList = new ArrayList<>(); startAttributeIndex[0] = 0; numAttributes[0] = insituAttributeNames.length; startAttributeIndex[1] = startAttributeIndex[0] + insituAttributeNames.length; for (String insituAttributeName : insituAttributeNames) { attributeNameList.add("insitu_" + insituAttributeName); } int index = 1; for (IndexedRecordWritable recordWritable : records) { Object[] attributeNames = recordWritable.getAttributeValues(); numAttributes[index] = attributeNames.length; index++; if (index < startAttributeIndex.length) { startAttributeIndex[index] = startAttributeIndex[index - 1] + attributeNames.length; } Collections.addAll(attributeNameList, attributeNames); } Object[] attributeValues = attributeNameList.toArray(new Object[attributeNameList.size()]); numAttributeValues = startAttributeIndex[numAttributes.length - 1] + numAttributes[numAttributes.length - 1]; all.processHeaderRecord(attributeValues, ANNOTATION_VALUES); common.processHeaderRecord(attributeValues, ANNOTATION_VALUES); for (RecordProcessor individual : individuals) { individual.processHeaderRecord(attributeValues, ANNOTATION_VALUES); } } RecordMerger(String[] identifiers, RecordProcessor all, RecordProcessor common, RecordProcessor... individuals); void finalizeRecordProcessing();  }
@Test public void processHeader() throws Exception { recordMerger.processHeader(insituAttributeNames, headerValues); String[] expected = {"insitu_a", "insitu_b", "p1_m", "p1_n", "p2_o", "p2_q"}; assertArrayEquals(expected, rpAll.headerAttributes.toArray()); assertArrayEquals(expected, rpCBQ.headerAttributes.toArray()); assertArrayEquals(expected, rpIBQp1.headerAttributes.toArray()); assertArrayEquals(expected, rpIBQp2.headerAttributes.toArray()); expected = new String[]{""}; assertArrayEquals(expected, rpAll.headerAnnotations.toArray()); assertArrayEquals(expected, rpCBQ.headerAnnotations.toArray()); assertArrayEquals(expected, rpIBQp1.headerAnnotations.toArray()); assertArrayEquals(expected, rpIBQp2.headerAnnotations.toArray()); }