Changeset 11889 in josm for trunk/src/org


Ignore:
Timestamp:
2017-04-12T22:22:52+02:00 (7 years ago)
Author:
Don-vip
Message:

PMD - fix some InefficientEmptyStringCheck (new in PMD 5.5.5)

Location:
trunk/src/org/openstreetmap/josm
Files:
6 edited

Legend:

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

    r11419 r11889  
    1010import java.util.LinkedList;
    1111import java.util.List;
     12import java.util.Optional;
    1213
    1314import javax.swing.JLabel;
     
    6162        }
    6263
    63         String searchTerm = searchTermBox.getText();
    64         if (searchTerm == null || searchTerm.trim().isEmpty()) {
     64        String searchTerm = Optional.ofNullable(searchTermBox.getText()).orElse("").trim();
     65        if (searchTerm.isEmpty()) {
    6566            Notification notification = new Notification(tr("You must enter a search term"));
    6667            notification.setIcon(JOptionPane.WARNING_MESSAGE);
  • trunk/src/org/openstreetmap/josm/data/Version.java

    r10420 r11889  
    77import java.io.InputStream;
    88import java.util.Map.Entry;
     9import java.util.Optional;
    910import java.util.Properties;
    1011
     
    1415/**
    1516 * Provides basic information about the currently used JOSM build.
    16  *
     17 * @since 2358
    1718 */
    1819public class Version {
     
    6162            Main.warn(e, tr("Error reading revision info from revision file: {0}", e.getMessage()));
    6263        }
    63         String value = properties.getProperty("Revision");
    64         if (value != null) {
    65             value = value.trim();
     64        String value = Optional.ofNullable(properties.getProperty("Revision")).orElse("").trim();
     65        if (!value.isEmpty()) {
    6666            try {
    6767                version = Integer.parseInt(value);
     
    8383        // is this a local build ?
    8484        //
    85         isLocalBuild = false;
    86         value = properties.getProperty("Is-Local-Build");
    87         if (value != null && "true".equalsIgnoreCase(value.trim())) {
    88             isLocalBuild = true;
    89         }
     85        isLocalBuild = "true".equalsIgnoreCase(
     86                Optional.ofNullable(properties.getProperty("Is-Local-Build")).orElse("").trim());
    9087
    9188        // is this a specific build ?
    9289        //
    93         buildName = null;
    94         value = properties.getProperty("Build-Name");
    95         if (value != null && !value.trim().isEmpty()) {
    96             buildName = value.trim();
    97         }
     90        buildName = Optional.ofNullable(properties.getProperty("Build-Name")).orElse("").trim();
    9891
    9992        // the revision info
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r11858 r11889  
    375375        if (t != null) {
    376376            this.imageryType = t;
    377         } else if (type != null && !type.trim().isEmpty()) {
     377        } else if (type != null && !type.isEmpty()) {
    378378            throw new IllegalArgumentException("unknown type: "+type);
    379379        }
    380380    }
    381381
     382    /**
     383     * Constructs a new {@code ImageryInfo} with given name, url, id, extended and EULA URLs.
     384     * @param name The entry name
     385     * @param url The entry URL
     386     * @param type The entry imagery type. If null, WMS will be used as default
     387     * @param eulaAcceptanceRequired The EULA URL
     388     * @param cookies The data part of HTTP cookies header in case the service requires cookies to work
     389     * @param id tile id
     390     * @throws IllegalArgumentException if type refers to an unknown imagery type
     391     */
    382392    public ImageryInfo(String name, String url, String type, String eulaAcceptanceRequired, String cookies, String id) {
    383393        this(name, url, type, eulaAcceptanceRequired, cookies);
     
    558568    }
    559569
     570    /**
     571     * Determines if URL is equal to given imagery info.
     572     * @param in imagery info
     573     * @return {@code true} if URL is equal to given imagery info
     574     */
    560575    public boolean equalsBaseValues(ImageryInfo in) {
    561576        return url.equals(in.url);
  • trunk/src/org/openstreetmap/josm/data/projection/CustomProjection.java

    r11858 r11889  
    344344    public static Map<String, String> parseParameterList(String pref, boolean ignoreUnknownParameter) throws ProjectionConfigurationException {
    345345        Map<String, String> parameters = new HashMap<>();
    346         if (pref.trim().isEmpty()) {
     346        String trimmedPref = pref.trim();
     347        if (trimmedPref.isEmpty()) {
    347348            return parameters;
    348349        }
    349350
    350351        Pattern keyPattern = Pattern.compile("\\+(?<key>[a-zA-Z0-9_]+)(=(?<value>.*))?");
    351         String[] parts = Utils.WHITE_SPACES_PATTERN.split(pref.trim());
     352        String[] parts = Utils.WHITE_SPACES_PATTERN.split(trimmedPref);
    352353        for (String part : parts) {
    353354            Matcher m = keyPattern.matcher(part);
     
    488489    }
    489490
     491    /**
     492     * Parse {@code towgs84} parameter.
     493     * @param paramList List of parameter arguments (expected: 3 or 7)
     494     * @param ellps ellipsoid
     495     * @return parsed datum ({@link ThreeParameterDatum} or {@link SevenParameterDatum})
     496     * @throws ProjectionConfigurationException if the arguments cannot be parsed
     497     */
    490498    public Datum parseToWGS84(String paramList, Ellipsoid ellps) throws ProjectionConfigurationException {
    491499        String[] numStr = paramList.split(",");
  • trunk/src/org/openstreetmap/josm/data/validation/routines/UrlValidator.java

    r11747 r11889  
    2424import java.util.HashSet;
    2525import java.util.Locale;
     26import java.util.Optional;
    2627import java.util.Set;
    2728import java.util.regex.Matcher;
     
    428429        }
    429430
    430         String extra = authorityMatcher.group(PARSE_AUTHORITY_EXTRA);
    431         if (extra != null && !extra.trim().isEmpty()) {
    432             return false;
    433         }
    434 
    435         return true;
     431        return Optional.ofNullable(authorityMatcher.group(PARSE_AUTHORITY_EXTRA)).orElse("").trim().isEmpty();
    436432    }
    437433
  • trunk/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java

    r11129 r11889  
    197197    public List<OpeningHoursTestError> checkOpeningHourSyntax(final String key, final String value, CheckMode mode,
    198198            boolean ignoreOtherSeverity, String locale) {
    199         if (ENGINE == null || value == null || value.trim().isEmpty()) {
     199        if (ENGINE == null || value == null || value.isEmpty()) {
    200200            return Collections.emptyList();
    201201        }
Note: See TracChangeset for help on using the changeset viewer.