Ignore:
Timestamp:
2017-02-12T16:32:18+01:00 (7 years ago)
Author:
Don-vip
Message:

refactor handling of null values - use Java 8 Optional where possible

Location:
trunk/src/org/openstreetmap/josm/gui/mappaint
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleCache.java

    r11212 r11553  
    33
    44import java.util.Arrays;
     5import java.util.Optional;
    56
    67import org.openstreetmap.josm.data.osm.Storage;
     
    4445
    4546        int idx = getIndex(selected);
    46         DividedScale<StyleElementList> ds = s.states[idx];
    47         if (ds == null) {
    48             ds = new DividedScale<>();
    49         }
    50         s.states[idx] = ds.put(o, r);
     47        s.states[idx] = Optional.ofNullable(s.states[idx]).orElseGet(DividedScale::new).put(o, r);
    5148        return s.intern();
    5249    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/LabelCompositionStrategy.java

    r10599 r11553  
    163163
    164164        private static List<String> buildNameTags(List<String> nameTags) {
    165             if (nameTags == null) {
    166                 nameTags = Collections.emptyList();
    167             }
    168165            List<String> result = new ArrayList<>();
    169             for (String tag: nameTags) {
    170                 if (tag == null) {
    171                     continue;
    172                 }
    173                 tag = tag.trim();
    174                 if (tag.isEmpty()) {
    175                     continue;
    176                 }
    177                 result.add(tag);
     166            if (nameTags != null) {
     167                for (String tag: nameTags) {
     168                    if (tag == null) {
     169                        continue;
     170                    }
     171                    tag = tag.trim();
     172                    if (tag.isEmpty()) {
     173                        continue;
     174                    }
     175                    result.add(tag);
     176                }
    178177            }
    179178            return result;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/LineElement.java

    r11452 r11553  
    66import java.util.Arrays;
    77import java.util.Objects;
     8import java.util.Optional;
    89
    910import org.openstreetmap.josm.Main;
     
    357358                if (casingWidth == null)
    358359                    return null;
    359                 width = getWidth(c, WIDTH, getWidth(cDef, WIDTH, null));
    360                 if (width == null) {
    361                     width = 0f;
    362                 }
    363                 width += 2 * casingWidth;
     360                width = Optional.ofNullable(getWidth(c, WIDTH, getWidth(cDef, WIDTH, null))).orElse(0f) + 2 * casingWidth;
    364361                break;
    365362            case LEFT_CASING:
     
    378375
    379376            /* if we have a "width" tag, try use it */
    380             String widthTag = env.osm.get("width");
    381             if (widthTag == null) {
    382                 widthTag = env.osm.get("est_width");
    383             }
     377            String widthTag = Optional.ofNullable(env.osm.get("width")).orElseGet(() -> env.osm.get("est_width"));
    384378            if (widthTag != null) {
    385379                try {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java

    r10875 r11553  
    167167            sizeOnDefault = null;
    168168        }
    169         Float size = getWidth(c, "symbol-size", sizeOnDefault);
    170 
    171         if (size == null) {
    172             size = 10f;
    173         }
    174 
     169        Float size = Optional.ofNullable(getWidth(c, "symbol-size", sizeOnDefault)).orElse(10f);
    175170        if (size <= 0)
    176171            return null;
Note: See TracChangeset for help on using the changeset viewer.