[Minor] added GenericReport.getOrderedColumnKeys()

This commit is contained in:
Robert von Burg 2017-03-27 14:04:39 +02:00
parent 3935a425e0
commit a982097d4f
2 changed files with 12 additions and 5 deletions

View File

@ -77,8 +77,11 @@ public class GenericReport {
return this;
}
public Set<String> getColumnKeys() {
return this.columnIds;
public List<String> getOrderedColumnKeys() {
return this.columnsBag.getParameters().stream() //
.sorted((p1, p2) -> Integer.compare(p1.getIndex(), p2.getIndex())) //
.map(p -> p.getId()) //
.collect(Collectors.toList());
}
public GenericReport filter(String type, String... ids) {
@ -122,7 +125,7 @@ public class GenericReport {
public Stream<ReportElement> doReport() {
return buildStream().map(e -> new ReportElement(getColumnKeys(), columnId -> {
return buildStream().map(e -> new ReportElement(this.columnIds, columnId -> {
StringParameter columnDefP = (StringParameter) this.columnsBag.getParameter(columnId);
return evaluateColumnValue(columnDefP, e);
}));
@ -191,7 +194,7 @@ public class GenericReport {
return doReport().map(e -> {
JsonObject o = new JsonObject();
e.stream().forEach(elem -> o.addProperty(elem.getKey(), elem.getValue()));
e.keyValueStream().forEach(elem -> o.addProperty(elem.getKey(), elem.getValue()));
return o;
});
}

View File

@ -24,7 +24,11 @@ public class ReportElement {
return this.columnGetter.apply(key);
}
public Stream<SimpleEntry<String, String>> stream() {
public Stream<SimpleEntry<String, String>> keyValueStream() {
return this.columnKeys.stream().map(k -> new SimpleEntry<>(k, this.columnGetter.apply(k)));
}
public Stream<String> valueStream() {
return this.columnKeys.stream().map(k -> this.columnGetter.apply(k));
}
}