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