|
21 | 21 | import java.io.OutputStream;
|
22 | 22 | import java.util.ArrayList;
|
23 | 23 | import java.util.Collections;
|
24 |
| -import java.util.HashMap; |
25 | 24 | import java.util.List;
|
26 | 25 | import java.util.Map;
|
| 26 | +import java.util.concurrent.ConcurrentHashMap; |
27 | 27 |
|
28 | 28 | /**
|
29 | 29 | * GeoShape representing a path across the surface of the globe, with a specified half-width. Path
|
@@ -1070,7 +1070,7 @@ private static class PathSegment {
|
1070 | 1070 | /** End point of the segment */
|
1071 | 1071 | public final GeoPoint end;
|
1072 | 1072 | /** Place to keep any complete segment distances we've calculated so far */
|
1073 |
| - public final Map<DistanceStyle, Double> fullDistanceCache = new HashMap<>(); |
| 1073 | + public final Map<DistanceStyle, Double> fullDistanceCache = new ConcurrentHashMap<>(); |
1074 | 1074 | /** Normalized plane connecting the two points and going through world center */
|
1075 | 1075 | public final Plane normalizedConnectingPlane;
|
1076 | 1076 | /** Cutoff plane parallel to connecting plane representing one side of the path segment */
|
@@ -1175,16 +1175,14 @@ public PathSegment(
|
1175 | 1175 | * @return the distance metric, in aggregation form.
|
1176 | 1176 | */
|
1177 | 1177 | public double fullPathDistance(final DistanceStyle distanceStyle) {
|
1178 |
| - synchronized (fullDistanceCache) { |
1179 |
| - Double dist = fullDistanceCache.get(distanceStyle); |
1180 |
| - if (dist == null) { |
1181 |
| - dist = |
1182 |
| - distanceStyle.toAggregationForm( |
1183 |
| - distanceStyle.computeDistance(start, end.x, end.y, end.z)); |
1184 |
| - fullDistanceCache.put(distanceStyle, dist); |
1185 |
| - } |
1186 |
| - return dist.doubleValue(); |
| 1178 | + Double dist = fullDistanceCache.get(distanceStyle); |
| 1179 | + if (dist == null) { |
| 1180 | + dist = |
| 1181 | + distanceStyle.toAggregationForm( |
| 1182 | + distanceStyle.computeDistance(start, end.x, end.y, end.z)); |
| 1183 | + fullDistanceCache.put(distanceStyle, dist); |
1187 | 1184 | }
|
| 1185 | + return dist.doubleValue(); |
1188 | 1186 | }
|
1189 | 1187 |
|
1190 | 1188 | /**
|
|
0 commit comments