Skip to content

Commit 358ec7d

Browse files
committed
Use Map.compute to optimize counting
1 parent 81629ee commit 358ec7d

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

modules/core/src/main/java/org/locationtech/jts/coverage/CoverageRingEdges.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ private Set<Coordinate> findMultiRingNodes(Geometry[] coverage) {
320320
private Set<Coordinate> findBoundaryNodes(Set<LineSegment> boundarySegments) {
321321
Map<Coordinate, Integer> counter = new HashMap<>();
322322
for (LineSegment seg : boundarySegments) {
323-
counter.put(seg.p0, counter.getOrDefault(seg.p0, 0) + 1);
324-
counter.put(seg.p1, counter.getOrDefault(seg.p1, 0) + 1);
323+
counter.compute(seg.p0, (key, value) -> value == null ? 1 : value + 1);
324+
counter.compute(seg.p1, (key, value) -> value == null ? 1 : value + 1);
325325
}
326326
return counter.entrySet().stream()
327327
.filter(e->e.getValue() > 2)

modules/core/src/main/java/org/locationtech/jts/coverage/VertexRingCounter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ public void filter(CoordinateSequence seq, int i) {
5151
if (CoordinateSequences.isRing(seq) && i == 0)
5252
return;
5353
Coordinate v = seq.getCoordinate(i);
54-
int count = vertexRingCount.containsKey(v) ? vertexRingCount.get(v) : 0;
55-
count++;
56-
vertexRingCount.put(v, count);
54+
vertexRingCount.compute(v, (key, val) -> val == null ? 1 : val + 1);
5755
}
5856

5957
@Override

0 commit comments

Comments
 (0)