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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java

    r11397 r11553  
    1515import java.util.Collection;
    1616import java.util.Date;
     17import java.util.Optional;
    1718import java.util.TreeSet;
    1819import java.util.regex.Matcher;
     
    362363    public static String explainGenericOsmApiException(OsmApiException e) {
    363364        Main.error(e);
    364         String errMsg = e.getErrorHeader();
    365         if (errMsg == null) {
    366             errMsg = e.getErrorBody();
    367         }
    368         if (errMsg == null) {
    369             errMsg = tr("no error message available");
    370         }
    371365        return tr("<html>"
    372366                + "Communication with the OSM server ''{0}''failed. The server replied<br>"
     
    377371                getUrlFromException(e),
    378372                e.getResponseCode(),
    379                 errMsg
     373                Optional.ofNullable(Optional.ofNullable(e.getErrorHeader()).orElseGet(e::getErrorBody))
     374                    .orElse(tr("no error message available"))
    380375        );
    381376    }
  • trunk/src/org/openstreetmap/josm/tools/HttpClient.java

    r11535 r11553  
    1919import java.util.Map;
    2020import java.util.Map.Entry;
     21import java.util.Optional;
    2122import java.util.Scanner;
    2223import java.util.TreeMap;
     
    148149                if (redirectLocation == null) {
    149150                    /* I18n: argument is HTTP response code */
    150                     String msg = tr("Unexpected response from HTTP server. Got {0} response without ''Location'' header." +
    151                             " Can''t redirect. Aborting.", connection.getResponseCode());
    152                     throw new IOException(msg);
     151                    throw new IOException(tr("Unexpected response from HTTP server. Got {0} response without ''Location'' header." +
     152                            " Can''t redirect. Aborting.", connection.getResponseCode()));
    153153                } else if (maxRedirects > 0) {
    154154                    url = new URL(url, redirectLocation);
     
    284284            } catch (IOException ioe) {
    285285                Main.debug(ioe);
    286                 in = connection.getErrorStream();
    287                 if (in == null) {
    288                     in = new ByteArrayInputStream(new byte[]{});
    289                 }
     286                in = Optional.ofNullable(connection.getErrorStream()).orElseGet(() -> new ByteArrayInputStream(new byte[]{}));
    290287            }
    291288            in = new ProgressInputStream(in, getContentLength(), monitor);
  • trunk/src/org/openstreetmap/josm/tools/Shortcut.java

    r11454 r11553  
    384384
    385385    private static int getGroupModifier(int group) {
    386         Integer m = groups.get(group);
    387         if (m == null)
    388             m = -1;
    389         return m;
     386        return Optional.ofNullable(groups.get(group)).orElse(-1);
    390387    }
    391388
Note: See TracChangeset for help on using the changeset viewer.