Changeset 14681 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2019-01-12T19:30:46+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/relation/ExportRelationToGpxAction.java
r14434 r14681 16 16 import java.util.HashMap; 17 17 import java.util.Iterator; 18 import java.util.LinkedList; 18 19 import java.util.List; 19 import java.util.ListIterator;20 20 import java.util.Map; 21 21 import java.util.Set; … … 32 32 import org.openstreetmap.josm.data.osm.Relation; 33 33 import org.openstreetmap.josm.data.osm.RelationMember; 34 import org.openstreetmap.josm.data.osm.Way;35 34 import org.openstreetmap.josm.gui.MainApplication; 36 35 import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType; … … 111 110 } 112 111 113 private static final class BidiIterableList {114 private final List<RelationMember> l;115 116 private BidiIterableList(List<RelationMember> l) {117 this.l = l;118 }119 120 public Iterator<RelationMember> iterator() {121 return l.iterator();122 }123 124 public Iterator<RelationMember> reverseIterator() {125 ListIterator<RelationMember> li = l.listIterator(l.size());126 return new Iterator<RelationMember>() {127 @Override128 public boolean hasNext() {129 return li.hasPrevious();130 }131 132 @Override133 public RelationMember next() {134 return li.previous();135 }136 137 @Override138 public void remove() {139 li.remove();140 }141 };142 }143 }144 145 112 @Override 146 113 protected Layer getLayer() { … … 149 116 List<RelationMember> init = new ArrayList<>(); 150 117 relations.forEach(t -> init.add(new RelationMember("", t))); 151 BidiIterableList l = new BidiIterableList(init);152 118 153 119 Stack<Iterator<RelationMember>> stack = new Stack<>(); 154 stack.push(mode .contains(FROM_FIRST_MEMBER) ? l.iterator() : l.reverseIterator());120 stack.push(modeAwareIterator(init)); 155 121 156 122 List<Relation> relsFound = new ArrayList<>(); … … 162 128 RelationMember m = i.next(); 163 129 if (m.isRelation() && !m.getRelation().isIncomplete()) { 164 l = new BidiIterableList(m.getRelation().getMembers());165 stack.push(mode .contains(FROM_FIRST_MEMBER) ? l.iterator() : l.reverseIterator());130 final List<RelationMember> members = m.getRelation().getMembers(); 131 stack.push(modeAwareIterator(members)); 166 132 relsFound.add(m.getRelation()); 167 133 break; … … 196 162 } 197 163 if (trkAttr.isEmpty()) { 198 Relation r = Way.getParentRelations(Arrays.asList(flat.get(i).getWay())) 199 .stream().filter(relsFound::contains).findFirst().orElseGet(null); 200 if (r != null) { 201 trkAttr.put("name", r.getName() != null ? r.getName() : r.getId()); 202 trkAttr.put("desc", tr("based on osm route relation data, timestamps are synthetic")); 203 } 164 flat.get(i).getWay().referrers(Relation.class) 165 .filter(relsFound::contains) 166 .findFirst() 167 .ifPresent(r -> { 168 trkAttr.put("name", r.getName() != null ? r.getName() : r.getId()); 169 trkAttr.put("desc", tr("based on osm route relation data, timestamps are synthetic")); 170 }); 204 171 GpxData.ensureUniqueName(trkAttr, names); 205 172 } … … 225 192 } 226 193 194 private <T> Iterator<T> modeAwareIterator(List<T> list) { 195 return mode.contains(FROM_FIRST_MEMBER) 196 ? list.iterator() 197 : new LinkedList<>(list).descendingIterator(); 198 } 199 227 200 /** 228 201 *
Note:
See TracChangeset
for help on using the changeset viewer.