Ignore:
Timestamp:
2019-11-02T15:11:34+01:00 (4 years ago)
Author:
Don-vip
Message:

fix #16796 - Rework of GPX track colors / layer preferences (patch by Bjoeni)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/gpx/ImmutableGpxTrack.java

    r13210 r15496  
    22package org.openstreetmap.josm.data.gpx;
    33
    4 import java.util.ArrayList;
    54import java.util.Collection;
    6 import java.util.Collections;
    7 import java.util.HashMap;
    85import java.util.List;
    96import java.util.Map;
    107
    11 import org.openstreetmap.josm.data.Bounds;
    12 
    138/**
    14  * Immutable GPX track.
     9 * GPX track, NOT immutable
    1510 * @since 2907
     11 * @deprecated Use {@link GpxTrack} instead!
    1612 */
    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
     14public class ImmutableGpxTrack extends GpxTrack {
    2215
    2316    /**
     
    2720     */
    2821    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);
    3923    }
    4024
     
    4832     * @since 13210
    4933     */
    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);
    12136    }
    12237}
Note: See TracChangeset for help on using the changeset viewer.