Changeset 17787 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2021-04-14T21:29:47+02:00 (3 years ago)
Author:
simon04
Message:

fix #20741 - Various code simplifications (patch by gaben)

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

Legend:

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

    r16866 r17787  
    8787
    8888        } else if (GpxUrlPattern.TRACKPOINTS_BBOX.matches(url)) {
    89             String[] table = url.split("\\?|=|&", -1);
     89            String[] table = url.split("[?=&]", -1);
    9090            for (int i = 0; i < table.length; i++) {
    9191                if ("bbox".equals(table[i]) && i < table.length-1)
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadSessionTask.java

    r16630 r17787  
    2323public class DownloadSessionTask extends AbstractDownloadTask<Object> {
    2424
    25     private static final String PATTERN_SESSION = "https?://.*/.*\\.jo(s|z)";
     25    private static final String PATTERN_SESSION = "https?://.*/.*\\.jo([sz])";
    2626
    2727    private Loader loader;
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r17670 r17787  
    442442
    443443        try (PreferencesWriter writer = new PreferencesWriter(
    444                 new PrintWriter(new File(prefFile + "_tmp"), StandardCharsets.UTF_8.name()), false, defaults)) {
     444                new PrintWriter(prefFile + "_tmp", StandardCharsets.UTF_8.name()), false, defaults)) {
    445445            writer.write(settings);
    446446        } catch (SecurityException e) {
  • trunk/src/org/openstreetmap/josm/data/coor/conversion/LatLonParser.java

    r13602 r17787  
    4343            + "('|"+MIN+"|min)|"                // (4)
    4444            + "(\"|"+SEC+"|sec)|"               // (5)
    45             + "(,|;)|"                          // (6)
     45            + "([,;])|"                         // (6)
    4646            + "([NSEW"+N_TR+S_TR+E_TR+W_TR+"])|"// (7)
    4747            + "\\s+|"
  • trunk/src/org/openstreetmap/josm/data/osm/Storage.java

    r16630 r17787  
    232232        modCount++;
    233233        size = 0;
    234         for (int i = 0; i < data.length; i++) {
    235             data[i] = null;
    236         }
     234        Arrays.fill(data, null);
    237235    }
    238236
  • trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java

    r17786 r17787  
    732732                    String v1 = Normalizer.normalize(caseSensitive ? mv : mv.toLowerCase(Locale.ENGLISH), Normalizer.Form.NFC);
    733733                    String v2 = Normalizer.normalize(caseSensitive ? value : value.toLowerCase(Locale.ENGLISH), Normalizer.Form.NFC);
    734                     return v1.indexOf(v2) != -1;
     734                    return v1.contains(v2);
    735735                }
    736736            }
     
    10721072                    value = Normalizer.normalize(value, Normalizer.Form.NFC);
    10731073
    1074                     if (key.indexOf(search) != -1 || value.indexOf(search) != -1)
     1074                    if (key.contains(search) || value.contains(search))
    10751075                        return true;
    10761076                }
  • trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java

    r17349 r17787  
    364364    public static JTree buildJTreeList() {
    365365        DefaultMutableTreeNode root = new DefaultMutableTreeNode(tr("Ignore list"));
    366         final Pattern elemId1Pattern = Pattern.compile(":(r|w|n)_");
     366        final Pattern elemId1Pattern = Pattern.compile(":([rwn])_");
    367367        final Pattern elemId2Pattern = Pattern.compile("^[0-9]+$");
    368368        for (Entry<String, String> e: ignoredErrors.entrySet()) {
     
    464464                String item = child.getUserObject().toString();
    465465                String entry = null;
    466                 if (item.matches("^\\[(r|w|n)_.*")) {
     466                if (item.matches("^\\[([rwn])_.*")) {
    467467                    // list of elements (produced with list.toString() method)
    468468                    entry = key + ":" + item.substring(1, item.lastIndexOf(']')).replace(", ", ":");
    469                 } else if (item.matches("^(r|w|n)_.*")) {
     469                } else if (item.matches("^([rwn])_.*")) {
    470470                    // single element
    471471                    entry = key + ":" + item;
  • trunk/src/org/openstreetmap/josm/data/validation/tests/Addresses.java

    r16829 r17787  
    269269     */
    270270    static List<String> expandHouseNumber(String houseNumber) {
    271         return Arrays.asList(houseNumber.split(",|;", -1));
     271        return Arrays.asList(houseNumber.split("[,;]", -1));
    272272    }
    273273
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/HeadersTable.java

    r16953 r17787  
    55
    66import java.awt.GridBagLayout;
    7 import java.util.Comparator;
    87import java.util.List;
    98import java.util.Map;
     
    107106
    108107    private static List<String[]> getHeadersAsVector(Map<String, String> headers) {
    109         return headers.entrySet().stream().sorted(Comparator.comparing(Map.Entry::getKey))
     108        return headers.entrySet().stream().sorted(Map.Entry.comparingByKey())
    110109                .map(e -> new String[] {e.getKey(), e.getValue()}).collect(Collectors.toList());
    111110    }
  • trunk/src/org/openstreetmap/josm/gui/preferences/shortcut/PrefJPanel.java

    r17768 r17787  
    107107            }
    108108        }
    109         KeyboardUtils.getExtendedKeyCodes(InputContext.getInstance().getLocale()).entrySet()
    110             .forEach(e -> list.put(e.getKey(), e.getValue().toString()));
     109        KeyboardUtils.getExtendedKeyCodes(InputContext.getInstance().getLocale())
     110                .forEach((key, value) -> list.put(key, value.toString()));
    111111        list.put(Integer.valueOf(-1), "");
    112112        return list;
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetItem.java

    r17651 r17787  
    8989            return TYPE_CACHE.get(types);
    9090        Set<TaggingPresetType> result = EnumSet.noneOf(TaggingPresetType.class);
    91         for (String type : Arrays.asList(types.split(",", -1))) {
     91        for (String type : types.split(",", -1)) {
    9292            try {
    9393                TaggingPresetType presetType = TaggingPresetType.fromString(type);
  • trunk/src/org/openstreetmap/josm/io/CachedFile.java

    r16841 r17787  
    353353                ZipEntry entry = entries.nextElement();
    354354                // choose any file with correct extension. When more than one file, prefer the one which matches namepart
    355                 if (entry.getName().endsWith('.' + extension) && (resentry == null || entry.getName().indexOf(namepart) >= 0)) {
     355                if (entry.getName().endsWith('.' + extension) && (resentry == null || entry.getName().contains(namepart))) {
    356356                    resentry = entry;
    357357                }
  • trunk/src/org/openstreetmap/josm/io/GpxWriter.java

    r17725 r17787  
    1212import java.util.ArrayList;
    1313import java.util.Collection;
    14 import java.util.Comparator;
    1514import java.util.Date;
    1615import java.util.List;
     
    9897            data.getLayerPrefs().entrySet()
    9998            .stream()
    100             .sorted(Comparator.comparing(Map.Entry::getKey))
     99            .sorted(Map.Entry.comparingByKey())
    101100            .forEach(entry -> {
    102101                GpxExtension e = layerExts.add("josm", "entry");
  • trunk/src/org/openstreetmap/josm/io/InvalidXmlCharacterFilter.java

    r12620 r17787  
    44import java.io.IOException;
    55import java.io.Reader;
     6import java.util.Arrays;
    67
    78import org.openstreetmap.josm.tools.Logging;
     
    2829    static {
    2930        INVALID_CHARS = new boolean[0x20];
    30         for (int i = 0; i < INVALID_CHARS.length; ++i) {
    31             INVALID_CHARS[i] = true;
    32         }
     31        Arrays.fill(INVALID_CHARS, true);
    3332        INVALID_CHARS[0x9] = false; // tab
    3433        INVALID_CHARS[0xA] = false; // LF
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r17760 r17787  
    319319    }
    320320
    321     protected static final Comparator<Entry<String, String>> byKeyComparator = Comparator.comparing(Entry::getKey);
     321    protected static final Comparator<Entry<String, String>> byKeyComparator = Entry.comparingByKey();
    322322
    323323    protected void addTags(Tagged osm, String tagname, boolean tagOpen) {
  • trunk/src/org/openstreetmap/josm/io/OverpassDownloadReader.java

    r17333 r17787  
    271271        }
    272272        if (javaDur) {
    273             d = Duration.parse(javaPer ? 'P' + duration.substring(idx, duration.length()) : duration);
     273            d = Duration.parse(javaPer ? 'P' + duration.substring(idx) : duration);
    274274        } else if (!javaPer) {
    275275            d = Duration.parse(duration);
  • trunk/src/org/openstreetmap/josm/io/rtklib/RtkLibPosReader.java

    r17786 r17787  
    7878        Collection<WayPoint> waypoints = new ArrayList<>();
    7979        try (BufferedReader rd = new BufferedReader(new InputStreamReader(source, StandardCharsets.UTF_8))) {
    80             String line = null;
     80            String line;
    8181            do {
    8282                line = rd.readLine();
  • trunk/src/org/openstreetmap/josm/tools/LanguageInfo.java

    r16873 r17787  
    6666                }
    6767            }
    68             if ("nb".equals(code)) { /* OSM-Wiki has "no", but no "nb" */
    69                 return "No:";
    70             } else if ("sr@latin".equals(code)) { /* OSM-Wiki has "Sr-latn" and not Sr-latin */
    71                 return "Sr-latn:";
    72             } else if ("de".equals(code) || "es".equals(code) || "fr".equals(code)
    73                     || "it".equals(code) || "nl".equals(code) || "ru".equals(code)
    74                     || "ja".equals(code)) {
    75                 return code.toUpperCase(Locale.ENGLISH) + ":";
    76             } else {
    77                 return code.substring(0, 1).toUpperCase(Locale.ENGLISH) + code.substring(1) + ":";
     68            switch (code) {
     69                case "nb":          /* OSM-Wiki has "no", but no "nb" */
     70                    return "No:";
     71                case "sr@latin":    /* OSM-Wiki has "Sr-latn" and not Sr-latin */
     72                    return "Sr-latn:";
     73                case "de":
     74                case "es":
     75                case "fr":
     76                case "it":
     77                case "nl":
     78                case "ru":
     79                case "ja":
     80                    return code.toUpperCase(Locale.ENGLISH) + ":";
     81                default:
     82                    return code.substring(0, 1).toUpperCase(Locale.ENGLISH) + code.substring(1) + ":";
    7883            }
    7984        }
     
    160165    public static String getJavaLocaleCode(String localeName) {
    161166        if (localeName == null) return "en";
    162         if ("ca@valencia".equals(localeName)) {
    163             localeName = "ca__valencia";
    164         } else if ("sr@latin".equals(localeName)) {
    165             localeName = "sr__latin";
    166         } else if ("he".equals(localeName)) {
    167             localeName = "iw_IL";
    168         } else if ("id".equals(localeName)) {
    169             localeName = "in";
     167        switch (localeName) {
     168            case "ca@valencia":
     169                return "ca__valencia";
     170            case "sr@latin":
     171                return "sr__latin";
     172            case "he":
     173                return "iw_IL";
     174            case "id":
     175                return "in";
    170176        }
    171177        return localeName;
Note: See TracChangeset for help on using the changeset viewer.