Changeset 5630 in josm


Ignore:
Timestamp:
2012-12-24T15:13:33+01:00 (7 years ago)
Author:
jttt
Message:

Relation sorting and way connection refactored, added tests

Location:
trunk
Files:
10 added
3 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTable.java

    r5297 r5630  
    2727import org.openstreetmap.josm.gui.MapView;
    2828import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    29 import org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction;
     29import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType;
     30import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType.Direction;
    3031import org.openstreetmap.josm.gui.layer.Layer;
    3132import org.openstreetmap.josm.gui.layer.OsmDataLayer;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableLinkedCellRenderer.java

    r4072 r5630  
    1111import javax.swing.JTable;
    1212
    13 import org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction;
     13import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType;
     14import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType.Direction;
    1415import org.openstreetmap.josm.tools.ImageProvider;
    1516
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r5614 r5630  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.dialogs.relation;
    3 
    4 import static org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction.BACKWARD;
    5 import static org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction.FORWARD;
    6 import static org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction.NONE;
    7 import static org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction.ROUNDABOUT_LEFT;
    8 import static org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction.ROUNDABOUT_RIGHT;
    93
    104import java.util.ArrayList;
     
    126import java.util.Collection;
    137import java.util.Collections;
    14 import java.util.Comparator;
    158import java.util.EnumSet;
    16 import java.util.HashMap;
    179import java.util.HashSet;
    1810import java.util.Iterator;
    19 import java.util.LinkedList;
    2011import java.util.List;
    21 import java.util.Map;
    2212import java.util.Set;
    2313import java.util.concurrent.CopyOnWriteArrayList;
     
    3121import org.openstreetmap.josm.Main;
    3222import org.openstreetmap.josm.data.SelectionChangedListener;
    33 import org.openstreetmap.josm.data.coor.EastNorth;
    3423import org.openstreetmap.josm.data.osm.DataSet;
    35 import org.openstreetmap.josm.data.osm.Node;
    3624import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3725import org.openstreetmap.josm.data.osm.Relation;
    3826import org.openstreetmap.josm.data.osm.RelationMember;
    39 import org.openstreetmap.josm.data.osm.Way;
    4027import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
    4128import org.openstreetmap.josm.data.osm.event.DataChangedEvent;
     
    4835import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
    4936import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel;
    50 import org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction;
     37import org.openstreetmap.josm.gui.dialogs.relation.sort.RelationSorter;
     38import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType;
     39import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionTypeCalculator;
    5140import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    5241import org.openstreetmap.josm.gui.tagging.TaggingPreset;
     
    6655    private final PresetListPanel.PresetHandler presetHandler;
    6756
    68     private final int UNCONNECTED = Integer.MIN_VALUE;
    69    
    70     private static final Collection<AdditionalSorter> additionalSorters = new ArrayList<AdditionalSorter>();
    71    
    72     static {
    73         additionalSorters.add(new AssociatedStreetSorter());
    74     }
     57    private final WayConnectionTypeCalculator wayConnectionTypeCalculator = new WayConnectionTypeCalculator();
     58    private final RelationSorter relationSorter = new RelationSorter();
    7559
    7660    /**
     
    590574     */
    591575    public static boolean hasMembersReferringTo(Collection<RelationMember> members, Collection<OsmPrimitive> primitives) {
    592         if (primitives == null || primitives.isEmpty()) {
     576        if (primitives == null || primitives.isEmpty())
    593577            return false;
    594         }
    595578        HashSet<OsmPrimitive> referrers = new HashSet<OsmPrimitive>();
    596579        for (RelationMember member : members) {
     
    598581        }
    599582        for (OsmPrimitive referred : primitives) {
    600             if (referrers.contains(referred)) {
     583            if (referrers.contains(referred))
    601584                return true;
    602             }
    603585        }
    604586        return false;
     
    699681    }*/
    700682
    701     /*
    702      * Sort a collection of relation members by the way they are linked.
    703      *
    704      * @param relationMembers collection of relation members
    705      * @return sorted collection of relation members
    706      */
    707     private List<RelationMember> sortMembers(List<RelationMember> relationMembers) {
    708         ArrayList<RelationMember> newMembers = new ArrayList<RelationMember>();
    709 
    710         // Sort members with custom mechanisms (relation-dependent)
    711         List<RelationMember> defaultMembers = new LinkedList<RelationMember>();
    712         Map<AdditionalSorter, List<RelationMember>> customMap = new HashMap<AdditionalSorter, List<RelationMember>>();
    713 
    714         // Dispatch members to correct sorters
    715         for (RelationMember m : relationMembers) {
    716             for (AdditionalSorter sorter : additionalSorters) {
    717                 List<RelationMember> list = defaultMembers;
    718                 if (sorter.acceptsMember(m)) {
    719                     list = customMap.get(sorter);
    720                     if (list == null) {
    721                         customMap.put(sorter, list = new LinkedList<RelationMember>());
    722                     }
    723                 }
    724                 list.add(m);
    725             }
    726         }
    727        
    728         // Sort members and add them to result
    729         for (AdditionalSorter s : customMap.keySet()) {
    730             newMembers.addAll(s.sortMembers(customMap.get(s)));
    731         }
    732        
    733         RelationNodeMap map = new RelationNodeMap(defaultMembers);
    734         // List of groups of linked members
    735         //
    736         ArrayList<LinkedList<Integer>> allGroups = new ArrayList<LinkedList<Integer>>();
    737 
    738         // current group of members that are linked among each other
    739         // Two successive members are always linked i.e. have a common node.
    740         //
    741         LinkedList<Integer> group;
    742 
    743         Integer first;
    744         while ((first = map.pop()) != null) {
    745             group = new LinkedList<Integer>();
    746             group.add(first);
    747 
    748             allGroups.add(group);
    749 
    750             Integer next = first;
    751             while ((next = map.popAdjacent(next)) != null) {
    752                 group.addLast(next);
    753             }
    754 
    755             // The first element need not be in front of the list.
    756             // So the search goes in both directions
    757             //
    758             next = first;
    759             while ((next = map.popAdjacent(next)) != null) {
    760                 group.addFirst(next);
    761             }
    762         }
    763 
    764         for (LinkedList<Integer> tmpGroup : allGroups) {
    765             for (Integer p : tmpGroup) {
    766                 newMembers.add(defaultMembers.get(p));
    767             }
    768         }
    769        
    770         // Finally, add members that have not been sorted at all
    771         for (Integer i : map.getNotSortableMembers()) {
    772             newMembers.add(defaultMembers.get(i));
    773         }
    774        
    775         return newMembers;
    776     }
    777683
    778684    /**
     
    784690        List<RelationMember> newMembers;
    785691        if (selectedMembers.size() <= 1) {
    786             newMembers = sortMembers(members);
     692            newMembers = relationSorter.sortMembers(members);
    787693            sortedMembers = newMembers;
    788694        } else {
    789             sortedMembers = sortMembers(selectedMembers);
     695            sortedMembers = relationSorter.sortMembers(selectedMembers);
    790696            List<Integer> selectedIndices = getSelectedIndices();
    791697            newMembers = new ArrayList<RelationMember>();
     
    811717    }
    812718
    813     private Direction determineDirection(int ref_i, Direction ref_direction, int k) {
    814         return determineDirection(ref_i, ref_direction, k, false);
    815     }
    816     /**
    817      * Determines the direction of way k with respect to the way ref_i.
    818      * The way ref_i is assumed to have the direction ref_direction and
    819      * to be the predecessor of k.
    820      *
    821      * If both ways are not linked in any way, NONE is returned.
    822      *
    823      * Else the direction is given as follows:
    824      * Let the relation be a route of oneway streets, and someone travels them in the given order.
    825      * Direction is FORWARD if it is legal and BACKWARD if it is illegal to do so for the given way.
    826      *
    827      **/
    828     private Direction determineDirection(int ref_i, final Direction ref_direction, int k, boolean reversed) {
    829         if (ref_i < 0 || k < 0 || ref_i >= members.size() || k >= members.size())
    830             return NONE;
    831         if (ref_direction == NONE)
    832             return NONE;
    833 
    834         final RelationMember m_ref = members.get(ref_i);
    835         final RelationMember m = members.get(k);
    836         Way way_ref = null;
    837         Way way = null;
    838 
    839         if (m_ref.isWay()) {
    840             way_ref = m_ref.getWay();
    841         }
    842         if (m.isWay()) {
    843             way = m.getWay();
    844         }
    845 
    846         if (way_ref == null || way == null)
    847             return NONE;
    848 
    849         /** the list of nodes the way k can dock to */
    850         List<Node> refNodes= new ArrayList<Node>();
    851 
    852         switch (ref_direction) {
    853         case FORWARD:
    854             refNodes.add(way_ref.lastNode());
    855             break;
    856         case BACKWARD:
    857             refNodes.add(way_ref.firstNode());
    858             break;
    859         case ROUNDABOUT_LEFT:
    860         case ROUNDABOUT_RIGHT:
    861             refNodes = way_ref.getNodes();
    862             break;
    863         }
    864 
    865         if (refNodes == null)
    866             return NONE;
    867 
    868         for (Node n : refNodes) {
    869             if (n == null) {
    870                 continue;
    871             }
    872             if (roundaboutType(k) != NONE) {
    873                 for (Node nn : way.getNodes()) {
    874                     if (n == nn)
    875                         return roundaboutType(k);
    876                 }
    877             } else if(isOneway(m)) {
    878                 if (n == RelationNodeMap.firstOnewayNode(m) && !reversed) {
    879                     if(isBackward(m))
    880                         return BACKWARD;
    881                     else
    882                         return FORWARD;
    883                 }
    884                 if (n == RelationNodeMap.lastOnewayNode(m) && reversed) {
    885                     if(isBackward(m))
    886                         return FORWARD;
    887                     else
    888                         return BACKWARD;
    889                 }
    890             } else {
    891                 if (n == way.firstNode())
    892                     return FORWARD;
    893                 if (n == way.lastNode())
    894                     return BACKWARD;
    895             }
    896         }
    897         return NONE;
    898     }
    899 
    900     /**
    901      * determine, if the way i is a roundabout and if yes, what type of roundabout
    902      */
    903     private Direction roundaboutType(int i) {
    904         RelationMember m = members.get(i);
    905         if (m == null || !m.isWay()) return NONE;
    906         Way w = m.getWay();
    907         return roundaboutType(w);
    908     }
    909     static Direction roundaboutType(Way w) {
    910         if (w != null &&
    911                 "roundabout".equals(w.get("junction")) &&
    912                 w.getNodesCount() < 200 &&
    913                 w.getNodesCount() > 2 &&
    914                 w.getNode(0) != null &&
    915                 w.getNode(1) != null &&
    916                 w.getNode(2) != null &&
    917                 w.firstNode() == w.lastNode()) {
    918             /** do some simple determinant / cross pruduct test on the first 3 nodes
    919                 to see, if the roundabout goes clock wise or ccw */
    920             EastNorth en1 = w.getNode(0).getEastNorth();
    921             EastNorth en2 = w.getNode(1).getEastNorth();
    922             EastNorth en3 = w.getNode(2).getEastNorth();
    923             if (en1 != null && en2 != null && en3 != null) {
    924                 en1 = en1.sub(en2);
    925                 en2 = en2.sub(en3);
    926                 return en1.north() * en2.east() - en2.north() * en1.east() > 0 ? ROUNDABOUT_LEFT : ROUNDABOUT_RIGHT;
    927             }
    928         }
    929         return NONE;
    930     }
    931719
    932720    WayConnectionType getWayConnection(int i) {
    933721        if (connectionType == null) {
    934             updateLinks();
     722            connectionType = wayConnectionTypeCalculator.updateLinks(members);
    935723        }
    936724        return connectionType.get(i);
     
    967755            setSelectedMembersIdx(selectedIndices);
    968756        }
    969     }
    970 
    971     /**
    972      * refresh the cache of member WayConnectionTypes
    973      */
    974     public void updateLinks() {
    975         connectionType = null;
    976         final List<WayConnectionType> con = new ArrayList<WayConnectionType>();
    977 
    978         for (int i=0; i<members.size(); ++i) {
    979             con.add(null);
    980         }
    981 
    982         firstGroupIdx=0;
    983 
    984         lastForwardWay = UNCONNECTED;
    985         lastBackwardWay = UNCONNECTED;
    986         onewayBeginning = false;
    987         WayConnectionType lastWct = null;
    988 
    989         for (int i=0; i<members.size(); ++i) {
    990             final RelationMember m = members.get(i);
    991             if (!m.isWay() || m.getWay() == null || m.getWay().isIncomplete()) {
    992                 if(i > 0) {
    993                     makeLoopIfNeeded(con, i-1);
    994                 }
    995                 con.set(i, new WayConnectionType());
    996                 firstGroupIdx = i;
    997                 continue;
    998             }
    999 
    1000             WayConnectionType wct = new WayConnectionType(false);
    1001             wct.linkPrev = i>0 && con.get(i-1) != null && con.get(i-1).isValid();
    1002             wct.direction = NONE;
    1003 
    1004             if(isOneway(m)){
    1005                 if(lastWct != null && lastWct.isOnewayTail) {
    1006                     wct.isOnewayHead = true;
    1007                 }
    1008                 if(lastBackwardWay == UNCONNECTED && lastForwardWay == UNCONNECTED){ //Beginning of new oneway
    1009                     wct.isOnewayHead = true;
    1010                     lastForwardWay = i-1;
    1011                     lastBackwardWay = i-1;
    1012                     onewayBeginning = true;
    1013                 }
    1014             }
    1015 
    1016             if (wct.linkPrev) {
    1017                 if(lastBackwardWay != UNCONNECTED && lastForwardWay != UNCONNECTED) {
    1018                     wct = determineOnewayConnectionType(con, m, i, wct);
    1019                     if(!wct.linkPrev) {
    1020                         firstGroupIdx = i;
    1021                     }
    1022                 }
    1023 
    1024                 if(!isOneway(m)) {
    1025                     wct.direction = determineDirection(i-1, lastWct.direction, i);
    1026                     wct.linkPrev = (wct.direction != NONE);
    1027                 }
    1028             }
    1029 
    1030             if (!wct.linkPrev) {
    1031                 wct.direction = determineDirectionOfFirst(i, m);
    1032                 if(isOneway(m)){
    1033                     wct.isOnewayLoopForwardPart = true;
    1034                     lastForwardWay = i;
    1035                 }
    1036             }
    1037 
    1038             wct.linkNext = false;
    1039             if(lastWct != null) {
    1040                 lastWct.linkNext = wct.linkPrev;
    1041             }
    1042             con.set(i, wct);
    1043             lastWct = wct;
    1044 
    1045             if(!wct.linkPrev) {
    1046                 if(i > 0) {
    1047                     makeLoopIfNeeded(con, i-1);
    1048                 }
    1049                 firstGroupIdx = i;
    1050             }
    1051         }
    1052         makeLoopIfNeeded(con, members.size()-1);
    1053         connectionType = con;
    1054757    }
    1055758
     
    1064767    //    }
    1065768
    1066     private static Direction reverse(final Direction dir){
    1067         if(dir == FORWARD) return BACKWARD;
    1068         if(dir == BACKWARD) return FORWARD;
    1069         return dir;
    1070     }
    1071 
    1072     private static boolean isBackward(final RelationMember member){
    1073         return member.getRole().equals("backward");
    1074     }
    1075 
    1076     private static boolean isForward(final RelationMember member){
    1077         return member.getRole().equals("forward");
    1078     }
    1079 
    1080     public static boolean isOneway(final RelationMember member){
    1081         return isForward(member) || isBackward(member);
    1082     }
    1083 
    1084     int firstGroupIdx;
    1085     private void makeLoopIfNeeded(final List<WayConnectionType> con, final int i) {
    1086         boolean loop;
    1087         if (i == firstGroupIdx) { //is primitive loop
    1088             loop = determineDirection(i, FORWARD, i) == FORWARD;
    1089         } else {
    1090             loop = determineDirection(i, con.get(i).direction, firstGroupIdx) == con.get(firstGroupIdx).direction;
    1091         }
    1092         if (loop) {
    1093             for (int j=firstGroupIdx; j <= i; ++j) {
    1094                 con.get(j).isLoop = true;
    1095             }
    1096         }
    1097     }
    1098 
    1099     private Direction determineDirectionOfFirst(final int i, final RelationMember m) {
    1100         if (roundaboutType(i) != NONE)
    1101             return roundaboutType(i);
    1102 
    1103         if (isOneway(m)){
    1104             if(isBackward(m)) return BACKWARD;
    1105             else return FORWARD;
    1106         } else { /** guess the direction and see if it fits with the next member */
    1107             if(determineDirection(i, FORWARD, i+1) != NONE) return FORWARD;
    1108             if(determineDirection(i, BACKWARD, i+1) != NONE) return BACKWARD;
    1109         }
    1110         return NONE;
    1111     }
    1112 
    1113     int lastForwardWay, lastBackwardWay;
    1114     boolean onewayBeginning;
    1115     private WayConnectionType determineOnewayConnectionType(final List<WayConnectionType> con,
    1116             RelationMember m, int i, final WayConnectionType wct) {
    1117         Direction dirFW = determineDirection(lastForwardWay, con.get(lastForwardWay).direction, i);
    1118         Direction dirBW = NONE;
    1119         if(onewayBeginning) {
    1120             if(lastBackwardWay < 0) {
    1121                 dirBW = determineDirection(firstGroupIdx, reverse(con.get(firstGroupIdx).direction), i, true);
    1122             } else {
    1123                 dirBW = determineDirection(lastBackwardWay, con.get(lastBackwardWay).direction, i, true);
    1124             }
    1125 
    1126             if(dirBW != NONE) {
    1127                 onewayBeginning = false;
    1128             }
    1129         } else {
    1130             dirBW = determineDirection(lastBackwardWay, con.get(lastBackwardWay).direction, i, true);
    1131         }
    1132 
    1133         if(isOneway(m)) {
    1134             if(dirBW != NONE){
    1135                 wct.direction = dirBW;
    1136                 lastBackwardWay = i;
    1137                 wct.isOnewayLoopBackwardPart = true;
    1138             }
    1139             if(dirFW != NONE){
    1140                 wct.direction = dirFW;
    1141                 lastForwardWay = i;
    1142                 wct.isOnewayLoopForwardPart = true;
    1143             }
    1144             if(dirFW == NONE && dirBW == NONE) { //Not connected to previous
    1145                 //                        unconnectPreviousLink(con, i, true);
    1146                 //                        unconnectPreviousLink(con, i, false);
    1147                 wct.linkPrev = false;
    1148                 if(isOneway(m)){
    1149                     wct.isOnewayHead = true;
    1150                     lastForwardWay = i-1;
    1151                     lastBackwardWay = i-1;
    1152                 } else {
    1153                     lastForwardWay = UNCONNECTED;
    1154                     lastBackwardWay = UNCONNECTED;
    1155                 }
    1156                 onewayBeginning = true;
    1157             }
    1158 
    1159             if(dirFW != NONE && dirBW != NONE) { //End of oneway loop
    1160                 if(i+1<members.size() && determineDirection(i, dirFW, i+1) != NONE) {
    1161                     wct.isOnewayLoopBackwardPart = false;
    1162                     dirBW = NONE;
    1163                     wct.direction = dirFW;
    1164                 } else {
    1165                     wct.isOnewayLoopForwardPart = false;
    1166                     dirFW = NONE;
    1167                     wct.direction = dirBW;
    1168                 }
    1169 
    1170                 wct.isOnewayTail = true;
    1171             }
    1172 
    1173         } else {
    1174             lastForwardWay = UNCONNECTED;
    1175             lastBackwardWay = UNCONNECTED;
    1176             if(dirFW == NONE || dirBW == NONE) {
    1177                 wct.linkPrev = false;
    1178             }
    1179         }
    1180         return wct;
    1181     }
    1182    
    1183     private static interface AdditionalSorter {
    1184         public boolean acceptsMember(RelationMember m);
    1185         public List<RelationMember> sortMembers(List<RelationMember> list);
    1186     }
    1187    
    1188     /**
    1189      * Class that sorts type=associatedStreet relation's houses.
    1190      */
    1191     private static class AssociatedStreetSorter implements AdditionalSorter {
    1192 
    1193         @Override
    1194         public boolean acceptsMember(RelationMember m) {
    1195             return m != null
    1196                     && m.getRole() != null && m.getRole().equals("house")
    1197                     && m.getMember() != null && m.getMember().get("addr:housenumber") != null;
    1198         }
    1199 
    1200         @Override
    1201         public List<RelationMember> sortMembers(List<RelationMember> list) {
    1202             Collections.sort(list, new Comparator<RelationMember>() {
    1203                 @Override
    1204                 public int compare(RelationMember a, RelationMember b) {
    1205                     if (a == b || a.getMember() == b.getMember()) return 0;
    1206                     String addrA = a.getMember().get("addr:housenumber").trim();
    1207                     String addrB = b.getMember().get("addr:housenumber").trim();
    1208                     if (addrA.equals(addrB)) return 0;
    1209                     // Strip non-digits (from "1B" addresses for example)
    1210                     String addrAnum = addrA.replaceAll("\\D+", "");
    1211                     String addrBnum = addrB.replaceAll("\\D+", "");
    1212                     // Compare only numbers
    1213                     try {
    1214                         Integer res = Integer.parseInt(addrAnum) - Integer.parseInt(addrBnum);
    1215                         if (res != 0) return res;
    1216                     } catch (NumberFormatException e) {
    1217                         // Ignore NumberFormatException. If the number is not composed of digits, strings are compared next
    1218                     }
    1219                     // Same number ? Compare full strings
    1220                     return addrA.compareTo(addrB);
    1221                 }
    1222             });
    1223             return list;
    1224         }
    1225     }
    1226769}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationNodeMap.java

    r5627 r5630  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.gui.dialogs.relation;
    3 
    4 import static org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction.NONE;
     2package org.openstreetmap.josm.gui.dialogs.relation.sort;
     3
     4import static org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType.Direction.NONE;
    55
    66import java.util.ArrayList;
     
    3030 */
    3131public class RelationNodeMap {
     32
    3233    private static class NodesWays{
    33         public Map<Node, Set<Integer>> nodes = new TreeMap<Node, Set<Integer>>();
    34         public Map<Integer, Set<Node>> ways = new TreeMap<Integer, Set<Node>>();
    35         public boolean oneWay;
     34        public final Map<Node, Set<Integer>> nodes = new TreeMap<Node, Set<Integer>>();
     35        public final Map<Integer, Set<Node>> ways = new TreeMap<Integer, Set<Node>>();
     36        public final boolean oneWay;
    3637        public NodesWays(boolean oneWay){
    3738            this.oneWay = oneWay;
     
    4243     * the maps. (Need TreeMap for efficiency.)
    4344     */
    44     private NodesWays map = new NodesWays(false);
     45    private final NodesWays map = new NodesWays(false);
    4546    /*
    4647     * Maps for oneways (forward/backward roles)
    4748     */
    4849
    49     private NodesWays onewayMap = new NodesWays(true);
    50     private NodesWays onewayReverseMap = new NodesWays(true);
     50    private final NodesWays onewayMap = new NodesWays(true);
     51    private final NodesWays onewayReverseMap = new NodesWays(true);
    5152    /*
    5253     * Used to keep track of what members are done.
    5354     */
    54     private Set<Integer> remaining;
    55     private Map<Integer, Set<Node>> remainingOneway = new TreeMap<Integer, Set<Node>>();;
     55    private final Set<Integer> remaining = new TreeSet<Integer>();
     56    private final Map<Integer, Set<Node>> remainingOneway = new TreeMap<Integer, Set<Node>>();
    5657
    5758    /**
    5859     * All members that are incomplete or not a way
    5960     */
    60     private List<Integer> notSortable = new ArrayList<Integer>();
     61    private final List<Integer> notSortable = new ArrayList<Integer>();
    6162
    6263    public static Node firstOnewayNode(RelationMember m){
     
    7374
    7475    RelationNodeMap(List<RelationMember> members) {
    75         map.nodes = new TreeMap<Node, Set<Integer>>();
    76         map.ways = new TreeMap<Integer, Set<Node>>();
    77 
    7876        for (int i = 0; i < members.size(); ++i) {
    7977            RelationMember m = members.get(i);
     
    8482
    8583            Way w = m.getWay();
    86             if ((MemberTableModel.roundaboutType(w) != NONE)) {
     84            if ((RelationSortUtils.roundaboutType(w) != NONE)) {
    8785                for (Node nd : w.getNodes()) {
    8886                    addPair(nd, i);
    8987                }
    90             } else if(MemberTableModel.isOneway(m)) {
     88            } else if(RelationSortUtils.isOneway(m)) {
    9189                addNodeWayMap(firstOnewayNode(m), i);
    9290                addWayNodeMap(lastOnewayNode(m), i);
     
    10199        }
    102100
    103         remaining = new TreeSet<Integer>();
    104101        remaining.addAll(map.ways.keySet());
    105102
     
    325322
    326323        if (remainingOneway.isEmpty()) return null;
    327         for(Integer i :remainingOneway.keySet()){ //find oneway, whic is connected to more than one way (is between two oneway loops)
     324        for(Integer i :remainingOneway.keySet()){ //find oneway, which is connected to more than one way (is between two oneway loops)
    328325            for(Node n : onewayReverseMap.ways.get(i)){
    329326                if(onewayReverseMap.nodes.containsKey(n) && onewayReverseMap.nodes.get(n).size() > 1) {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionType.java

    r5627 r5630  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.gui.dialogs.relation;
     2package org.openstreetmap.josm.gui.dialogs.relation.sort;
    33
    4 import static org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction.NONE;
     4import static org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType.Direction.NONE;
    55import static org.openstreetmap.josm.tools.I18n.tr;
    66
Note: See TracChangeset for help on using the changeset viewer.