| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.data.gpx;
|
|---|
| 3 |
|
|---|
| 4 | import java.awt.Color;
|
|---|
| 5 | import java.util.Collection;
|
|---|
| 6 | import java.util.Iterator;
|
|---|
| 7 | import java.util.Map;
|
|---|
| 8 | import java.util.Objects;
|
|---|
| 9 |
|
|---|
| 10 | /**
|
|---|
| 11 | * Line represents a linear collection of GPX waypoints with the ordered/unordered distinction.
|
|---|
| 12 | * @since 14451
|
|---|
| 13 | */
|
|---|
| 14 | public class Line implements Collection<WayPoint> {
|
|---|
| 15 | private final Collection<WayPoint> waypoints;
|
|---|
| 16 | private final boolean unordered;
|
|---|
| 17 | private final Color color;
|
|---|
| 18 |
|
|---|
| 19 | /**
|
|---|
| 20 | * Constructs a new {@code Line}.
|
|---|
| 21 | * @param waypoints collection of waypoints
|
|---|
| 22 | * @param attributes track/route attributes
|
|---|
| 23 | * @param color color of the track
|
|---|
| 24 | * @since 15496
|
|---|
| 25 | */
|
|---|
| 26 | public Line(Collection<WayPoint> waypoints, Map<String, Object> attributes, Color color) {
|
|---|
| 27 | this.color = color;
|
|---|
| 28 | this.waypoints = Objects.requireNonNull(waypoints);
|
|---|
| 29 | unordered = attributes.isEmpty() && waypoints.stream().allMatch(x -> x.get(GpxConstants.PT_TIME) == null);
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | /**
|
|---|
| 33 | * Constructs a new {@code Line}.
|
|---|
| 34 | * @param trackSegment track segment
|
|---|
| 35 | * @param trackAttributes track attributes
|
|---|
| 36 | * @param color color of the track
|
|---|
| 37 | * @since 15496
|
|---|
| 38 | */
|
|---|
| 39 | public Line(IGpxTrackSegment trackSegment, Map<String, Object> trackAttributes, Color color) {
|
|---|
| 40 | this(trackSegment.getWayPoints(), trackAttributes, color);
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | /**
|
|---|
| 44 | * Constructs a new {@code Line}.
|
|---|
| 45 | * @param route route
|
|---|
| 46 | */
|
|---|
| 47 | public Line(GpxRoute route) {
|
|---|
| 48 | this(route.routePoints, route.attr, null);
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | /**
|
|---|
| 52 | * Determines if waypoints are ordered.
|
|---|
| 53 | * @return {@code true} if waypoints are ordered
|
|---|
| 54 | */
|
|---|
| 55 | public boolean isUnordered() {
|
|---|
| 56 | return unordered;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | /**
|
|---|
| 60 | * Returns the track/route color
|
|---|
| 61 | * @return the color
|
|---|
| 62 | * @since 15496
|
|---|
| 63 | */
|
|---|
| 64 | public Color getColor() {
|
|---|
| 65 | return color;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | @Override
|
|---|
| 69 | public int size() {
|
|---|
| 70 | return waypoints.size();
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | @Override
|
|---|
| 74 | public boolean isEmpty() {
|
|---|
| 75 | return waypoints.isEmpty();
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | @Override
|
|---|
| 79 | public boolean contains(Object o) {
|
|---|
| 80 | return waypoints.contains(o);
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | @Override
|
|---|
| 84 | public Iterator<WayPoint> iterator() {
|
|---|
| 85 | return waypoints.iterator();
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | @Override
|
|---|
| 89 | public Object[] toArray() {
|
|---|
| 90 | return waypoints.toArray();
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | @Override
|
|---|
| 94 | public <T> T[] toArray(T[] a) {
|
|---|
| 95 | return waypoints.toArray(a);
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | @Override
|
|---|
| 99 | public boolean add(WayPoint e) {
|
|---|
| 100 | return waypoints.add(e);
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | @Override
|
|---|
| 104 | public boolean remove(Object o) {
|
|---|
| 105 | return waypoints.remove(o);
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | @Override
|
|---|
| 109 | public boolean containsAll(Collection<?> c) {
|
|---|
| 110 | return waypoints.containsAll(c);
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | @Override
|
|---|
| 114 | public boolean addAll(Collection<? extends WayPoint> c) {
|
|---|
| 115 | return waypoints.addAll(c);
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | @Override
|
|---|
| 119 | public boolean removeAll(Collection<?> c) {
|
|---|
| 120 | return waypoints.removeAll(c);
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | @Override
|
|---|
| 124 | public boolean retainAll(Collection<?> c) {
|
|---|
| 125 | return waypoints.retainAll(c);
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | @Override
|
|---|
| 129 | public void clear() {
|
|---|
| 130 | waypoints.clear();
|
|---|
| 131 | }
|
|---|
| 132 | }
|
|---|