Changeset 13136 in josm
- Timestamp:
- 2017-11-20T01:25:31+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
r12725 r13136 107 107 * @param other existing GPX data 108 108 */ 109 public void mergeFrom(GpxData other) {109 public synchronized void mergeFrom(GpxData other) { 110 110 if (storageFile == null && other.storageFile != null) { 111 111 storageFile = other.storageFile; … … 125 125 } 126 126 } 127 other. getTracks().forEach(this::addTrack);128 other. getRoutes().forEach(this::addRoute);129 other. getWaypoints().forEach(this::addWaypoint);127 other.privateTracks.forEach(this::addTrack); 128 other.privateRoutes.forEach(this::addRoute); 129 other.privateWaypoints.forEach(this::addWaypoint); 130 130 dataSources.addAll(other.dataSources); 131 131 fireInvalidate(); … … 136 136 * @return The tracks. 137 137 */ 138 public Collection<GpxTrack> getTracks() {138 public synchronized Collection<GpxTrack> getTracks() { 139 139 return Collections.unmodifiableCollection(privateTracks); 140 140 } … … 145 145 * @since 12156 146 146 */ 147 public void addTrack(GpxTrack track) {147 public synchronized void addTrack(GpxTrack track) { 148 148 if (privateTracks.stream().anyMatch(t -> t == track)) { 149 149 throw new IllegalArgumentException(MessageFormat.format("The track was already added to this data: {0}", track)); … … 159 159 * @since 12156 160 160 */ 161 public void removeTrack(GpxTrack track) {161 public synchronized void removeTrack(GpxTrack track) { 162 162 if (!privateTracks.removeIf(t -> t == track)) { 163 163 throw new IllegalArgumentException(MessageFormat.format("The track was not in this data: {0}", track)); … … 172 172 * @since 12156 173 173 */ 174 public Collection<GpxRoute> getRoutes() {174 public synchronized Collection<GpxRoute> getRoutes() { 175 175 return Collections.unmodifiableCollection(privateRoutes); 176 176 } … … 181 181 * @since 12156 182 182 */ 183 public void addRoute(GpxRoute route) {183 public synchronized void addRoute(GpxRoute route) { 184 184 if (privateRoutes.stream().anyMatch(r -> r == route)) { 185 185 throw new IllegalArgumentException(MessageFormat.format("The route was already added to this data: {0}", route)); … … 194 194 * @since 12156 195 195 */ 196 public void removeRoute(GpxRoute route) {196 public synchronized void removeRoute(GpxRoute route) { 197 197 if (!privateRoutes.removeIf(r -> r == route)) { 198 198 throw new IllegalArgumentException(MessageFormat.format("The route was not in this data: {0}", route)); … … 206 206 * @since 12156 207 207 */ 208 public Collection<WayPoint> getWaypoints() {208 public synchronized Collection<WayPoint> getWaypoints() { 209 209 return Collections.unmodifiableCollection(privateWaypoints); 210 210 } … … 215 215 * @since 12156 216 216 */ 217 public void addWaypoint(WayPoint waypoint) {217 public synchronized void addWaypoint(WayPoint waypoint) { 218 218 if (privateWaypoints.stream().anyMatch(w -> w == waypoint)) { 219 219 throw new IllegalArgumentException(MessageFormat.format("The route was already added to this data: {0}", waypoint)); … … 228 228 * @since 12156 229 229 */ 230 public void removeWaypoint(WayPoint waypoint) {230 public synchronized void removeWaypoint(WayPoint waypoint) { 231 231 if (!privateWaypoints.removeIf(w -> w == waypoint)) { 232 232 throw new IllegalArgumentException(MessageFormat.format("The route was not in this data: {0}", waypoint)); … … 239 239 * @return {@code true} if this GPX data has track points, {@code false} otherwise 240 240 */ 241 public boolean hasTrackPoints() {241 public synchronized boolean hasTrackPoints() { 242 242 return getTrackPoints().findAny().isPresent(); 243 243 } … … 251 251 * @since 12156 252 252 */ 253 public Stream<WayPoint> getTrackPoints() {253 public synchronized Stream<WayPoint> getTrackPoints() { 254 254 return getTracks().stream().flatMap(trk -> trk.getSegments().stream()).flatMap(trkseg -> trkseg.getWayPoints().stream()); 255 255 } … … 259 259 * @return {@code true} if this GPX data has route points, {@code false} otherwise 260 260 */ 261 public boolean hasRoutePoints() {262 return getRoutes().stream().anyMatch(rte -> !rte.routePoints.isEmpty());261 public synchronized boolean hasRoutePoints() { 262 return privateRoutes.stream().anyMatch(rte -> !rte.routePoints.isEmpty()); 263 263 } 264 264 … … 267 267 * @return {@code true} if this GPX data is empty, {@code false} otherwise 268 268 */ 269 public boolean isEmpty() {269 public synchronized boolean isEmpty() { 270 270 return !hasRoutePoints() && !hasTrackPoints() && waypoints.isEmpty(); 271 271 } … … 301 301 * @see #dataSources 302 302 */ 303 public Bounds recalculateBounds() {303 public synchronized Bounds recalculateBounds() { 304 304 Bounds bounds = null; 305 for (WayPoint wpt : getWaypoints()) {305 for (WayPoint wpt : privateWaypoints) { 306 306 if (bounds == null) { 307 307 bounds = new Bounds(wpt.getCoor()); … … 310 310 } 311 311 } 312 for (GpxRoute rte : getRoutes()) {312 for (GpxRoute rte : privateRoutes) { 313 313 for (WayPoint wpt : rte.routePoints) { 314 314 if (bounds == null) { … … 319 319 } 320 320 } 321 for (GpxTrack trk : getTracks()) {321 for (GpxTrack trk : privateTracks) { 322 322 Bounds trkBounds = trk.getBounds(); 323 323 if (trkBounds != null) { … … 336 336 * @return the length in meters 337 337 */ 338 public double length() {339 return getTracks().stream().mapToDouble(GpxTrack::length).sum();338 public synchronized double length() { 339 return privateTracks.stream().mapToDouble(GpxTrack::length).sum(); 340 340 } 341 341 … … 362 362 * @return minimum and maximum dates in array of 2 elements 363 363 */ 364 public Date[] getMinMaxTimeForAllTracks() {364 public synchronized Date[] getMinMaxTimeForAllTracks() { 365 365 double now = System.currentTimeMillis() / 1000.0; 366 366 final DoubleSummaryStatistics statistics = tracks.stream() … … 384 384 * end of a segment, or may be null if nothing close enough 385 385 */ 386 public WayPoint nearestPointOnTrack(EastNorth p, double tolerance) {386 public synchronized WayPoint nearestPointOnTrack(EastNorth p, double tolerance) { 387 387 /* 388 388 * assume the coordinates of P are xp,yp, and those of a section of track between two … … 414 414 double py = p.north(); 415 415 double rx = 0.0, ry = 0.0, sx, sy, x, y; 416 for (GpxTrack track : getTracks()) {416 for (GpxTrack track : privateTracks) { 417 417 for (GpxTrackSegment seg : track.getSegments()) { 418 418 WayPoint r = null; … … 502 502 * Resets the internal caches of east/north coordinates. 503 503 */ 504 public void resetEastNorthCache() {505 getWaypoints().forEach(WayPoint::invalidateEastNorthCache);504 public synchronized void resetEastNorthCache() { 505 privateWaypoints.forEach(WayPoint::invalidateEastNorthCache); 506 506 getTrackPoints().forEach(WayPoint::invalidateEastNorthCache); 507 507 for (GpxRoute route: getRoutes()) { … … 594 594 595 595 @Override 596 public int hashCode() {596 public synchronized int hashCode() { 597 597 final int prime = 31; 598 598 int result = 1; … … 605 605 606 606 @Override 607 public boolean equals(Object obj) {607 public synchronized boolean equals(Object obj) { 608 608 if (this == obj) 609 609 return true;
Note:
See TracChangeset
for help on using the changeset viewer.