Changeset 15427 in josm for trunk


Ignore:
Timestamp:
2019-10-06T00:32:07+02:00 (5 years ago)
Author:
Don-vip
Message:

fix recent SonarQube issues

Location:
trunk
Files:
9 edited

Legend:

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

    r15419 r15427  
    184184
    185185            String lengthstr = SystemOfMeasurement.getSystemOfMeasurement().getDistText(
    186                     ways.stream().collect(
    187                             Collectors.summingDouble(w -> {
    188                                 return w.getLength();
    189                             })));
     186                    ways.stream().mapToDouble(Way::getLength).sum());
    190187
    191188            double err = askSimplifyWays(trn(
  • trunk/src/org/openstreetmap/josm/data/SystemOfMeasurement.java

    r15396 r15427  
    55
    66import java.text.NumberFormat;
     7import java.util.Collections;
    78import java.util.Locale;
    89import java.util.Map;
     
    7374     * @since 3406
    7475     */
    75     public static final Map<String, SystemOfMeasurement> ALL_SYSTEMS = Stream.of(METRIC, CHINESE, IMPERIAL, NAUTICAL_MILE)
    76             .collect(Collectors.toMap(SystemOfMeasurement::getName, Function.identity()));
     76    public static final Map<String, SystemOfMeasurement> ALL_SYSTEMS = Collections.unmodifiableMap(
     77            Stream.of(METRIC, CHINESE, IMPERIAL, NAUTICAL_MILE)
     78            .collect(Collectors.toMap(SystemOfMeasurement::getName, Function.identity())));
    7779
    7880    /**
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java

    r15398 r15427  
    436436
    437437    /**
     438     * Ensures a unique name among gpx layers
    438439     * @param attrs attributes of/for an gpx track, written to if the name appeared previously in {@code counts}.
    439440     * @param counts a {@code HashMap} of previously seen names, associated with their count.
  • trunk/src/org/openstreetmap/josm/data/validation/tests/SharpAngles.java

    r15406 r15427  
    99import java.util.Map;
    1010import java.util.Map.Entry;
     11import java.util.Objects;
    1112import java.util.TreeSet;
    1213
     
    2021import org.openstreetmap.josm.data.validation.TestError;
    2122import org.openstreetmap.josm.tools.Geometry;
    22 import org.openstreetmap.josm.tools.Logging;
     23import org.openstreetmap.josm.tools.bugreport.BugReport;
    2324
    2425/**
     
    5657            try {
    5758                checkWayForSharpAngles(way);
    58             } catch (Exception e) {
    59                 Logging.error("Way https://osm.org/way/{0} caused an error ({1})", way.getUniqueId(), e);
    60                 throw e;
     59            } catch (RuntimeException e) {
     60                throw BugReport.intercept(e).put("way", way);
    6161            }
    6262        }
     
    159159        severityBreakPoints.put(maxAngle * 2 / 3, Severity.WARNING);
    160160    }
     161
     162    @Override
     163    public int hashCode() {
     164        return 31 * super.hashCode() + Objects.hash(ignoreHighways, maxAngle, maxLength);
     165    }
     166
     167    @Override
     168    public boolean equals(Object obj) {
     169        if (this == obj)
     170            return true;
     171        if (!super.equals(obj) || getClass() != obj.getClass())
     172            return false;
     173        SharpAngles other = (SharpAngles) obj;
     174        return Objects.equals(ignoreHighways, other.ignoreHighways)
     175                && Double.doubleToLongBits(maxAngle) == Double.doubleToLongBits(other.maxAngle)
     176                && Double.doubleToLongBits(maxLength) == Double.doubleToLongBits(other.maxLength);
     177    }
    161178}
    162 
  • trunk/src/org/openstreetmap/josm/gui/io/importexport/GeoJSONImporter.java

    r15424 r15427  
    5252            progressMonitor.worked(1);
    5353            MainApplication.getLayerManager().addLayer(new OsmDataLayer(data, file.getName(), file));
    54         } catch (final Exception e) {
     54        } catch (IOException | IllegalDataException e) {
    5555            Logging.error("Error while reading json file!");
    5656            Logging.error(e);
  • trunk/src/org/openstreetmap/josm/io/GeoJSONReader.java

    r15424 r15427  
    8989    private void parseFeature(final JsonObject feature) {
    9090        JsonValue geometry = feature.get(GEOMETRY);
    91         if (geometry != null && geometry.getValueType().equals(JsonValue.ValueType.OBJECT)) {
     91        if (geometry != null && geometry.getValueType() == JsonValue.ValueType.OBJECT) {
    9292            parseGeometry(feature, geometry.asJsonObject());
    9393        } else {
    9494            JsonValue properties = feature.get(PROPERTIES);
    95             if (properties != null && properties.getValueType().equals(JsonValue.ValueType.OBJECT)) {
     95            if (properties != null && properties.getValueType() == JsonValue.ValueType.OBJECT) {
    9696                parseNonGeometryFeature(feature, properties.asJsonObject());
    9797            } else {
     
    104104        // get relation type
    105105        JsonValue type = properties.get(TYPE);
    106         if (type == null || properties.getValueType().equals(JsonValue.ValueType.STRING)) {
     106        if (type == null || properties.getValueType() == JsonValue.ValueType.STRING) {
    107107            Logging.warn(tr("Relation/non-geometry feature without type found: {0}", feature));
    108108            return;
     
    258258    }
    259259
    260     private void fillTagsFromFeature(final JsonObject feature, final OsmPrimitive primitive) {
     260    private static void fillTagsFromFeature(final JsonObject feature, final OsmPrimitive primitive) {
    261261        if (feature != null) {
    262262            primitive.setKeys(getTags(feature));
     
    264264    }
    265265
    266     private void parseUnknown(final JsonObject object) {
     266    private static void parseUnknown(final JsonObject object) {
    267267        Logging.warn(tr("Unknown json object found {0}", object));
    268268    }
    269269
    270     private void parseNullGeometry(JsonObject feature) {
     270    private static void parseNullGeometry(JsonObject feature) {
    271271        Logging.warn(tr("Geometry of feature {0} is null", feature));
    272272    }
    273273
    274     private Map<String, String> getTags(final JsonObject feature) {
     274    private static Map<String, String> getTags(final JsonObject feature) {
    275275        final Map<String, String> tags = new TreeMap<>();
    276276
    277277        if (feature.containsKey(PROPERTIES) && !feature.isNull(PROPERTIES)) {
    278278            JsonValue properties = feature.get(PROPERTIES);
    279             if (properties != null && JsonValue.ValueType.OBJECT.equals(properties.getValueType())) {
     279            if (properties != null && properties.getValueType() == JsonValue.ValueType.OBJECT) {
    280280                for (Map.Entry<String, JsonValue> stringJsonValueEntry : properties.asJsonObject().entrySet()) {
    281281                    final JsonValue value = stringJsonValueEntry.getValue();
  • trunk/src/org/openstreetmap/josm/io/GeoJSONServerReader.java

    r15424 r15427  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.io.IOException;
    67import java.util.Objects;
    78
     
    3233            progressMonitor.beginTask(tr("Contacting Server…"), 10);
    3334            return new GeoJSONImporter().parseDataSet(url);
    34         } catch (Exception e) {
     35        } catch (IOException | IllegalDataException e) {
    3536            throw new OsmTransferException(e);
    3637        } finally {
  • trunk/src/org/openstreetmap/josm/tools/XmlObjectParser.java

    r15401 r15427  
    140140                fieldName += '_';
    141141            }
    142             fieldName = fieldName.replaceAll(":", "_");
     142            fieldName = fieldName.replace(':', '_');
    143143            try {
    144144                Object c = current.peek();
  • trunk/test/unit/org/openstreetmap/josm/io/GeoJSONReaderTest.java

    r15424 r15427  
    3939     */
    4040    @Test
    41     public void test() throws Exception {
     41    public void testReadGeoJson() throws Exception {
    4242        try (InputStream in = Files.newInputStream(Paths.get(TestUtils.getTestDataRoot(), "geo.json"))) {
    4343            final List<OsmPrimitive> primitives = new ArrayList<>(new GeoJSONReader()
Note: See TracChangeset for help on using the changeset viewer.