Skip to content

Commit

Permalink
Special-case arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmitterdorfer committed Feb 1, 2024
1 parent 3bede77 commit 55b910b
Showing 1 changed file with 65 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,51 +252,22 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
}
builder.endArray();
traceStop("Edges");
traceStart("FileID");
builder.field("FileID", fileIds);
traceStop("FileID");
traceStart("FrameType");
builder.field("FrameType", frameTypes);
traceStop("FrameType");
traceStart("Inline");
builder.field("Inline", inlineFrames);
traceStop("Inline");
traceStart("ExeFilename");
builder.field("ExeFilename", fileNames);
traceStop("ExeFilename");
traceStart("AddressOrLine");
builder.field("AddressOrLine", addressOrLines);
traceStop("AddressOrLine");
traceStart("FunctionName");
builder.field("FunctionName", functionNames);
traceStop("FunctionName");
traceStart("FunctionOffset");
builder.field("FunctionOffset", functionOffsets);
traceStop("FunctionOffset");
traceStart("SourceFilename");
builder.field("SourceFilename", sourceFileNames);
traceStop("SourceFilename");
traceStart("SourceLine");
builder.field("SourceLine", sourceLines);
traceStop("SourceLine");
traceStart("CountInclusive");
builder.field("CountInclusive", countInclusive);
traceStop("CountInclusive");
traceStart("CountExclusive");
builder.field("CountExclusive", countExclusive);
traceStop("CountExclusive");
traceStart("AnnualCO2TonsInclusive");
builder.field("AnnualCO2TonsInclusive", annualCO2TonsInclusive);
traceStop("AnnualCO2TonsInclusive");
traceStart("AnnualCO2TonsExclusive");
builder.field("AnnualCO2TonsExclusive", annualCO2TonsExclusive);
traceStop("AnnualCO2TonsExclusive");
traceStart("AnnualCostsUSDInclusive");
builder.field("AnnualCostsUSDInclusive", annualCostsUSDInclusive);
traceStop("AnnualCostsUSDInclusive");
traceStart("AnnualCostsUSDExclusive");
builder.field("AnnualCostsUSDExclusive", annualCostsUSDExclusive);
traceStop("AnnualCostsUSDExclusive");
stringArray(builder, "FileID", fileIds);
intArray(builder, "FrameType", frameTypes);
boolArray(builder, "Inline", inlineFrames);
stringArray(builder, "ExeFilename", fileNames);
intArray(builder, "AddressOrLine", addressOrLines);
stringArray(builder, "FunctionName", functionNames);
intArray(builder, "FunctionOffset", functionOffsets);
stringArray(builder,"SourceFilename", sourceFileNames);
intArray(builder, "SourceLine", sourceLines);
longArray(builder, "CountInclusive", countInclusive);
longArray(builder, "CountExclusive", countExclusive);
doubleArray(builder, "AnnualCO2TonsInclusive", annualCO2TonsInclusive);
doubleArray(builder, "AnnualCO2TonsExclusive", annualCO2TonsExclusive);
doubleArray(builder, "AnnualCostsUSDInclusive", annualCostsUSDInclusive);
doubleArray(builder, "AnnualCostsUSDExclusive", annualCostsUSDExclusive);

traceStart("Size");
builder.field("Size", size);
traceStop("Size");
Expand All @@ -317,6 +288,55 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder;
}

private void stringArray(XContentBuilder builder, String name, Iterable<String> values) throws IOException {
traceStart(name);
builder.startArray(name);
for (String value : values) {
builder.value(value);
}
builder.endArray();
traceStop(name);
}

private void intArray(XContentBuilder builder, String name, Iterable<Integer> values) throws IOException {
traceStart(name);
builder.startArray(name);
for (int value : values) {
builder.value(value);
}
builder.endArray();
traceStop(name);
}

private void longArray(XContentBuilder builder, String name, Iterable<Long> values) throws IOException {
traceStart(name);
builder.startArray(name);
for (long value : values) {
builder.value(value);
}
builder.endArray();
traceStop(name);
}

private void doubleArray(XContentBuilder builder, String name, Iterable<Double> values) throws IOException {
traceStart(name);
builder.startArray(name);
for (double value : values) {
builder.value(value);
}
builder.endArray();
traceStop(name);
}
private void boolArray(XContentBuilder builder, String name, Iterable<Boolean> values) throws IOException {
traceStart(name);
builder.startArray(name);
for (boolean value : values) {
builder.value(value);
}
builder.endArray();
traceStop(name);
}

@Override
public boolean isFragment() {
return false;
Expand Down

0 comments on commit 55b910b

Please sign in to comment.