Changeset 9968 in josm


Ignore:
Timestamp:
2016-03-12T19:18:29+01:00 (9 years ago)
Author:
Don-vip
Message:

sonar - Add parentheses to make the operator precedence explicit + add unit tests

Location:
trunk
Files:
1 added
6 edited

Legend:

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

    r9067 r9968  
    198198        Arrays.sort(angles, new PolarNodeComparator());
    199199        int[] count = distributeNodes(angles,
    200                 numberOfNodesInCircle >= nodes.size() ? numberOfNodesInCircle - nodes.size() : 0);
     200                numberOfNodesInCircle >= nodes.size() ? (numberOfNodesInCircle - nodes.size()) : 0);
    201201
    202202        // now we can start doing things to OSM data
  • trunk/src/org/openstreetmap/josm/actions/ExtensionFileFilter.java

    r9547 r9968  
    319319            defaultExtension,
    320320            description + (!extensionsForDescription.isEmpty()
    321                 ? " (" + Utils.join(", ", extensionsForDescription) + ")"
     321                ? (" (" + Utils.join(", ", extensionsForDescription) + ")")
    322322                : "")
    323323            );
  • trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java

    r9230 r9968  
    7676        protected boolean isHeterogeneousSource() {
    7777            int count = 0;
    78             count = !getSourcePrimitivesByType(OsmPrimitiveType.NODE).isEmpty() ? count + 1 : count;
    79             count = !getSourcePrimitivesByType(OsmPrimitiveType.WAY).isEmpty() ? count + 1 : count;
    80             count = !getSourcePrimitivesByType(OsmPrimitiveType.RELATION).isEmpty() ? count + 1 : count;
     78            count = !getSourcePrimitivesByType(OsmPrimitiveType.NODE).isEmpty() ? (count + 1) : count;
     79            count = !getSourcePrimitivesByType(OsmPrimitiveType.WAY).isEmpty() ? (count + 1) : count;
     80            count = !getSourcePrimitivesByType(OsmPrimitiveType.RELATION).isEmpty() ? (count + 1) : count;
    8181            return count > 1;
    8282        }
  • trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java

    r9872 r9968  
    614614                        String role = rm.getRole();
    615615                        if ("from".equals(role) || "to".equals(role)) {
    616                             OsmPrimitive via = null;
    617                             for (RelationMember rmv : r.getMembers()) {
    618                                 if ("restriction".equals(type) && "via".equals(rmv.getRole())
    619                                         || "destination_sign".equals(type) && rmv.hasRole("sign", "intersection")) {
    620                                     via = rmv.getMember();
    621                                 }
    622                             }
     616                            OsmPrimitive via = findVia(r, type);
    623617                            List<Node> nodes = new ArrayList<>();
    624618                            if (via != null) {
     
    751745    }
    752746
     747    static OsmPrimitive findVia(Relation r, String type) {
     748        for (RelationMember rmv : r.getMembers()) {
     749            if (("restriction".equals(type) && "via".equals(rmv.getRole()))
     750             || ("destination_sign".equals(type) && rmv.hasRole("sign", "intersection"))) {
     751                return rmv.getMember();
     752            }
     753        }
     754        return null;
     755    }
     756
    753757    /**
    754758     * Splits the way {@code way} at the nodes in {@code atNodes} and replies
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r9572 r9968  
    535535                // existing way or make a new way of its own? The "alt" modifier means that the
    536536                // user wants a new way.
    537                 Way way = alt ? null : (selectedWay != null) ? selectedWay : getWayForNode(n0);
     537                Way way = alt ? null : (selectedWay != null ? selectedWay : getWayForNode(n0));
    538538                Way wayToSelect;
    539539
     
    15651565                    e0 = p0.east();
    15661566                    n0 = p0.north();
    1567                     buildLabelText((nearestAngle <= 180) ? nearestAngle : nearestAngle-360);
     1567                    buildLabelText((nearestAngle <= 180) ? nearestAngle : (nearestAngle-360));
    15681568
    15691569                    phi = (nearestAngle + activeBaseHeading) * Math.PI / 180;
  • trunk/test/unit/org/openstreetmap/josm/actions/SplitWayActionTest.java

    r9661 r9968  
    33
    44import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertNull;
    56import static org.junit.Assert.assertSame;
    67import static org.junit.Assert.assertTrue;
     
    102103    }
    103104
     105    /**
     106     * Unit test of {@link SplitWayAction#findVia}.
     107     */
     108    @Test
     109    public void testFindVia() {
     110        // empty relation
     111        assertNull(SplitWayAction.findVia(new Relation(), null));
     112        // restriction relation without via member
     113        Relation r = new Relation();
     114        r.addMember(new RelationMember("", new Node()));
     115        assertNull(SplitWayAction.findVia(r, "restriction"));
     116        // restriction relation with via member
     117        r = new Relation();
     118        OsmPrimitive via = new Node();
     119        r.addMember(new RelationMember("via", via));
     120        assertEquals(via, SplitWayAction.findVia(r, "restriction"));
     121        // destination_sign relation without sign nor intersection
     122        r = new Relation();
     123        r.addMember(new RelationMember("", new Node()));
     124        assertNull(SplitWayAction.findVia(r, "destination_sign"));
     125        // destination_sign with sign
     126        r = new Relation();
     127        via = new Node();
     128        r.addMember(new RelationMember("sign", via));
     129        assertEquals(via, SplitWayAction.findVia(r, "destination_sign"));
     130        // destination_sign with intersection
     131        r = new Relation();
     132        via = new Node();
     133        r.addMember(new RelationMember("intersection", via));
     134        assertEquals(via, SplitWayAction.findVia(r, "destination_sign"));
     135    }
     136
     137    /**
     138     * Unit tests of route relations.
     139     */
    104140    @Test
    105141    public void testRouteRelation() {
     
    143179        dataSet.setSelected(Arrays.asList(w2, n3, n4, n5));
    144180
    145 
    146181        final SplitWayAction.Strategy strategy = new SplitWayAction.Strategy() {
    147182
     
    174209        assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(5)), n6);
    175210        assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(5)), n7);
    176 
    177211    }
    178212
Note: See TracChangeset for help on using the changeset viewer.