use of com.revolsys.record.schema.RecordDefinitionBuilder in project com.revolsys.open by revolsys.
the class CategoryLabelCountMap method writeCounts.
public void writeCounts(final Object target, final String labelTitle, final Iterable<String> categoryNames) {
final RecordDefinitionBuilder recordDefinitionBuilder = new RecordDefinitionBuilder("Counts");
recordDefinitionBuilder.addField(labelTitle, DataTypes.STRING, 50);
final Set<String> allLabels = new TreeSet<>();
final List<String> matchedCategoryNames = new ArrayList<>();
for (final String categoryName : categoryNames) {
final LabelCountMap labelCountMap = this.labelCountMapByCategory.get(categoryName);
if (labelCountMap != null) {
matchedCategoryNames.add(categoryName);
recordDefinitionBuilder.addField(categoryName, DataTypes.LONG, 10);
final Set<String> labels = labelCountMap.getLabels();
allLabels.addAll(labels);
}
}
final RecordDefinition recordDefinition = recordDefinitionBuilder.getRecordDefinition();
try (RecordWriter recordWriter = RecordWriter.newRecordWriter(recordDefinition, target)) {
final List<Object> row = new ArrayList<>(matchedCategoryNames.size() + 1);
for (final String label : allLabels) {
row.clear();
row.add(label);
for (final String categoryName : matchedCategoryNames) {
final Long count = getCount(categoryName, label);
row.add(count);
}
recordWriter.write(row);
}
}
}
Aggregations