- Timestamp:
- 2020-01-19T18:57:26+01:00 (5 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionType.java
r15696 r15732 80 80 */ 81 81 public WayConnectionType(boolean invalid) { 82 this.linkPrev = false; 83 this.linkNext = false; 84 this.isLoop = false; 85 this.direction = NONE; 82 86 this.invalid = invalid; 83 87 } … … 85 89 /** construct invalid instance */ 86 90 public WayConnectionType() { 87 this.linkPrev = false; 88 this.linkNext = false; 89 this.isLoop = false; 90 this.direction = NONE; 91 invalid = true; 91 this(true); 92 92 } 93 93 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionTypeCalculator.java
r15700 r15732 8 8 import java.util.ArrayList; 9 9 import java.util.List; 10 import java.util.stream.Collectors; 10 11 11 12 import org.openstreetmap.josm.data.osm.Node; … … 14 15 import org.openstreetmap.josm.data.osm.Way; 15 16 import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType.Direction; 17 import org.openstreetmap.josm.tools.StreamUtils; 16 18 import org.openstreetmap.josm.tools.bugreport.BugReport; 17 19 … … 43 45 public List<WayConnectionType> updateLinks(Relation r, List<RelationMember> members) { 44 46 this.members = members; 45 final List<WayConnectionType> con = new ArrayList<>(); 46 47 for (int i = 0; i < members.size(); ++i) { 48 con.add(null); 49 } 47 final List<WayConnectionType> con = members.stream() 48 .map(ignore -> (WayConnectionType) null) 49 .collect(Collectors.toList()); 50 50 51 51 firstGroupIdx = 0; … … 65 65 } 66 66 } 67 makeLoopIfNeeded(con, members.size()-1); 67 if (!isSuperRoute(r)) { 68 makeLoopIfNeeded(con, members.size() - 1); 69 } 68 70 69 71 return con; … … 72 74 private WayConnectionType updateLinksFor(Relation r, List<WayConnectionType> con, WayConnectionType lastWct, int i) { 73 75 final RelationMember m = members.get(i); 74 if (isNoHandleableWay(m)) { 76 if (isSuperRoute(r)) { 77 final WayConnectionType wct; 78 if (!members.get(i).isRelation()) { 79 return new WayConnectionType(true); 80 } else if (i == 0) { 81 return new WayConnectionType(false); 82 } else { 83 final List<RelationMember> previousMembers = members.get(i - 1).getRelation().getMembers(); 84 final Way previousLastWay = StreamUtils.reversedStream(previousMembers) 85 .filter(x -> x.isWay() && !x.hasRole()) 86 .map(RelationMember::getWay) 87 .findFirst().orElse(null); 88 final Way currentFirstWay = m.getRelation().getMembers().stream() 89 .filter(x -> x.isWay() && !x.hasRole()) 90 .map(RelationMember::getWay) 91 .findFirst().orElse(null); 92 final boolean isConnected = isConnected(previousLastWay, currentFirstWay); 93 wct = new WayConnectionType(false); 94 lastWct.linkNext = wct.linkPrev = isConnected; 95 } 96 con.set(i, wct); 97 return wct; 98 } else if (isNoHandleableWay(m)) { 75 99 if (i > 0) { 76 100 makeLoopIfNeeded(con, i-1); … … 139 163 con.set(i, wct); 140 164 return wct; 165 } 166 167 private boolean isSuperRoute(Relation r) { 168 return r != null && r.hasTag("type", "superroute"); 141 169 } 142 170 … … 372 400 members = null; 373 401 } 402 403 private boolean isConnected(Way way1, Way way2) { 404 return way1 != null && way2 != null && way1.isUsable() && way2.isUsable() 405 && (way1.isFirstLastNode(way2.firstNode()) || way1.isFirstLastNode(way2.lastNode())); 406 } 374 407 } -
trunk/src/org/openstreetmap/josm/tools/StreamUtils.java
r11921 r15732 2 2 package org.openstreetmap.josm.tools; 3 3 4 import java.util.List; 5 import java.util.Objects; 4 6 import java.util.StringJoiner; 5 7 import java.util.stream.Collector; 8 import java.util.stream.IntStream; 6 9 import java.util.stream.Stream; 7 10 import java.util.stream.StreamSupport; … … 32 35 33 36 /** 37 * Creqates a stream iterating the list in reversed order 38 * @param list the list to iterate over 39 * @param <T> the type of elements in the list 40 * @return a stream iterating the list in reversed order 41 * @since 15732 42 */ 43 public static <T> Stream<T> reversedStream(List<T> list) { 44 Objects.requireNonNull(list, "list"); 45 final int size = list.size(); 46 return IntStream.range(0, size).mapToObj(i -> list.get(size - i - 1)); 47 } 48 49 /** 34 50 * Creates a new Collector that collects the items and returns them as HTML unordered list. 35 51 * @return The collector. -
trunk/test/unit/org/openstreetmap/josm/tools/StreamUtilsTest.java
r11921 r15732 5 5 import org.junit.Test; 6 6 import org.openstreetmap.josm.testutils.JOSMTestRules; 7 8 import static org.junit.Assert.assertEquals; 9 10 import java.util.Arrays; 11 import java.util.stream.Collectors; 7 12 8 13 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 29 34 UtilityClassTestUtil.assertUtilityClassWellDefined(StreamUtils.class); 30 35 } 36 37 /** 38 * Tests {@link StreamUtils#reversedStream(java.util.List)} 39 */ 40 @Test 41 public void testReverseStream() { 42 assertEquals("baz/bar/foo", 43 StreamUtils.reversedStream(Arrays.asList("foo", "bar", "baz")).collect(Collectors.joining("/"))); 44 } 31 45 }
Note:
See TracChangeset
for help on using the changeset viewer.