diff --git a/citydb-query/src/main/java/org/citydb/query/filter/encoding/FilterJSONWriter.java b/citydb-query/src/main/java/org/citydb/query/filter/encoding/FilterJSONWriter.java index b5ff18d9..3c73f529 100644 --- a/citydb-query/src/main/java/org/citydb/query/filter/encoding/FilterJSONWriter.java +++ b/citydb-query/src/main/java/org/citydb/query/filter/encoding/FilterJSONWriter.java @@ -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(); } @@ -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(); } } @@ -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(); } @@ -296,18 +296,13 @@ private void negate(NumericExpression expression) { expression.negate(); } - private void writeList(List expressions, DelimiterWriter delimiter) { + private void writeList(List 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(); - } } diff --git a/citydb-query/src/main/java/org/citydb/query/filter/encoding/GeoJSONWriter.java b/citydb-query/src/main/java/org/citydb/query/filter/encoding/GeoJSONWriter.java index 4390d5a1..1618a0b0 100644 --- a/citydb-query/src/main/java/org/citydb/query/filter/encoding/GeoJSONWriter.java +++ b/citydb-query/src/main/java/org/citydb/query/filter/encoding/GeoJSONWriter.java @@ -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()); } } @@ -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(); } @@ -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(); } @@ -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)); } } @@ -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(); - } } } }