Changeset 14654 in josm for trunk/src/org
- Timestamp:
- 2019-01-06T20:22:48+01:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java
r14542 r14654 9 9 import java.io.Serializable; 10 10 import java.util.ArrayList; 11 import java.util.Arrays;12 11 import java.util.Collection; 13 12 import java.util.Collections; … … 139 138 */ 140 139 public static void runOn(DataSet ds) { 141 Collection<OsmPrimitive> sel = ds.getSelected(); 142 List<Node> nodes = OsmPrimitive.getFilteredList(sel, Node.class); 143 List<Way> ways = OsmPrimitive.getFilteredList(sel, Way.class); 140 List<Node> nodes = new ArrayList<>(ds.getSelectedNodes()); 141 Collection<Way> ways = ds.getSelectedWays(); 144 142 145 143 Way existingWay = null; … … 148 146 // then use the way's nodes 149 147 if (nodes.isEmpty() && (ways.size() == 1)) { 150 existingWay = ways. get(0);148 existingWay = ways.iterator().next(); 151 149 for (Node n : existingWay.getNodes()) { 152 150 if (!nodes.contains(n)) { … … 203 201 204 202 // Order nodes by angle 205 PolarNode[] angles = new PolarNode[nodes.size()]; 206 for (int i = 0; i < nodes.size(); i++) { 207 angles[i] = new PolarNode(center, nodes.get(i)); 208 } 209 Arrays.sort(angles, new PolarNodeComparator()); 203 final PolarNode[] angles = nodes.stream() 204 .map(n -> new PolarNode(center, n)) 205 .sorted() 206 .toArray(PolarNode[]::new); 210 207 int[] count = distributeNodes(angles, 211 208 numberOfNodesInCircle >= nodes.size() ? (numberOfNodesInCircle - nodes.size()) : 0); -
trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java
r14302 r14654 190 190 final Set<Relation> relatedRelations = new HashSet<>(); 191 191 for (final Way w : selectedWays) { 192 relatedRelations.addAll(Utils.filteredCollection(w.getReferrers(), Relation.class));192 w.referrers(Relation.class).forEach(relatedRelations::add); 193 193 } 194 194 return relatedRelations.size() == 1 ? relatedRelations.iterator().next() : null; -
trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java
r14397 r14654 17 17 import java.util.Optional; 18 18 import java.util.Set; 19 import java.util.stream.Collectors; 19 20 20 21 import javax.swing.JOptionPane; … … 75 76 if (!isEnabled()) 76 77 return; 77 Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getAllSelected();78 List<Node> selectedNodes = OsmPrimitive.getFilteredList(selection, Node.class);79 selectedNodes.removeIf(n -> n.isDeleted() || n.isIncomplete());78 final List<Node> selectedNodes = getLayerManager().getEditDataSet().getSelectedNodes().stream() 79 .filter(n -> !n.isDeleted() && !n.isIncomplete()) 80 .collect(Collectors.toList()); 80 81 81 82 if (selectedNodes.size() == 1) { … … 203 204 Set<Way> waysToDelete = new HashSet<>(); 204 205 205 for (Way w: OsmPrimitive.getFilteredList(OsmPrimitive.getReferrer(nodesToDelete), Way.class)) {206 for (Way w: (Iterable<Way>) nodesToDelete.stream().flatMap(p -> p.referrers(Way.class))::iterator) { 206 207 List<Node> newNodes = new ArrayList<>(w.getNodesCount()); 207 208 for (Node n: w.getNodes()) { -
trunk/src/org/openstreetmap/josm/actions/SelectNonBranchingWaySequences.java
r12048 r14654 89 89 Way foundWay = null; 90 90 91 for (Way way : OsmPrimitive.getFilteredList(node.getReferrers(), 92 Way.class)) { 91 for (Way way : node.getParentWays()) { 93 92 if (way.getNodesCount() < 2 || !way.isFirstLastNode(node) 94 93 || !way.isSelectable() -
trunk/src/org/openstreetmap/josm/actions/SimplifyWayAction.java
r14397 r14654 16 16 import java.util.List; 17 17 import java.util.Set; 18 import java.util.stream.Collectors; 18 19 19 20 import javax.swing.JOptionPane; … … 98 99 ds.beginUpdate(); 99 100 try { 100 List<Way> ways = OsmPrimitive.getFilteredList(ds.getSelected(), Way.class); 101 ways.removeIf(OsmPrimitive::isIncomplete); 101 List<Way> ways = ds.getSelectedWays().stream() 102 .filter(p -> !p.isIncomplete()) 103 .collect(Collectors.toList()); 102 104 if (ways.isEmpty()) { 103 105 alertSelectAtLeastOneWay(); -
trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java
r14542 r14654 32 32 import org.openstreetmap.josm.data.osm.OsmUtils; 33 33 import org.openstreetmap.josm.data.osm.PrimitiveId; 34 import org.openstreetmap.josm.data.osm.Relation;35 34 import org.openstreetmap.josm.data.osm.Way; 36 35 import org.openstreetmap.josm.data.osm.WaySegment; … … 83 82 } 84 83 85 Collection<OsmPrimitive> selection = ds.getSelected(); 86 87 List<Node> selectedNodes = OsmPrimitive.getFilteredList(selection, Node.class); 88 List<Way> selectedWays = OsmPrimitive.getFilteredList(selection, Way.class); 84 List<Node> selectedNodes = new ArrayList<>(ds.getSelectedNodes()); 85 List<Way> selectedWays = new ArrayList<>(ds.getSelectedWays()); 89 86 List<Way> applicableWays = getApplicableWays(selectedWays, selectedNodes); 90 87 … … 139 136 final List<List<Node>> wayChunks = SplitWayCommand.buildSplitChunks(selectedWay, selectedNodes); 140 137 if (wayChunks != null) { 141 List<Relation> selectedRelations = OsmPrimitive.getFilteredList(selection, Relation.class); 142 final List<OsmPrimitive> sel = new ArrayList<>(selectedWays.size() + selectedRelations.size()); 138 final List<OsmPrimitive> sel = new ArrayList<>(ds.getSelectedRelations()); 143 139 sel.addAll(selectedWays); 144 sel.addAll(selectedRelations);145 140 146 141 final List<Way> newWays = SplitWayCommand.createNewWaysFromChunks(selectedWay, wayChunks); -
trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java
r14653 r14654 390 390 } 391 391 // modify all relations containing the node 392 for (Relation r : OsmPrimitive.get FilteredList(originalNode.getReferrers(), Relation.class)) {392 for (Relation r : OsmPrimitive.getParentRelations(Collections.singleton(originalNode))) { 393 393 if (r.isDeleted()) { 394 394 continue; -
trunk/src/org/openstreetmap/josm/actions/UnJoinNodeWayAction.java
r14397 r14654 17 17 import org.openstreetmap.josm.command.RemoveNodesCommand; 18 18 import org.openstreetmap.josm.data.UndoRedoHandler; 19 import org.openstreetmap.josm.data.osm.DataSet; 19 20 import org.openstreetmap.josm.data.osm.Node; 20 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 46 47 public void actionPerformed(ActionEvent e) { 47 48 48 Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected(); 49 50 List<Node> selectedNodes = OsmPrimitive.getFilteredList(selection, Node.class); 51 List<Way> selectedWays = OsmPrimitive.getFilteredList(selection, Way.class); 49 final DataSet dataSet = getLayerManager().getEditDataSet(); 50 List<Node> selectedNodes = new ArrayList<>(dataSet.getSelectedNodes()); 51 List<Way> selectedWays = new ArrayList<>(dataSet.getSelectedWays()); 52 52 53 53 selectedNodes = cleanSelectedNodes(selectedWays, selectedNodes); -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r14510 r14654 1024 1024 public static Way getWayForNode(Node n) { 1025 1025 Way way = null; 1026 for (Way w : Utils.filteredCollection(n.getReferrers(), Way.class)) {1026 for (Way w : (Iterable<Way>) n.referrers(Way.class)::iterator) { 1027 1027 if (!w.isUsable() || w.getNodesCount() < 1) { 1028 1028 continue; 1029 1029 } 1030 Node firstNode = w. getNode(0);1031 Node lastNode = w. getNode(w.getNodesCount() - 1);1030 Node firstNode = w.firstNode(); 1031 Node lastNode = w.lastNode(); 1032 1032 if ((firstNode == n || lastNode == n) && (firstNode != lastNode)) { 1033 1033 if (way != null) -
trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java
r14153 r14654 18 18 import java.util.LinkedList; 19 19 import java.util.List; 20 import java.util.stream.Collectors; 20 21 21 22 import javax.swing.JOptionPane; … … 432 433 virtualCmds.add(new AddCommand(ds, virtualNode)); 433 434 434 // Looking for candidateSegment copies in ways that are 435 // referenced 436 // by candidateSegment nodes 437 List<Way> firstNodeWays = OsmPrimitive.getFilteredList( 438 candidateSegment.getFirstNode().getReferrers(), 439 Way.class); 440 List<Way> secondNodeWays = OsmPrimitive.getFilteredList( 441 candidateSegment.getFirstNode().getReferrers(), 442 Way.class); 435 // Looking for candidateSegment copies in ways that are referenced by candidateSegment nodes 436 List<Way> firstNodeWays = candidateSegment.getFirstNode().referrers(Way.class).collect(Collectors.toList()); 437 List<Way> secondNodeWays = candidateSegment.getFirstNode().referrers(Way.class).collect(Collectors.toList()); 443 438 444 439 Collection<WaySegment> virtualSegments = new LinkedList<>(); … … 484 479 485 480 //check to see if node is in use by more than one object 486 List<OsmPrimitive> referrers = candidateNode.getReferrers();487 List<Way> ways = OsmPrimitive.getFilteredList(referrers, Way.class);488 if (referrers .size() != 1 || ways.size()!= 1) {481 long referrersCount = candidateNode.referrers(OsmPrimitive.class).count(); 482 long referrerWayCount = candidateNode.referrers(Way.class).count(); 483 if (referrersCount != 1 || referrerWayCount != 1) { 489 484 // detach node from way 490 485 final Way newWay = new Way(targetWay); -
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r14397 r14654 59 59 import org.openstreetmap.josm.tools.PlatformManager; 60 60 import org.openstreetmap.josm.tools.Shortcut; 61 import org.openstreetmap.josm.tools.Utils;62 61 63 62 /** … … 884 883 private boolean movesHiddenWay() { 885 884 DataSet ds = getLayerManager().getEditDataSet(); 886 final Collection< OsmPrimitive> elementsToTest = new HashSet<>(ds.getSelected());885 final Collection<Node> elementsToTest = new HashSet<>(ds.getSelectedNodes()); 887 886 for (Way osm : ds.getSelectedWays()) { 888 887 elementsToTest.addAll(osm.getNodes()); 889 888 } 890 for (OsmPrimitive node : Utils.filteredCollection(elementsToTest, Node.class)) { 891 for (Way ref : Utils.filteredCollection(node.getReferrers(), Way.class)) { 892 if (ref.isDisabledAndHidden()) { 893 return true; 894 } 895 } 896 } 897 return false; 889 return elementsToTest.stream() 890 .flatMap(n -> n.referrers(Way.class)) 891 .anyMatch(Way::isDisabledAndHidden); 898 892 } 899 893 -
trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
r13173 r14654 19 19 import java.util.Objects; 20 20 import java.util.Set; 21 import java.util.stream.Collectors; 21 22 22 23 import javax.swing.Icon; … … 361 362 protected static Collection<Node> computeNodesToDelete(Collection<OsmPrimitive> primitivesToDelete) { 362 363 Collection<Node> nodesToDelete = new HashSet<>(); 363 for (Way way : OsmPrimitive.getFilteredList(primitivesToDelete, Way.class)) {364 for (Way way : Utils.filteredCollection(primitivesToDelete, Way.class)) { 364 365 for (Node n : way.getNodes()) { 365 366 if (n.isTagged()) { … … 435 436 return null; 436 437 437 Collection<Way> waysToBeChanged = new HashSet<>(OsmPrimitive.getFilteredSet(OsmPrimitive.getReferrer(primitivesToDelete), Way.class)); 438 Collection<Way> waysToBeChanged = primitivesToDelete.stream() 439 .flatMap(p -> p.referrers(Way.class)) 440 .collect(Collectors.toSet()); 438 441 439 442 Collection<Command> cmds = new LinkedList<>(); 440 443 for (Way w : waysToBeChanged) { 441 444 Way wnew = new Way(w); 442 wnew.removeNodes( OsmPrimitive.getFilteredSet(primitivesToDelete, Node.class));445 wnew.removeNodes(new HashSet<>(Utils.filteredCollection(primitivesToDelete, Node.class))); 443 446 if (wnew.getNodesCount() < 2) { 444 447 primitivesToDelete.add(w); … … 460 463 // remove the objects from their parent relations 461 464 // 462 for (Relation cur : OsmPrimitive.getFilteredSet(OsmPrimitive.getReferrer(primitivesToDelete), Relation.class)) { 465 final Set<Relation> relationsToBeChanged = primitivesToDelete.stream() 466 .flatMap(p -> p.referrers(Relation.class)) 467 .collect(Collectors.toSet()); 468 for (Relation cur : relationsToBeChanged) { 463 469 Relation rel = new Relation(cur); 464 470 rel.removeMembersFor(primitivesToDelete); -
trunk/src/org/openstreetmap/josm/command/SplitWayCommand.java
r14143 r14654 8 8 import java.util.Arrays; 9 9 import java.util.Collection; 10 import java.util.Collections; 10 11 import java.util.HashSet; 11 12 import java.util.Iterator; … … 297 298 // now copy all relations to new way also 298 299 299 for (Relation r : OsmPrimitive.get FilteredList(way.getReferrers(), Relation.class)) {300 for (Relation r : OsmPrimitive.getParentRelations(Collections.singleton(way))) { 300 301 if (!r.isUsable()) { 301 302 continue; -
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r14120 r14654 9 9 import java.util.TreeSet; 10 10 import java.util.function.Predicate; 11 import java.util.stream.Collectors; 11 12 12 13 import org.openstreetmap.josm.data.coor.EastNorth; … … 17 18 import org.openstreetmap.josm.data.projection.ProjectionRegistry; 18 19 import org.openstreetmap.josm.tools.CheckParameterUtil; 19 import org.openstreetmap.josm.tools.Utils;20 20 21 21 /** … … 370 370 if (hops > 0 && visited != null) { 371 371 visited.add(this); 372 for (final Way w : Utils.filteredCollection(this.getReferrers(), Way.class)) {372 for (final Way w : getParentWays()) { 373 373 for (final Node n : w.getNodes()) { 374 374 final boolean containsN = visited.contains(n); … … 401 401 */ 402 402 public List<Way> getParentWays() { 403 return getFilteredList(getReferrers(), Way.class);403 return referrers(Way.class).collect(Collectors.toList()); 404 404 } 405 405 } -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r14003 r14654 6 6 import java.text.MessageFormat; 7 7 import java.util.ArrayList; 8 import java.util.Arrays; 8 9 import java.util.Collection; 9 10 import java.util.Collections; 10 11 import java.util.Date; 11 import java.util.HashSet;12 12 import java.util.LinkedHashSet; 13 import java.util.LinkedList;14 13 import java.util.List; 15 14 import java.util.Locale; … … 18 17 import java.util.Set; 19 18 import java.util.function.Consumer; 19 import java.util.stream.Collectors; 20 import java.util.stream.Stream; 20 21 21 22 import org.openstreetmap.josm.data.osm.search.SearchCompiler; … … 91 92 * @param type the type to filter for 92 93 * @return the sub-list of OSM primitives of type <code>type</code> 93 */ 94 * @deprecated Use {@link Stream} or {@link Utils#filteredCollection(Collection, Class)} instead. 95 */ 96 @Deprecated 94 97 public static <T extends OsmPrimitive> List<T> getFilteredList(Collection<OsmPrimitive> list, Class<T> type) { 95 if (list == null) return Collections.emptyList(); 96 List<T> ret = new LinkedList<>(); 97 for (OsmPrimitive p: list) { 98 if (type.isInstance(p)) { 99 ret.add(type.cast(p)); 100 } 101 } 102 return ret; 98 return (list != null ? list.stream() : Stream.empty()) 99 .filter(type::isInstance) 100 .map(type::cast) 101 .collect(Collectors.toList()); 103 102 } 104 103 … … 113 112 * @param type the type to filter for 114 113 * @return the sub-set of OSM primitives of type <code>type</code> 115 */ 114 * @deprecated Use {@link Stream} instead 115 */ 116 @Deprecated 116 117 public static <T extends OsmPrimitive> Set<T> getFilteredSet(Collection<OsmPrimitive> set, Class<T> type) { 117 Set<T> ret = new LinkedHashSet<>(); 118 if (set != null) { 119 for (OsmPrimitive p: set) { 120 if (type.isInstance(p)) { 121 ret.add(type.cast(p)); 122 } 123 } 124 } 125 return ret; 118 return (set != null ? set.stream() : Stream.empty()) 119 .filter(type::isInstance) 120 .map(type::cast) 121 .collect(Collectors.toCollection(LinkedHashSet::new)); 126 122 } 127 123 … … 134 130 */ 135 131 public static Set<OsmPrimitive> getReferrer(Collection<? extends OsmPrimitive> primitives) { 136 Set<OsmPrimitive> ret = new HashSet<>(); 137 if (primitives == null || primitives.isEmpty()) return ret; 138 for (OsmPrimitive p: primitives) { 139 ret.addAll(p.getReferrers()); 140 } 141 return ret; 132 return (primitives != null ? primitives.stream() : Stream.<OsmPrimitive>empty()) 133 .flatMap(p -> p.referrers(OsmPrimitive.class)) 134 .collect(Collectors.toSet()); 142 135 } 143 136 … … 816 809 } 817 810 818 @Override 819 public final List<OsmPrimitive> getReferrers(boolean allowWithoutDataset) { 811 private <T extends OsmPrimitive> Stream<T> referrers(boolean allowWithoutDataset, Class<T> filter) { 820 812 // Returns only referrers that are members of the same dataset (primitive can have some fake references, for example 821 813 // when way is cloned 822 814 823 if (dataSet == null && allowWithoutDataset) 824 return Collections.emptyList();825 815 if (dataSet == null && allowWithoutDataset) { 816 return Stream.empty(); 817 } 826 818 checkDataset(); 827 Object referrers = this.referrers; 828 List<OsmPrimitive> result = new ArrayList<>(); 829 if (referrers != null) { 830 if (referrers instanceof OsmPrimitive) { 831 OsmPrimitive ref = (OsmPrimitive) referrers; 832 if (ref.dataSet == dataSet) { 833 result.add(ref); 834 } 835 } else { 836 for (OsmPrimitive o:(OsmPrimitive[]) referrers) { 837 if (dataSet == o.dataSet) { 838 result.add(o); 839 } 840 } 841 } 842 } 843 return result; 819 final Object referrers = this.referrers; 820 if (referrers == null) { 821 return Stream.empty(); 822 } 823 final Stream<OsmPrimitive> stream = referrers instanceof OsmPrimitive 824 ? Stream.of((OsmPrimitive) referrers) 825 : Arrays.stream((OsmPrimitive[]) referrers); 826 return stream 827 .filter(p -> p.dataSet == dataSet) 828 .filter(filter::isInstance) 829 .map(filter::cast); 830 } 831 832 /** 833 * Gets all primitives in the current dataset that reference this primitive. 834 * @param filter restrict primitives to subclasses 835 * @param <T> type of primitives 836 * @return the referrers as Stream 837 * @since 14654 838 */ 839 public final <T extends OsmPrimitive> Stream<T> referrers(Class<T> filter) { 840 return referrers(false, filter); 841 } 842 843 @Override 844 public final List<OsmPrimitive> getReferrers(boolean allowWithoutDataset) { 845 return referrers(allowWithoutDataset, OsmPrimitive.class) 846 .collect(Collectors.toList()); 844 847 } 845 848 … … 1159 1162 */ 1160 1163 public static Set<Relation> getParentRelations(Collection<? extends OsmPrimitive> primitives) { 1161 Set<Relation> ret = new HashSet<>(); 1162 for (OsmPrimitive w : primitives) { 1163 ret.addAll(OsmPrimitive.getFilteredList(w.getReferrers(), Relation.class)); 1164 } 1165 return ret; 1164 return primitives.stream() 1165 .flatMap(p -> p.referrers(Relation.class)) 1166 .collect(Collectors.toSet()); 1166 1167 } 1167 1168 -
trunk/src/org/openstreetmap/josm/data/osm/RelationToChildReference.java
r12190 r14654 6 6 import java.util.Objects; 7 7 import java.util.Set; 8 import java.util.stream.Collectors; 8 9 9 10 /** … … 19 20 */ 20 21 public static Set<RelationToChildReference> getRelationToChildReferences(OsmPrimitive child) { 21 Set<Relation> parents = OsmPrimitive.getFilteredSet(child.getReferrers(), Relation.class);22 Set<Relation> parents = child.referrers(Relation.class).collect(Collectors.toSet()); 22 23 Set<RelationToChildReference> references = new HashSet<>(); 23 24 for (Relation parent: parents) { -
trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java
r14561 r14654 48 48 import org.openstreetmap.josm.tools.Logging; 49 49 import org.openstreetmap.josm.tools.UncheckedParseException; 50 import org.openstreetmap.josm.tools.Utils;51 50 import org.openstreetmap.josm.tools.date.DateUtils; 52 51 … … 1473 1472 protected Long getNumber(OsmPrimitive osm) { 1474 1473 if (osm instanceof Node) { 1475 return (long) Utils.filteredCollection(osm.getReferrers(), Way.class).size();1474 return osm.referrers(Way.class).count(); 1476 1475 } else if (osm instanceof Relation) { 1477 1476 return (long) ((Relation) osm).getMemberPrimitives(Way.class).size(); -
trunk/src/org/openstreetmap/josm/data/validation/tests/Addresses.java
r14273 r14654 76 76 77 77 protected List<Relation> getAndCheckAssociatedStreets(OsmPrimitive p) { 78 List<Relation> list = OsmPrimitive.getFilteredList(p.getReferrers(), Relation.class); 79 list.removeIf(r -> !r.hasTag("type", ASSOCIATED_STREET)); 78 final List<Relation> list = p.referrers(Relation.class) 79 .filter(r -> r.hasTag("type", ASSOCIATED_STREET)) 80 .collect(Collectors.toList()); 80 81 if (list.size() > 1) { 81 82 Severity level; … … 107 108 } 108 109 } 109 for (Way w : OsmPrimitive.getFilteredList(p.getReferrers(), Way.class)) { 110 if (w.hasKey(ADDR_INTERPOLATION) && w.hasKey(ADDR_STREET)) { 111 return; 112 } 110 if (p.referrers(Way.class).anyMatch(w -> w.hasKey(ADDR_INTERPOLATION) && w.hasKey(ADDR_STREET))) { 111 return; 113 112 } 114 113 // No street found -
trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateNode.java
r12846 r14654 8 8 9 9 import java.util.ArrayList; 10 import java.util.Collection;11 10 import java.util.Collections; 12 11 import java.util.HashMap; … … 14 13 import java.util.Iterator; 15 14 import java.util.LinkedHashSet; 16 import java.util.LinkedList;17 15 import java.util.List; 18 16 import java.util.Map; 19 17 import java.util.Map.Entry; 20 18 import java.util.Set; 19 import java.util.stream.Collectors; 21 20 22 21 import org.openstreetmap.josm.actions.MergeNodesAction; 23 22 import org.openstreetmap.josm.command.Command; 24 23 import org.openstreetmap.josm.data.coor.LatLon; 25 import org.openstreetmap.josm.data.osm.AbstractPrimitive;26 24 import org.openstreetmap.josm.data.osm.Hash; 27 25 import org.openstreetmap.josm.data.osm.Node; … … 312 310 @Override 313 311 public Command fixError(TestError testError) { 314 Collection<OsmPrimitive> sel = new LinkedList<>(testError.getPrimitives()); 315 Set<Node> nodes = new LinkedHashSet<>(OsmPrimitive.getFilteredList(sel, Node.class)); 316 317 // Filter nodes that have already been deleted (see #5764 and #5773) 318 nodes.removeIf(AbstractPrimitive::isDeleted); 312 final Set<Node> nodes = testError.getPrimitives().stream() 313 .filter(Node.class::isInstance) 314 .map(Node.class::cast) 315 // Filter nodes that have already been deleted (see #5764 and #5773) 316 .filter(n -> !n.isDeleted()) 317 .collect(Collectors.toCollection(LinkedHashSet::new)); 319 318 320 319 // Merge only if at least 2 nodes remain -
trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateRelation.java
r13809 r14654 12 12 import java.util.Objects; 13 13 import java.util.Set; 14 import java.util.stream.Collectors; 14 15 15 16 import org.openstreetmap.josm.command.ChangeCommand; … … 261 262 // Find the relation that is member of one or more relations. (If any) 262 263 Relation relationWithRelations = null; 263 List<Relation> relRef = null;264 Collection<Relation> relRef = null; 264 265 for (Relation w : relFix) { 265 List<Relation> rel = OsmPrimitive.getFilteredList(w.getReferrers(), Relation.class);266 Collection<Relation> rel = w.referrers(Relation.class).collect(Collectors.toList()); 266 267 if (!rel.isEmpty()) { 267 268 if (relationWithRelations != null) … … 318 319 return false; 319 320 320 int relationsWithRelations = 0; 321 for (Relation w : rels) { 322 List<Relation> rel = OsmPrimitive.getFilteredList(w.getReferrers(), Relation.class); 323 if (!rel.isEmpty()) { 324 ++relationsWithRelations; 325 } 326 } 327 return relationsWithRelations <= 1; 321 // count relations with relations 322 return rels.stream() 323 .filter(x -> x.referrers(Relation.class).anyMatch(y -> true)) 324 .limit(2) 325 .count() <= 1; 328 326 } 329 327 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateWay.java
r13809 r14654 13 13 import java.util.Objects; 14 14 import java.util.Set; 15 import java.util.stream.Collectors; 15 16 16 17 import org.openstreetmap.josm.command.ChangeCommand; … … 267 268 List<Relation> relations = null; 268 269 for (Way w : wayz) { 269 List<Relation> rel = OsmPrimitive.getFilteredList(w.getReferrers(), Relation.class);270 List<Relation> rel = w.referrers(Relation.class).collect(Collectors.toList()); 270 271 if (!rel.isEmpty()) { 271 272 if (wayWithRelations != null) … … 328 329 int waysWithRelations = 0; 329 330 for (Way w : wayz) { 330 List<Relation> rel = OsmPrimitive.getFilteredList(w.getReferrers(), Relation.class);331 List<Relation> rel = w.referrers(Relation.class).collect(Collectors.toList()); 331 332 if (!rel.isEmpty()) { 332 333 ++waysWithRelations; -
trunk/src/org/openstreetmap/josm/data/validation/tests/Highways.java
r14198 r14654 115 115 // As roundabouts are closed ways, take care of not processing the first/last node twice 116 116 for (Node n : new HashSet<>(w.getNodes())) { 117 for (Way h : Utils.filteredCollection(n.getReferrers(), Way.class)) {117 for (Way h : (Iterable<Way>) n.referrers(Way.class)::iterator) { 118 118 String value = h.get(HIGHWAY); 119 119 if (h != w && value != null) { -
trunk/src/org/openstreetmap/josm/data/validation/tests/OverlappingWays.java
r14467 r14654 69 69 70 70 private static boolean parentMultipolygonConcernsArea(OsmPrimitive p) { 71 for (Relation r : OsmPrimitive.getFilteredList(p.getReferrers(), Relation.class)) { 72 if (r.concernsArea()) { 73 return true; 74 } 75 } 76 return false; 71 return p.referrers(Relation.class) 72 .anyMatch(Relation::concernsArea); 77 73 } 78 74 -
trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesMembershipChoiceDialog.java
r14653 r14654 6 6 import java.awt.GridBagLayout; 7 7 import java.util.Collection; 8 import java.util.Objects; 8 9 9 10 import javax.swing.AbstractButton; … … 154 155 private static boolean isUsedInRelations(final Collection<Node> existingNodes) { 155 156 return existingNodes.stream().anyMatch( 156 selectedNode -> selectedNode. getReferrers().stream().anyMatch(Relation.class::isInstance));157 selectedNode -> selectedNode.referrers(Relation.class).anyMatch(Objects::nonNull)); 157 158 } 158 159 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationSorter.java
r12865 r14654 17 17 import org.openstreetmap.josm.data.osm.RelationMember; 18 18 import org.openstreetmap.josm.tools.AlphanumComparator; 19 import org.openstreetmap.josm.tools.Utils;20 19 21 20 /** … … 96 95 97 96 private static String getStopName(OsmPrimitive p) { 98 for (Relation ref : Utils.filteredCollection(p.getReferrers(), Relation.class)) { 99 if (ref.hasTag("type", "public_transport") && ref.hasTag("public_transport", "stop_area") && ref.getName() != null) { 100 return ref.getName(); 101 } 102 } 103 return p.getName(); 97 return p.referrers(Relation.class) 98 .filter(ref -> ref.hasTag("type", "public_transport") 99 && ref.hasTag("public_transport", "stop_area") 100 && ref.getName() != null) 101 .map(Relation::getName) 102 .findFirst() 103 .orElse(p.getName()); 104 104 } 105 105 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r14466 r14654 24 24 import org.openstreetmap.josm.data.osm.OsmUtils; 25 25 import org.openstreetmap.josm.data.osm.Relation; 26 import org.openstreetmap.josm.data.osm.Way; 26 27 import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor; 27 28 import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache; … … 33 34 import org.openstreetmap.josm.tools.Logging; 34 35 import org.openstreetmap.josm.tools.Pair; 35 import org.openstreetmap.josm.tools.SubclassFilteredCollection;36 36 import org.openstreetmap.josm.tools.Utils; 37 37 … … 354 354 // if right selector also matches relations and if matched primitive is a way which is part of a multipolygon, 355 355 // use the multipolygon for further analysis 356 if (!(e.osm instanceof IWay)356 if (!(e.osm instanceof Way) 357 357 || (right instanceof OptimizedGeneralSelector 358 358 && !((OptimizedGeneralSelector) right).matchesBase(OsmPrimitiveType.RELATION))) { 359 359 throw new NoSuchElementException(); 360 360 } 361 final Collection<Relation> multipolygons = Utils.filteredCollection(SubclassFilteredCollection.filter(362 e.osm.getReferrers(), p -> p.hasTag("type", "multipolygon")), Relation.class);363 final Relation multipolygon = multipolygons.iterator().next();364 if (multipolygon == null) throw new NoSuchElementException();361 final Relation multipolygon = ((Way) e.osm).referrers(Relation.class) 362 .filter(p -> p.hasTag("type", "multipolygon")) 363 .findFirst() 364 .orElseThrow(NoSuchElementException::new); 365 365 final Set<OsmPrimitive> members = multipolygon.getMemberPrimitives(); 366 366 containsFinder = new ContainsFinder(new Environment(multipolygon)) { -
trunk/src/org/openstreetmap/josm/tools/RotationAngle.java
r13623 r14654 2 2 package org.openstreetmap.josm.tools; 3 3 4 import java.util.List; 4 5 import java.util.Locale; 5 6 6 7 import org.openstreetmap.josm.data.osm.IPrimitive; 7 8 import org.openstreetmap.josm.data.osm.Node; 8 import org.openstreetmap.josm.data.osm.OsmPrimitive;9 9 import org.openstreetmap.josm.data.osm.Way; 10 10 … … 28 28 } 29 29 final Node n = (Node) p; 30 final SubclassFilteredCollection<OsmPrimitive, Way> ways = Utils.filteredCollection(n.getReferrers(), Way.class);30 final List<Way> ways = n.getParentWays(); 31 31 if (ways.isEmpty()) { 32 32 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.