Changeset 15496 in josm for trunk/src/org/openstreetmap/josm/data/gpx/ImmutableGpxTrack.java
- Timestamp:
- 2019-11-02T15:11:34+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/gpx/ImmutableGpxTrack.java
r13210 r15496 2 2 package org.openstreetmap.josm.data.gpx; 3 3 4 import java.util.ArrayList;5 4 import java.util.Collection; 6 import java.util.Collections;7 import java.util.HashMap;8 5 import java.util.List; 9 6 import java.util.Map; 10 7 11 import org.openstreetmap.josm.data.Bounds;12 13 8 /** 14 * ImmutableGPX track.9 * GPX track, NOT immutable 15 10 * @since 2907 11 * @deprecated Use {@link GpxTrack} instead! 16 12 */ 17 public class ImmutableGpxTrack extends WithAttributes implements GpxTrack { 18 19 private final List<GpxTrackSegment> segments; 20 private final double length; 21 private final Bounds bounds; 13 @Deprecated 14 public class ImmutableGpxTrack extends GpxTrack { 22 15 23 16 /** … … 27 20 */ 28 21 public ImmutableGpxTrack(Collection<Collection<WayPoint>> trackSegs, Map<String, Object> attributes) { 29 List<GpxTrackSegment> newSegments = new ArrayList<>(); 30 for (Collection<WayPoint> trackSeg: trackSegs) { 31 if (trackSeg != null && !trackSeg.isEmpty()) { 32 newSegments.add(new ImmutableGpxTrackSegment(trackSeg)); 33 } 34 } 35 this.attr = Collections.unmodifiableMap(new HashMap<>(attributes)); 36 this.segments = Collections.unmodifiableList(newSegments); 37 this.length = calculateLength(); 38 this.bounds = calculateBounds(); 22 super(trackSegs, attributes); 39 23 } 40 24 … … 48 32 * @since 13210 49 33 */ 50 public ImmutableGpxTrack(List<GpxTrackSegment> segments, Map<String, Object> attributes) { 51 this.attr = Collections.unmodifiableMap(new HashMap<>(attributes)); 52 this.segments = Collections.unmodifiableList(segments); 53 this.length = calculateLength(); 54 this.bounds = calculateBounds(); 55 } 56 57 private double calculateLength() { 58 double result = 0.0; // in meters 59 60 for (GpxTrackSegment trkseg : segments) { 61 result += trkseg.length(); 62 } 63 return result; 64 } 65 66 private Bounds calculateBounds() { 67 Bounds result = null; 68 for (GpxTrackSegment segment: segments) { 69 Bounds segBounds = segment.getBounds(); 70 if (segBounds != null) { 71 if (result == null) { 72 result = new Bounds(segBounds); 73 } else { 74 result.extend(segBounds); 75 } 76 } 77 } 78 return result; 79 } 80 81 @Override 82 public Map<String, Object> getAttributes() { 83 return attr; 84 } 85 86 @Override 87 public Bounds getBounds() { 88 return bounds == null ? null : new Bounds(bounds); 89 } 90 91 @Override 92 public double length() { 93 return length; 94 } 95 96 @Override 97 public Collection<GpxTrackSegment> getSegments() { 98 return segments; 99 } 100 101 @Override 102 public int hashCode() { 103 return 31 * super.hashCode() + ((segments == null) ? 0 : segments.hashCode()); 104 } 105 106 @Override 107 public boolean equals(Object obj) { 108 if (this == obj) 109 return true; 110 if (!super.equals(obj)) 111 return false; 112 if (getClass() != obj.getClass()) 113 return false; 114 ImmutableGpxTrack other = (ImmutableGpxTrack) obj; 115 if (segments == null) { 116 if (other.segments != null) 117 return false; 118 } else if (!segments.equals(other.segments)) 119 return false; 120 return true; 34 public ImmutableGpxTrack(List<IGpxTrackSegment> segments, Map<String, Object> attributes) { 35 super(segments, attributes); 121 36 } 122 37 }
Note:
See TracChangeset
for help on using the changeset viewer.
