Ticket #17600: 17600.patch

File 17600.patch, 15.2 KB (added by taylor.smock, 6 years ago)

Replace deprecated functions and move Utils.java to TurnlanesUtils.java with appropriate name changes.

  • src/org/openstreetmap/josm/plugins/turnlanes/gui/RoadGui.java

     
    3838import org.openstreetmap.josm.data.osm.Way;
    3939import org.openstreetmap.josm.plugins.turnlanes.model.Lane;
    4040import org.openstreetmap.josm.plugins.turnlanes.model.Road;
    41 import org.openstreetmap.josm.plugins.turnlanes.model.Utils;
     41import org.openstreetmap.josm.plugins.turnlanes.model.TurnlanesUtils;
    4242
    4343class RoadGui {
    4444    final class ViaConnector extends InteractiveElement {
     
    628628
    629629        final Node n = end.getJunction().getNode();
    630630        for (Way w : org.openstreetmap.josm.tools.Utils.filteredCollection(n.getReferrers(), Way.class)) {
    631             if (w.getNodesCount() > 1 && !end.getWay().equals(w) && w.isFirstLastNode(n) && Utils.isRoad(w)) {
     631            if (w.getNodesCount() > 1 && !end.getWay().equals(w) && w.isFirstLastNode(n) && TurnlanesUtils.isRoad(w)) {
    632632                final Node nextNode = w.firstNode().equals(n) ? w.getNode(1) : w.getNode(w.getNodesCount() - 2);
    633633                final Point2D nextNodeLoc = getContainer().translateAndScale(loc(nextNode));
    634634                result.add(new Extender(end, w, angle(a.getPoint(), nextNodeLoc)));
  • src/org/openstreetmap/josm/plugins/turnlanes/model/Lane.java

     
    6868    }
    6969
    7070    static int getRegularCount(Way w, Node end) {
    71         final int count = Utils.parseIntTag(w, "lanes");
     71        final int count = TurnlanesUtils.parseIntTag(w, "lanes");
    7272        final boolean forward = w.lastNode().equals(end);
    7373
    7474        if (w.hasDirectionKeys()) {
     
    8888
    8989    private static int getRegularCountTwoWay(Way w, boolean forward, final int count) {
    9090        if (w.get("lanes:backward") != null) {
    91             final int backwardCount = Utils.parseIntTag(w, "lanes:backward");
     91            final int backwardCount = TurnlanesUtils.parseIntTag(w, "lanes:backward");
    9292            return forward ? count - backwardCount : backwardCount;
    9393        }
    9494
    9595        if (w.get("lanes:forward") != null) {
    96             final int forwardCount = Utils.parseIntTag(w, "lanes:forward");
     96            final int forwardCount = TurnlanesUtils.parseIntTag(w, "lanes:forward");
    9797            return forward ? forwardCount : count - forwardCount;
    9898        }
    9999
     
    204204            if (via.isEmpty()) {
    205205                r.addMember(new RelationMember(Constants.TURN_ROLE_VIA, getOutgoingJunction().getNode()));
    206206            } else {
    207                 for (Way w : Utils.flattenVia(getOutgoingJunction().getNode(), via, to.getJunction().getNode())) {
     207                for (Way w : TurnlanesUtils.flattenVia(getOutgoingJunction().getNode(), via, to.getJunction().getNode())) {
    208208                    r.addMember(new RelationMember(Constants.TURN_ROLE_VIA, w));
    209209                }
    210210            }
  • src/org/openstreetmap/josm/plugins/turnlanes/model/ModelContainer.java

     
    4444            closed = true;
    4545
    4646            for (Node n : new ArrayList<>(closedNodes)) {
    47                 for (Way w : Utils.filterRoads(n.getReferrers())) {
     47                for (Way w : TurnlanesUtils.filterRoads(n.getReferrers())) {
    4848                    if (w.isFirstLastNode(n)) {
    4949                        closed &= close(closedNodes, closedWays, w);
    5050                    }
     
    7979        boolean closed = true;
    8080
    8181        final List<Way> via = new ArrayList<>();
    82         for (RelationMember m : Utils.getMembers(r, Constants.TURN_ROLE_VIA)) {
     82        for (RelationMember m : TurnlanesUtils.getMembers(r, Constants.TURN_ROLE_VIA)) {
    8383            if (m.isWay()) {
    8484                closed &= !closedWays.add(m.getWay());
    8585                via.add(m.getWay());
     
    8989        }
    9090
    9191        if (!via.isEmpty()) {
    92             final Way from = Utils.getMemberWay(r, Constants.TURN_ROLE_FROM);
    93             final Way to = Utils.getMemberWay(r, Constants.TURN_ROLE_TO);
     92            final Way from = TurnlanesUtils.getMemberWay(r, Constants.TURN_ROLE_FROM);
     93            final Way to = TurnlanesUtils.getMemberWay(r, Constants.TURN_ROLE_TO);
    9494
    95             closed &= !closedNodes.add(Utils.lineUp(from, via.get(0)));
    96             closed &= !closedNodes.add(Utils.lineUp(via.get(via.size() - 1), to));
     95            closed &= !closedNodes.add(TurnlanesUtils.lineUp(from, via.get(0)));
     96            closed &= !closedNodes.add(TurnlanesUtils.lineUp(via.get(via.size() - 1), to));
    9797        }
    9898
    9999        return closed;
     
    141141                }
    142142            }
    143143
    144             for (Route r : Utils.orderWays(this.primaryWays, this.primaryNodes)) {
     144            for (Route r : TurnlanesUtils.orderWays(this.primaryWays, this.primaryNodes)) {
    145145                addRoad(new Road(this, r));
    146146            }
    147147
     
    158158
    159159        for (Node n : primaryNodes) {
    160160            final List<Way> ws = new ArrayList<>();
    161             for (Way w : Utils.filterRoads(n.getReferrers())) {
     161            for (Way w : TurnlanesUtils.filterRoads(n.getReferrers())) {
    162162                if (w.isFirstLastNode(n)) {
    163163                    ws.add(w);
    164164                }
  • src/org/openstreetmap/josm/plugins/turnlanes/model/Road.java

     
    123123            final String lengthStr = toLengthString(length);
    124124            final Relation target;
    125125            if (rel == null) {
    126                 if (other == null || !Utils.getMemberNode(other, "end").equals(n)) {
     126                if (other == null || !TurnlanesUtils.getMemberNode(other, "end").equals(n)) {
    127127                    target = createLengthsRelation();
    128128                } else {
    129129                    target = other;
  • src/org/openstreetmap/josm/plugins/turnlanes/model/Route.java

     
    9797    }
    9898
    9999    public static Route load(Relation r) {
    100         final Node end = Utils.getMemberNode(r, Constants.LENGTHS_ROLE_END);
    101         final List<Way> ws = Utils.getMemberWays(r, Constants.LENGTHS_ROLE_WAYS);
     100        final Node end = TurnlanesUtils.getMemberNode(r, Constants.LENGTHS_ROLE_END);
     101        final List<Way> ws = TurnlanesUtils.getMemberWays(r, Constants.LENGTHS_ROLE_WAYS);
    102102
    103103        return create(ws, end);
    104104    }
     
    142142                throw new IllegalArgumentException("Ways must be ordered.");
    143143            }
    144144
    145             final Node start = Utils.getOppositeEnd(w, end);
     145            final Node start = TurnlanesUtils.getOppositeEnd(w, end);
    146146            segments.add(0, new Segment(start, w, end));
    147147            end = start;
    148148        }
  • src/org/openstreetmap/josm/plugins/turnlanes/model/Turn.java

     
    5353    }
    5454
    5555    private static Set<Turn> loadWithViaWays(ModelContainer c, Relation r) {
    56         final Way from = Utils.getMemberWay(r, Constants.TURN_ROLE_FROM);
    57         final Way to = Utils.getMemberWay(r, Constants.TURN_ROLE_TO);
     56        final Way from = TurnlanesUtils.getMemberWay(r, Constants.TURN_ROLE_FROM);
     57        final Way to = TurnlanesUtils.getMemberWay(r, Constants.TURN_ROLE_TO);
    5858
    5959        if (!c.hasRoad(from) || !c.hasRoad(to)) {
    6060            return Collections.emptySet();
    6161        }
    6262
    63         final List<Way> tmp = Utils.getMemberWays(r, Constants.TURN_ROLE_VIA);
     63        final List<Way> tmp = TurnlanesUtils.getMemberWays(r, Constants.TURN_ROLE_VIA);
    6464        final LinkedList<Road> via = new LinkedList<>();
    6565
    66         final Road.End fromRoadEnd = c.getJunction(Utils.lineUp(from, tmp.get(0))).getRoadEnd(from);
     66        final Road.End fromRoadEnd = c.getJunction(TurnlanesUtils.lineUp(from, tmp.get(0))).getRoadEnd(from);
    6767
    6868        Node n = fromRoadEnd.getJunction().getNode();
    6969        final Iterator<Way> it = tmp.iterator();
     
    7575
    7676            final Road v = c.getRoad(w);
    7777            via.add(v);
    78             n = Utils.getOppositeEnd(w, n);
     78            n = TurnlanesUtils.getOppositeEnd(w, n);
    7979
    8080            if (!v.isPrimary()) {
    8181                throw new IllegalStateException("The road is not part of the junction.");
     
    8787
    8888            while (it2.hasNext()) {
    8989                final Way w2 = it2.next().getWay();
    90                 n = Utils.getOppositeEnd(w2, n);
     90                n = TurnlanesUtils.getOppositeEnd(w2, n);
    9191
    9292                if (!it.hasNext() || !w2.equals(it.next())) {
    9393                    throw new IllegalStateException("The via ways of the relation do not form a road.");
     
    9595            }
    9696        }
    9797        final Road.End toRoadEnd = c.getJunction(n).getRoadEnd(to);
    98         n = Utils.getOppositeEnd(to, n);
     98        n = TurnlanesUtils.getOppositeEnd(to, n);
    9999
    100100        final Set<Turn> result = new HashSet<>();
    101101        for (int i : indices(r, Constants.TURN_KEY_LANES)) {
     
    123123    }
    124124
    125125    private static Set<Turn> loadWithViaNode(ModelContainer c, Relation r) {
    126         final Way from = Utils.getMemberWay(r, Constants.TURN_ROLE_FROM);
    127         final Node via = Utils.getMemberNode(r, Constants.TURN_ROLE_VIA);
    128         final Way to = Utils.getMemberWay(r, Constants.TURN_ROLE_TO);
     126        final Way from = TurnlanesUtils.getMemberWay(r, Constants.TURN_ROLE_FROM);
     127        final Node via = TurnlanesUtils.getMemberNode(r, Constants.TURN_ROLE_VIA);
     128        final Way to = TurnlanesUtils.getMemberWay(r, Constants.TURN_ROLE_TO);
    129129
    130130        if (!c.hasRoad(from) || !c.hasJunction(via) || !c.hasRoad(to)) {
    131131            return Collections.emptySet();
  • src/org/openstreetmap/josm/plugins/turnlanes/model/Validator.java

     
    1616
    1717import org.openstreetmap.josm.data.osm.DataSet;
    1818import org.openstreetmap.josm.data.osm.Node;
    19 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2019import org.openstreetmap.josm.data.osm.Relation;
    2120import org.openstreetmap.josm.data.osm.RelationMember;
    2221import org.openstreetmap.josm.data.osm.Way;
    2322import org.openstreetmap.josm.plugins.turnlanes.model.Issue.QuickFix;
     23import org.openstreetmap.josm.tools.Utils;
    2424
    2525public class Validator {
    2626    private static final class IncomingLanes {
     
    108108        final List<Relation> lenghts = new ArrayList<>();
    109109        final List<Relation> turns = new ArrayList<>();
    110110
    111         for (Relation r : OsmPrimitive.getFilteredList(dataSet.allPrimitives(), Relation.class)) {
     111        for (Relation r : Utils.filteredCollection(dataSet.allPrimitives(), Relation.class)) {
    112112            if (!r.isUsable()) {
    113113                continue;
    114114            }
     
    151151        final List<Issue> issues = new ArrayList<>();
    152152
    153153        try {
    154             final Node end = Utils.getMemberNode(r, Constants.LENGTHS_ROLE_END);
     154            final Node end = TurnlanesUtils.getMemberNode(r, Constants.LENGTHS_ROLE_END);
    155155            final Route route = validateLengthsWays(r, end, issues);
    156156
    157157            if (route == null) {
     
    206206    }
    207207
    208208    private Route validateLengthsWays(Relation r, Node end, List<Issue> issues) {
    209         final List<Way> ways = Utils.getMemberWays(r, Constants.LENGTHS_ROLE_WAYS);
     209        final List<Way> ways = TurnlanesUtils.getMemberWays(r, Constants.LENGTHS_ROLE_WAYS);
    210210
    211211        if (ways.isEmpty()) {
    212212            issues.add(Issue.newError(r, "A lengths-relation requires at least one member-way with role \""
     
    220220                return orderWays(r, ways, current, issues, "ways", "lengths");
    221221            }
    222222
    223             current = Utils.getOppositeEnd(w, current);
     223            current = TurnlanesUtils.getOppositeEnd(w, current);
    224224        }
    225225
    226226        return Route.create(ways, end);
     
    246246                if (w.isFirstLastNode(current)) {
    247247                    it.remove();
    248248                    ordered.add(w);
    249                     current = Utils.getOppositeEnd(w, current);
     249                    current = TurnlanesUtils.getOppositeEnd(w, current);
    250250                    continue findNext;
    251251                }
    252252            }
     
    293293        final List<Issue> issues = new ArrayList<>();
    294294
    295295        try {
    296             final Way from = Utils.getMemberWay(r, Constants.TURN_ROLE_FROM);
    297             final Way to = Utils.getMemberWay(r, Constants.TURN_ROLE_TO);
     296            final Way from = TurnlanesUtils.getMemberWay(r, Constants.TURN_ROLE_FROM);
     297            final Way to = TurnlanesUtils.getMemberWay(r, Constants.TURN_ROLE_TO);
    298298
    299299            if (from.firstNode().equals(from.lastNode())) {
    300300                issues.add(Issue.newError(r, from, "The from-way both starts as well as ends at the via-node."));
     
    307307            }
    308308
    309309            final Node fromJunctionNode;
    310             final List<RelationMember> viaMembers = Utils.getMembers(r, Constants.TURN_ROLE_VIA);
     310            final List<RelationMember> viaMembers = TurnlanesUtils.getMembers(r, Constants.TURN_ROLE_VIA);
    311311            if (viaMembers.isEmpty()) {
    312312                throw UnexpectedDataException.Kind.NO_MEMBER.chuck(Constants.TURN_ROLE_VIA);
    313313            } else if (viaMembers.get(0).isWay()) {
    314                 final List<Way> vias = Utils.getMemberWays(r, Constants.TURN_ROLE_VIA);
     314                final List<Way> vias = TurnlanesUtils.getMemberWays(r, Constants.TURN_ROLE_VIA);
    315315
    316                 fromJunctionNode = Utils.lineUp(from, vias.get(0));
     316                fromJunctionNode = TurnlanesUtils.lineUp(from, vias.get(0));
    317317                Node current = fromJunctionNode;
    318318                for (Way via : vias) {
    319319                    if (!via.isFirstLastNode(current)) {
     
    321321                        break;
    322322                    }
    323323
    324                     current = Utils.getOppositeEnd(via, current);
     324                    current = TurnlanesUtils.getOppositeEnd(via, current);
    325325                }
    326326            } else {
    327                 final Node via = Utils.getMemberNode(r, Constants.TURN_ROLE_VIA);
     327                final Node via = TurnlanesUtils.getMemberNode(r, Constants.TURN_ROLE_VIA);
    328328
    329329                if (!from.isFirstLastNode(via)) {
    330330                    issues.add(Issue.newError(r, from, "The from-way does not start or end at the via-node."));