Ignore:
Timestamp:
2007-10-26T10:44:20+02:00 (19 years ago)
Author:
gebner
Message:

Add a generic pair class.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java

    r426 r429  
    3838import org.openstreetmap.josm.data.osm.Way;
    3939import org.openstreetmap.josm.data.osm.Node;
    40 import org.openstreetmap.josm.data.osm.NodePair;
     40import org.openstreetmap.josm.tools.Pair;
    4141import org.openstreetmap.josm.tools.GBC;
    4242
     
    5353        }
    5454
    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 
    7555        public void actionPerformed(ActionEvent event) {
    7656                Collection<OsmPrimitive> selection = Main.ds.getSelected();
     
    9676                // Step 1, iterate over all relations and figure out which of our
    9777                // selected ways are members of a relation.
    98                 HashMap<RelationRolePair, HashSet<Way>> backlinks =
    99                         new HashMap<RelationRolePair, HashSet<Way>>();
     78                HashMap<Pair<Relation,String>, HashSet<Way>> backlinks =
     79                        new HashMap<Pair<Relation,String>, HashSet<Way>>();
    10080                HashSet<Relation> relationsUsingWays = new HashSet<Relation>();
    10181                for (Relation r : Main.ds.relations) {
     
    10585                                        for(Way w : selectedWays) {
    10686                                                if (rm.member == w) {
    107                                                         RelationRolePair pair = new RelationRolePair(r, rm.role);
     87                                                        Pair<Relation,String> pair = new Pair<Relation,String>(r, rm.role);
    10888                                                        HashSet<Way> waylinks = new HashSet<Way>();
    10989                                                        if (backlinks.containsKey(pair)) {
     
    238218                //  4. Profit!
    239219
    240                 HashSet<NodePair> chunkSet = new HashSet<NodePair>();
     220                HashSet<Pair<Node,Node>> chunkSet = new HashSet<Pair<Node,Node>>();
    241221                for (Way w : ways) {
    242222                        if (w.nodes.size() == 0) continue;
     
    248228                                }
    249229
    250                                 NodePair np = new NodePair(lastN, n);
     230                                Pair<Node,Node> np = new Pair<Node,Node>(lastN, n);
    251231                                if (ignoreDirection) {
    252                                         np.sort();
     232                                        Pair.sort(np);
    253233                                }
    254234                                chunkSet.add(np);
     
    257237                        }
    258238                }
    259                 LinkedList<NodePair> chunks = new LinkedList<NodePair>(chunkSet);
     239                LinkedList<Pair<Node,Node>> chunks = new LinkedList<Pair<Node,Node>>(chunkSet);
    260240
    261241                if (chunks.isEmpty()) {
     
    263243                }
    264244
    265                 List<Node> nodeList = chunks.poll().toArrayList();
     245                List<Node> nodeList = Pair.toArrayList(chunks.poll());
    266246                while (!chunks.isEmpty()) {
    267                         ListIterator<NodePair> it = chunks.listIterator();
     247                        ListIterator<Pair<Node,Node>> it = chunks.listIterator();
    268248                        boolean foundChunk = false;
    269249                        while (it.hasNext()) {
    270                                 NodePair curChunk = it.next();
     250                                Pair<Node,Node> curChunk = it.next();
    271251                                if (curChunk.a == nodeList.get(nodeList.size() - 1)) { // append
    272252                                        nodeList.add(curChunk.b);
Note: See TracChangeset for help on using the changeset viewer.