Skip to content

Commit

Permalink
minor change
Browse files Browse the repository at this point in the history
  • Loading branch information
clausnagel committed Jan 2, 2025
1 parent b7296c2 commit 39efaa9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void visit(Between between) {
@Override
public void visit(BinaryBooleanPredicate predicate) {
startOp(predicate.getOperator().getJSONToken().value());
writeList(predicate.getOperands(), jsonWriter::writeComma);
writeList(predicate.getOperands(), jsonWriter);
endOp();
}

Expand Down Expand Up @@ -163,7 +163,7 @@ public void visit(Function function) {
negate(function);
} else {
startOp(function.getName().getJsonToken());
writeList(function.getArguments(), jsonWriter::writeComma);
writeList(function.getArguments(), jsonWriter);
endOp();
}
}
Expand All @@ -182,7 +182,7 @@ public void visit(In in) {
in.getOperand().accept(this);
jsonWriter.writeComma();
jsonWriter.startArray();
writeList(in.getValues(), jsonWriter::writeComma);
writeList(in.getValues(), jsonWriter);
jsonWriter.endArray();
endOp();
}
Expand Down Expand Up @@ -296,18 +296,13 @@ private void negate(NumericExpression expression) {
expression.negate();
}

private void writeList(List<? extends Expression> expressions, DelimiterWriter delimiter) {
private void writeList(List<? extends Expression> expressions, JSONWriter writer) {
for (int i = 0; i < expressions.size(); i++) {
expressions.get(i).accept(this);
if (i < expressions.size() - 1) {
delimiter.write();
if (i != 0) {
writer.writeComma();
}
expressions.get(i).accept(this);
}
}
}

@FunctionalInterface
private interface DelimiterWriter {
void write();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ private void writeMultiPoint(MultiPoint multiPoint) {

if (!multiPoint.getPoints().isEmpty()) {
for (int i = 0; i < multiPoint.getPoints().size(); i++) {
writeCoordinate(multiPoint.getPoints().get(i).getCoordinate());
if (i < multiPoint.getPoints().size() - 1) {
if (i != 0) {
jsonWriter.writeComma();
}
writeCoordinate(multiPoint.getPoints().get(i).getCoordinate());
}
}

Expand All @@ -93,10 +93,10 @@ private void writeMultiLineString(MultiLineString multiLineString) {
if (!multiLineString.getLineStrings().isEmpty()) {
jsonWriter.startArray();
for (int i = 0; i < multiLineString.getLineStrings().size(); i++) {
writeCoordinates(multiLineString.getLineStrings().get(i));
if (i < multiLineString.getLineStrings().size() - 1) {
if (i != 0) {
jsonWriter.writeComma();
}
writeCoordinates(multiLineString.getLineStrings().get(i));
}
jsonWriter.endArray();
}
Expand All @@ -112,10 +112,10 @@ private void writeMultiSurface(SurfaceCollection<?> surfaceCollection) {
if (!surfaceCollection.getPolygons().isEmpty()) {
jsonWriter.startArray();
for (int i = 0; i < surfaceCollection.getPolygons().size(); i++) {
writeCoordinates(surfaceCollection.getPolygons().get(i));
if (i < surfaceCollection.getPolygons().size() - 1) {
if (i != 0) {
jsonWriter.writeComma();
}
writeCoordinates(surfaceCollection.getPolygons().get(i));
}
jsonWriter.endArray();
}
Expand All @@ -139,19 +139,19 @@ private void writeCoordinate(Coordinate coordinate) {

private void writeCoordinates(LineString lineString) {
for (int i = 0; i < lineString.getPoints().size(); i++) {
writeCoordinate(lineString.getPoints().get(i));
if (i < lineString.getPoints().size() - 1) {
if (i != 0) {
jsonWriter.writeComma();
}
writeCoordinate(lineString.getPoints().get(i));
}
}

private void writeCoordinates(LinearRing linearRing) {
for (int i = 0; i < linearRing.getPoints().size(); i++) {
writeCoordinate(linearRing.getPoints().get(i));
if (i < linearRing.getPoints().size() - 1) {
if (i != 0) {
jsonWriter.writeComma();
}
writeCoordinate(linearRing.getPoints().get(i));
}
}

Expand All @@ -163,12 +163,12 @@ private void writeCoordinates(Polygon polygon) {
if (polygon.hasInteriorRings()) {
jsonWriter.writeComma();
for (int i = 0; i < polygon.getInteriorRings().size(); i++) {
if (i != 0) {
jsonWriter.writeComma();
}
jsonWriter.startArray();
writeCoordinates(polygon.getInteriorRings().get(i));
jsonWriter.endArray();
if (i < polygon.getInteriorRings().size() - 1) {
jsonWriter.writeComma();
}
}
}
}
Expand Down

0 comments on commit 39efaa9

Please sign in to comment.