Changeset 10953 in josm for trunk/src/org


Ignore:
Timestamp:
2016-09-04T02:29:18+02:00 (8 years ago)
Author:
Don-vip
Message:

sonar - squid:S3655 - Optional value should only be accessed after calling isPresent()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    r10942 r10953  
    3434import java.util.Map;
    3535import java.util.NoSuchElementException;
     36import java.util.Optional;
    3637import java.util.concurrent.ForkJoinPool;
    3738import java.util.concurrent.ForkJoinTask;
     
    12861287        if (!longHalfSegment.isEmpty()) {
    12871288            // find the segment with the best quality. If there are several with best quality, the one close to the center is prefered.
    1288             HalfSegment best = longHalfSegment.stream().max(
     1289            Optional<HalfSegment> besto = longHalfSegment.stream().max(
    12891290                    Comparator.comparingDouble(segment ->
    12901291                        segment.quality - 1e-5 * Math.abs(0.5 * (segment.end + segment.start) - 0.5 * pathLength)
    1291                     )).get();
     1292                    ));
     1293            if (!besto.isPresent())
     1294                throw new IllegalStateException("Unable to find the segment with the best quality for " + way);
     1295            HalfSegment best = besto.get();
    12921296            double remaining = best.end - best.start - rec.getWidth(); // total space left and right from the text
    12931297            // The space left and right of the text should be distributed 20% - 80% (towards the center),
Note: See TracChangeset for help on using the changeset viewer.