Changeset 425 in josm
- Timestamp:
- 2007-10-26T09:14:14+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java
r407 r425 53 53 } 54 54 55 private static class RelationRolePair { 56 public Relation rel; 57 public String role; 58 59 public RelationRolePair(Relation rel, String role) { 60 this.rel = rel; 61 this.role = role; 62 } 63 64 @Override public boolean equals(Object o) { 65 return o instanceof RelationRolePair 66 && rel == ((RelationRolePair) o).rel 67 && role.equals(((RelationRolePair) o).role); 68 } 69 70 @Override public int hashCode() { 71 return rel.hashCode() ^ role.hashCode(); 72 } 73 } 74 55 75 public void actionPerformed(ActionEvent event) { 56 76 Collection<OsmPrimitive> selection = Main.ds.getSelected(); … … 74 94 // should be kept. 75 95 76 // Step 1, iterate over all relations and create counters indicating77 // how many of the selected ways are part of relation X in role Y78 // (hashMap backlinks contains keys formed like X@Y)79 HashMap<String, Integer> backlinks = new HashMap<String, Integer>();96 // Step 1, iterate over all relations and figure out which of our 97 // selected ways are members of a relation. 98 HashMap<RelationRolePair, HashSet<Way>> backlinks = 99 new HashMap<RelationRolePair, HashSet<Way>>(); 80 100 HashSet<Relation> relationsUsingWays = new HashSet<Relation>(); 81 101 for (Relation r : Main.ds.relations) { … … 85 105 for(Way w : selectedWays) { 86 106 if (rm.member == w) { 87 String hash = Long.toString(r.id) + "@" + rm.role;88 System.out.println(hash);89 if (backlinks.containsKey( hash)) {90 backlinks.put(hash, new Integer(backlinks.get(hash)+1));107 RelationRolePair pair = new RelationRolePair(r, rm.role); 108 HashSet<Way> waylinks = new HashSet<Way>(); 109 if (backlinks.containsKey(pair)) { 110 waylinks = backlinks.get(pair); 91 111 } else { 92 backlinks.put(hash, 1); 112 waylinks = new HashSet<Way>(); 113 backlinks.put(pair, waylinks); 93 114 } 115 waylinks.add(w); 116 94 117 // this is just a cache for later use 95 118 relationsUsingWays.add(r); … … 102 125 // Step 2, all values of the backlinks HashMap must now equal the size 103 126 // of the selection. 104 for ( Integer i: backlinks.values()) {105 if ( i.intValue() != selectedWays.size()) {127 for (HashSet<Way> waylinks : backlinks.values()) { 128 if (!selectedWays.equals(waylinks)) { 106 129 JOptionPane.showMessageDialog(Main.parent, tr("The selected ways cannot be combined as they have differing relation memberships.")); 107 return; 130 return; 108 131 } 109 132 }
Note:
See TracChangeset
for help on using the changeset viewer.