Changeset 15361 in josm
- Timestamp:
- 2019-09-19T15:26:23+02:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/Relation.java
r14905 r15361 12 12 import java.util.Set; 13 13 import java.util.stream.Collectors; 14 import java.util.stream.Stream; 14 15 15 16 import org.openstreetmap.josm.data.osm.visitor.OsmPrimitiveVisitor; … … 540 541 */ 541 542 public Set<String> getMemberRoles() { 542 Set<String> result = new HashSet<>(); 543 for (RelationMember rm : members) { 544 String role = rm.getRole(); 545 if (!role.isEmpty()) { 546 result.add(role); 547 } 548 } 549 return result; 543 return Stream.of(members).map(RelationMember::getRole).filter(role -> !role.isEmpty()).collect(Collectors.toSet()); 550 544 } 551 545 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationSorter.java
r14654 r15361 5 5 import java.util.Arrays; 6 6 import java.util.Collection; 7 import java.util.Comparator; 7 8 import java.util.HashMap; 8 9 import java.util.LinkedHashMap; … … 11 12 import java.util.Map; 12 13 import java.util.Map.Entry; 14 import java.util.stream.Collectors; 13 15 14 16 import org.openstreetmap.josm.data.osm.DefaultNameFormatter; … … 26 28 27 29 private interface AdditionalSorter { 28 boolean acceptsMember( RelationMember m);30 boolean acceptsMember(List<RelationMember> relationMembers, RelationMember m); 29 31 30 32 List<RelationMember> sortMembers(List<RelationMember> list); … … 35 37 new AssociatedStreetRoleStreetSorter(), 36 38 new AssociatedStreetRoleAddressHouseSorter(), 37 new PublicTransportRoleStopPlatformSorter() 39 new PublicTransportRoleStopPlatformSorter(), 40 new FromViaToSorter() 38 41 ); 39 42 … … 45 48 46 49 @Override 47 public boolean acceptsMember( RelationMember m) {50 public boolean acceptsMember(List<RelationMember> relationMembers, RelationMember m) { 48 51 return "street".equals(m.getRole()); 49 52 } … … 62 65 63 66 @Override 64 public boolean acceptsMember( RelationMember m) {67 public boolean acceptsMember(List<RelationMember> relationMembers, RelationMember m) { 65 68 return "address".equals(m.getRole()) || "house".equals(m.getRole()); 66 69 } … … 90 93 91 94 @Override 92 public boolean acceptsMember( RelationMember m) {95 public boolean acceptsMember(List<RelationMember> relationMembers, RelationMember m) { 93 96 return m.getRole() != null && (m.getRole().startsWith("platform") || m.getRole().startsWith("stop")); 94 97 } … … 133 136 134 137 /** 138 * Class that sorts the {@code from}, {@code via} and {@code to} members of 139 * {@code type=restriction} relations. 140 */ 141 private static class FromViaToSorter implements AdditionalSorter { 142 143 private static final List<String> ROLES = Arrays.asList("from", "via", "to"); 144 145 @Override 146 public boolean acceptsMember(List<RelationMember> relationMembers, RelationMember m) { 147 return ROLES.contains(m.getRole()) 148 && relationMembers.stream().map(RelationMember::getRole).collect(Collectors.toSet()).containsAll(ROLES); 149 } 150 151 @Override 152 public List<RelationMember> sortMembers(List<RelationMember> list) { 153 list.sort(Comparator.comparingInt(m -> ROLES.indexOf(m.getRole()))); 154 return list; 155 } 156 } 157 158 /** 135 159 * Sort a collection of relation members by the way they are linked. 136 160 * … … 150 174 boolean wasAdded = false; 151 175 for (AdditionalSorter sorter : ADDITIONAL_SORTERS) { 152 if (sorter.acceptsMember( m)) {176 if (sorter.acceptsMember(relationMembers, m)) { 153 177 wasAdded = customMap.computeIfAbsent(sorter, k -> new LinkedList<>()).add(m); 154 178 break;
Note:
See TracChangeset
for help on using the changeset viewer.