source: josm/trunk/src/org/openstreetmap/josm/data/gpx/ImmutableGpxTrack.java@ 5298

Last change on this file since 5298 was 5170, checked in by Don-vip, 12 years ago

cleanup svn:mime-type properties preventing Java sources from being viewed as such on Trac

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.gpx;
3
4import java.util.ArrayList;
5import java.util.Collection;
6import java.util.Collections;
7import java.util.HashMap;
8import java.util.List;
9import java.util.Map;
10
11import org.openstreetmap.josm.data.Bounds;
12
13public class ImmutableGpxTrack implements GpxTrack {
14
15 private final Map<String, Object> attributes;
16 private final Collection<GpxTrackSegment> segments;
17 private final double length;
18 private final Bounds bounds;
19
20 public ImmutableGpxTrack(Collection<Collection<WayPoint>> trackSegs, Map<String, Object> attributes) {
21 List<GpxTrackSegment> newSegments = new ArrayList<GpxTrackSegment>();
22 for (Collection<WayPoint> trackSeg: trackSegs) {
23 if (trackSeg != null && !trackSeg.isEmpty()) {
24 newSegments.add(new ImmutableGpxTrackSegment(trackSeg));
25 }
26 }
27 this.attributes = Collections.unmodifiableMap(new HashMap<String, Object>(attributes));
28 this.segments = Collections.unmodifiableCollection(newSegments);
29 this.length = calculateLength();
30 this.bounds = calculateBounds();
31 }
32
33 private double calculateLength(){
34 double result = 0.0; // in meters
35
36 for (GpxTrackSegment trkseg : segments) {
37 result += trkseg.length();
38 }
39 return result;
40 }
41
42 private Bounds calculateBounds() {
43 Bounds result = null;
44 for (GpxTrackSegment segment: segments) {
45 Bounds segBounds = segment.getBounds();
46 if (segBounds != null) {
47 if (result == null) {
48 result = new Bounds(segBounds);
49 } else {
50 result.extend(segBounds);
51 }
52 }
53 }
54 return result;
55 }
56
57 public Map<String, Object> getAttributes() {
58 return attributes;
59 }
60
61 public Bounds getBounds() {
62 if (bounds == null)
63 return null;
64 else
65 return new Bounds(bounds);
66 }
67
68 public double length() {
69 return length;
70 }
71
72 public Collection<GpxTrackSegment> getSegments() {
73 return segments;
74 }
75
76 public int getUpdateCount() {
77 return 0;
78 }
79}
Note: See TracBrowser for help on using the repository browser.