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/io
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/io/CloseChangesetTask.java

    r10611 r11553  
    88import java.util.Collection;
    99import java.util.List;
     10import java.util.Optional;
    1011
    1112import javax.swing.SwingUtilities;
     
    3839    public CloseChangesetTask(Collection<Changeset> changesets) {
    3940        super(tr("Closing changeset"), false /* don't ignore exceptions */);
    40         if (changesets == null) {
    41             changesets = new ArrayList<>();
    42         }
    43         this.changesets = changesets;
     41        this.changesets = Optional.ofNullable(changesets).orElseGet(ArrayList::new);
    4442        this.closedChangesets = new ArrayList<>();
    4543    }
  • trunk/src/org/openstreetmap/josm/gui/io/SaveLayerTask.java

    r10378 r11553  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
     5
     6import java.util.Optional;
    57
    68import org.openstreetmap.josm.Main;
     
    3840    protected SaveLayerTask(SaveLayerInfo layerInfo, ProgressMonitor monitor) {
    3941        CheckParameterUtil.ensureParameterNotNull(layerInfo, "layerInfo");
    40         if (monitor == null) {
    41             monitor = NullProgressMonitor.INSTANCE;
    42         }
    4342        this.layerInfo = layerInfo;
    44         this.parentMonitor = monitor;
     43        this.parentMonitor = Optional.ofNullable(monitor).orElse(NullProgressMonitor.INSTANCE);
    4544    }
    4645
  • trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java

    r10413 r11553  
    44import java.awt.BorderLayout;
    55import java.util.Map;
     6import java.util.Optional;
    67
    78import javax.swing.JPanel;
     
    125126            if (e.getSource() instanceof ChangesetCommentModel) {
    126127                String newValue = ((ChangesetCommentModel) e.getSource()).getComment();
    127                 String oldValue = getTagEditorValue(key);
    128                 if (oldValue == null) {
    129                     oldValue = "";
    130                 }
     128                String oldValue = Optional.ofNullable(getTagEditorValue(key)).orElse("");
    131129                if (!oldValue.equals(newValue)) {
    132130                    setProperty(key, newValue);
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r11452 r11553  
    2525import java.util.Map;
    2626import java.util.Map.Entry;
     27import java.util.Optional;
    2728import java.util.concurrent.TimeUnit;
    2829
     
    343344     */
    344345    public Changeset getChangeset() {
    345         Changeset cs = pnlChangesetManagement.getSelectedChangeset();
    346         if (cs == null) {
    347             cs = new Changeset();
    348         }
     346        Changeset cs = Optional.ofNullable(pnlChangesetManagement.getSelectedChangeset()).orElseGet(Changeset::new);
    349347        cs.setKeys(pnlTagSettings.getTags(false));
    350348        return cs;
  • trunk/src/org/openstreetmap/josm/gui/io/UploadLayerTask.java

    r11386 r11553  
    66import java.util.Collection;
    77import java.util.HashSet;
     8import java.util.Optional;
    89import java.util.Set;
    910
     
    6263        CheckParameterUtil.ensureParameterNotNull(layer, "layer");
    6364        CheckParameterUtil.ensureParameterNotNull(strategy, "strategy");
    64         if (monitor == null) {
    65             monitor = NullProgressMonitor.INSTANCE;
    66         }
    6765        this.layer = layer;
    68         this.monitor = monitor;
     66        this.monitor = Optional.ofNullable(monitor).orElse(NullProgressMonitor.INSTANCE);
    6967        this.changeset = changeset;
    7068        this.strategy = strategy;
  • trunk/src/org/openstreetmap/josm/gui/io/UploadNoteLayerTask.java

    r8624 r11553  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
     5
     6import java.util.Optional;
    57
    68import org.openstreetmap.josm.actions.upload.UploadNotesTask;
     
    2931    public UploadNoteLayerTask(NoteLayer layer, ProgressMonitor monitor) {
    3032        CheckParameterUtil.ensureParameterNotNull(layer, "layer");
    31         if (monitor == null) {
    32             monitor = NullProgressMonitor.INSTANCE;
    33         }
    3433        this.layer = layer;
    35         this.monitor = monitor;
     34        this.monitor = Optional.ofNullable(monitor).orElse(NullProgressMonitor.INSTANCE);
    3635    }
    3736
  • trunk/src/org/openstreetmap/josm/gui/io/UploadedObjectsSummaryPanel.java

    r10378 r11553  
    99import java.util.ArrayList;
    1010import java.util.List;
     11import java.util.Optional;
    1112
    1213import javax.swing.AbstractListModel;
     
    174175
    175176        public void setPrimitives(List<OsmPrimitive> primitives) {
    176             if (primitives == null) {
    177                 this.primitives = new ArrayList<>();
    178             } else {
    179                 this.primitives = primitives;
    180             }
     177            this.primitives = Optional.ofNullable(primitives).orElseGet(ArrayList::new);
    181178            fireContentsChanged(this, 0, getSize());
    182179        }
Note: See TracChangeset for help on using the changeset viewer.