Changeset 19101 in josm


Ignore:
Timestamp:
2024-06-11T23:53:20+02:00 (5 months ago)
Author:
taylor.smock
Message:

Cleanup some new PMD warnings from PMD 7.x

I haven't updated to PMD 7.x in ivy/maven yet since I still have 83 PMD violations
to go through, and I don't know (yet) if any of them were supposed to be ignored
by the xpath expressions in tools/pmd/josm-ruleset.xml.

I may re-enable some of the PMD checks I've temporarily disabled prior to committing
the update for PMD.

Additionally cleanup some SonarLint issues in the modified files.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/MultipolygonBuilder.java

    r17358 r19101  
    7171                Way way = this.ways.get(waypos);
    7272
    73                 if (!this.reversed.get(waypos)) {
     73                if (Boolean.FALSE.equals(this.reversed.get(waypos))) {
    7474                    for (int pos = 0; pos < way.getNodesCount() - 1; pos++) {
    7575                        ringNodes.add(way.getNode(pos));
     
    212212                //add cur way to the list
    213213                collectedWays.add(curWay);
    214                 collectedWaysReverse.add(Boolean.valueOf(curWayReverse));
     214                collectedWaysReverse.add(curWayReverse);
    215215
    216216                if (nextNode == startNode) {
  • trunk/src/org/openstreetmap/josm/gui/datatransfer/importers/PrimitiveDataPaster.java

    r16438 r19101  
    9292            List<PrimitiveData> bufferCopy, List<PrimitiveData> toSelect) {
    9393        EnumMap<OsmPrimitiveType, Map<Long, Long>> newIds = new EnumMap<>(OsmPrimitiveType.class);
    94         newIds.put(OsmPrimitiveType.NODE, new HashMap<Long, Long>());
    95         newIds.put(OsmPrimitiveType.WAY, new HashMap<Long, Long>());
    96         newIds.put(OsmPrimitiveType.RELATION, new HashMap<Long, Long>());
     94        newIds.put(OsmPrimitiveType.NODE, new HashMap<>());
     95        newIds.put(OsmPrimitiveType.WAY, new HashMap<>());
     96        newIds.put(OsmPrimitiveType.RELATION, new HashMap<>());
    9797
    9898        for (PrimitiveData data : pasteBuffer.getAll()) {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r19050 r19101  
    22package org.openstreetmap.josm.gui.dialogs;
    33
     4import static org.openstreetmap.josm.tools.I18n.marktr;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56import static org.openstreetmap.josm.tools.I18n.trn;
     
    9495 */
    9596public class SelectionListDialog extends ToggleDialog {
     97    private static final String SELECTION_CASING = marktr("Selection");
     98    private static final String SELECTION = "selection";
    9699    private JList<OsmPrimitive> lstPrimitives;
    97100    private final DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
     
    147150     */
    148151    public SelectionListDialog() {
    149         super(tr("Selection"), "selectionlist", tr("Open a selection list window."),
     152        super(tr(SELECTION_CASING), "selectionlist", tr("Open a selection list window."),
    150153                Shortcut.registerShortcut("subwindow:selection", tr("Windows: {0}",
    151                 tr("Selection")), KeyEvent.VK_T, Shortcut.ALT_SHIFT),
     154                tr(SELECTION_CASING)), KeyEvent.VK_T, Shortcut.ALT_SHIFT),
    152155                150, // default height
    153156                true // default is "show dialog"
     
    395398            putValue(NAME, tr("Zoom to selection"));
    396399            putValue(SHORT_DESCRIPTION, tr("Zoom to selection"));
    397             new ImageProvider("dialogs/autoscale", "selection").getResource().attachImageIcon(this, true);
     400            new ImageProvider("dialogs/autoscale", SELECTION).getResource().attachImageIcon(this, true);
    398401            updateEnabledState();
    399402        }
     
    434437         */
    435438        ZoomToListSelection() {
    436             new ImageProvider("dialogs/autoscale", "selection").getResource().attachImageIcon(this, true);
     439            new ImageProvider("dialogs/autoscale", SELECTION).getResource().attachImageIcon(this, true);
    437440            updateEnabledState();
    438441        }
     
    464467    /**
    465468     * The list model for the list of OSM primitives in the current JOSM selection.
    466      *
     469     * <p>
    467470     * The model also maintains a history of the last {@link SelectionListModel#SELECTION_HISTORY_SIZE}
    468471     * JOSM selection.
     
    493496         */
    494497        public synchronized String getJOSMSelectionSummary() {
    495             if (selection.isEmpty()) return tr("Selection");
     498            if (selection.isEmpty()) return tr(SELECTION_CASING);
    496499            int numNodes = 0;
    497500            int numWays = 0;
     
    650653                            : OsmPrimitiveComparator.comparingNames()));
    651654                } catch (IllegalArgumentException e) {
    652                     throw BugReport.intercept(e).put("size", size).put("quick", quick).put("selection", selection);
     655                    throw BugReport.intercept(e).put("size", size).put("quick", quick).put(SELECTION, selection);
    653656                }
    654657            }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/BooleanStyleSettingGui.java

    r15293 r19101  
    33
    44import java.awt.event.ActionEvent;
    5 import java.util.Arrays;
     5import java.util.Collections;
    66import java.util.Objects;
    77
     
    4040                    setting.setValue(isSelected());
    4141                    if (!noRepaint) {
    42                         MainApplication.worker.submit(new MapPaintStyleLoader(Arrays.asList(setting.parentStyle)));
     42                        MainApplication.worker.submit(new MapPaintStyleLoader(Collections.singletonList(setting.parentStyle)));
    4343                    }
    4444                }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSettingGroupGui.java

    r17270 r19101  
    66import java.awt.event.ActionEvent;
    77import java.util.Arrays;
     8import java.util.Collections;
    89import java.util.List;
    910import java.util.Objects;
     
    5253                public void actionPerformed(ActionEvent e) {
    5354                    List<BooleanStyleSettingCheckBoxMenuItem> items = Arrays.stream(submenu.getMenuComponents())
    54                             .filter(c -> c instanceof BooleanStyleSettingCheckBoxMenuItem)
     55                            .filter(BooleanStyleSettingCheckBoxMenuItem.class::isInstance)
    5556                            .map(c -> (BooleanStyleSettingCheckBoxMenuItem) c)
    5657                            .collect(Collectors.toList());
    5758                    final boolean select = items.stream().anyMatch(cbi -> !cbi.isSelected());
    5859                    items.stream().filter(cbi -> select != cbi.isSelected()).forEach(cbi -> cbi.doClickWithoutRepaint(0));
    59                     MainApplication.worker.submit(new MapPaintStyleLoader(Arrays.asList(group.parentStyle)));
     60                    MainApplication.worker.submit(new MapPaintStyleLoader(Collections.singletonList(group.parentStyle)));
    6061                }
    6162            });
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/LabelCompositionStrategy.java

    r19080 r19101  
    169169        /* Is joining an array really that complicated in Java? */
    170170        private static String[] getDefaultNameTags() {
    171             final var tags = new ArrayList<>(Arrays.asList(LanguageInfo.getOSMLocaleCodes("name:")));
     171            final ArrayList<String> tags = new ArrayList<>(Arrays.asList(LanguageInfo.getOSMLocaleCodes("name:")));
    172172            tags.addAll(Arrays.asList("name",
    173173                    "int_name",
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r19080 r19101  
    5959import javax.swing.KeyStroke;
    6060import javax.swing.ListSelectionModel;
     61import javax.swing.SwingConstants;
    6162import javax.swing.UIManager;
    6263import javax.swing.event.CellEditorListener;
     
    112113 */
    113114public abstract class SourceEditor extends JPanel {
     115    private static final String DELETE = "delete";
     116    private static final String DIALOGS = "dialogs";
    114117
    115118    /** the type of source entry **/
     
    219222        RemoveActiveSourcesAction removeActiveSourcesAction = new RemoveActiveSourcesAction();
    220223        tblActiveSources.getSelectionModel().addListSelectionListener(removeActiveSourcesAction);
    221         tblActiveSources.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "delete");
    222         tblActiveSources.getActionMap().put("delete", removeActiveSourcesAction);
     224        tblActiveSources.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DELETE);
     225        tblActiveSources.getActionMap().put(DELETE, removeActiveSourcesAction);
    223226
    224227        MoveUpDownAction moveUp = null;
     
    297300        gbc.insets = new Insets(0, 0, 0, 6);
    298301
    299         JToolBar sideButtonTB = new JToolBar(JToolBar.VERTICAL);
     302        JToolBar sideButtonTB = new JToolBar(SwingConstants.VERTICAL);
    300303        sideButtonTB.setFloatable(false);
    301304        sideButtonTB.setBorderPainted(false);
     
    363366        RemoveIconPathAction removeIconPathAction = new RemoveIconPathAction();
    364367        tblIconPaths.getSelectionModel().addListSelectionListener(removeIconPathAction);
    365         tblIconPaths.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "delete");
    366         tblIconPaths.getActionMap().put("delete", removeIconPathAction);
     368        tblIconPaths.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DELETE);
     369        tblIconPaths.getActionMap().put(DELETE, removeIconPathAction);
    367370
    368371        gbc.gridx = 0;
     
    721724            data = IntStream.range(0, data.size())
    722725                    .filter(i -> !idxs.contains(i))
    723                     .mapToObj(i -> data.get(i))
     726                    .mapToObj(data::get)
    724727                    .collect(Collectors.toList());
    725728            fireTableDataChanged();
     
    909912            putValue(NAME, tr("New"));
    910913            putValue(SHORT_DESCRIPTION, getStr(I18nString.NEW_SOURCE_ENTRY_TOOLTIP));
    911             new ImageProvider("dialogs", "add").getResource().attachImageIcon(this);
     914            new ImageProvider(DIALOGS, "add").getResource().attachImageIcon(this);
    912915        }
    913916
     
    939942            putValue(NAME, tr("Remove"));
    940943            putValue(SHORT_DESCRIPTION, getStr(I18nString.REMOVE_SOURCE_TOOLTIP));
    941             new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this);
     944            new ImageProvider(DIALOGS, DELETE).getResource().attachImageIcon(this);
    942945            updateEnabledState();
    943946        }
     
    962965            putValue(NAME, tr("Edit"));
    963966            putValue(SHORT_DESCRIPTION, getStr(I18nString.EDIT_SOURCE_TOOLTIP));
    964             new ImageProvider("dialogs", "edit").getResource().attachImageIcon(this);
     967            new ImageProvider(DIALOGS, "edit").getResource().attachImageIcon(this);
    965968            updateEnabledState();
    966969        }
     
    10081011        MoveUpDownAction(boolean isDown) {
    10091012            increment = isDown ? 1 : -1;
    1010             new ImageProvider("dialogs", isDown ? "down" : "up").getResource().attachImageIcon(this, true);
     1013            new ImageProvider(DIALOGS, isDown ? "down" : "up").getResource().attachImageIcon(this, true);
    10111014            putValue(SHORT_DESCRIPTION, isDown ? tr("Move the selected entry one row down.") : tr("Move the selected entry one row up."));
    10121015            updateEnabledState();
     
    11101113            putValue(NAME, tr("Reload"));
    11111114            putValue(SHORT_DESCRIPTION, tr(getStr(I18nString.RELOAD_ALL_AVAILABLE), url));
    1112             new ImageProvider("dialogs", "refresh").getResource().attachImageIcon(this);
     1115            new ImageProvider(DIALOGS, "refresh").getResource().attachImageIcon(this);
    11131116            this.url = url;
    11141117            this.sourceProviders = sourceProviders;
     
    12521255            putValue(NAME, tr("New"));
    12531256            putValue(SHORT_DESCRIPTION, tr("Add a new icon path"));
    1254             new ImageProvider("dialogs", "add").getResource().attachImageIcon(this);
     1257            new ImageProvider(DIALOGS, "add").getResource().attachImageIcon(this);
    12551258        }
    12561259
     
    12661269            putValue(NAME, tr("Remove"));
    12671270            putValue(SHORT_DESCRIPTION, tr("Remove the selected icon paths"));
    1268             new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this);
     1271            new ImageProvider(DIALOGS, DELETE).getResource().attachImageIcon(this);
    12691272            updateEnabledState();
    12701273        }
     
    12891292            putValue(NAME, tr("Edit"));
    12901293            putValue(SHORT_DESCRIPTION, tr("Edit the selected icon path"));
    1291             new ImageProvider("dialogs", "edit").getResource().attachImageIcon(this);
     1294            new ImageProvider(DIALOGS, "edit").getResource().attachImageIcon(this);
    12921295            updateEnabledState();
    12931296        }
     
    16081611        public void setInitialValue(String initialValue) {
    16091612            this.value = initialValue;
    1610             if (initialValue == null) {
    1611                 this.tfFileName.setText("");
    1612             } else {
    1613                 this.tfFileName.setText(initialValue);
    1614             }
     1613            this.tfFileName.setText(Objects.requireNonNullElse(initialValue, ""));
    16151614        }
    16161615
  • trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java

    r19050 r19101  
    9898
    9999    private static final String EMPTY_TOOLBAR_MARKER = "<!-empty-!>";
     100    private static final String TOOLBAR = "toolbar";
     101    private static final String DIALOGS = "dialogs";
    100102
    101103    /**
     
    363365            result.setLength(0);
    364366
    365             String val = (String) action.getAction().getValue("toolbar");
     367            String val = (String) action.getAction().getValue(TOOLBAR);
    366368            if (val == null)
    367369                return null;
     
    395397                tmp = action.getIcon();
    396398                if (!tmp.isEmpty()) {
    397                     result.append(first ? "{" : ",");
    398                     result.append("icon=");
     399                    result.append(first ? "{" : ",")
     400                            .append("icon=");
    399401                    escape(tmp);
    400402                    first = false;
     
    513515                // remove the button from toolbar preferences
    514516                t.remove(res);
    515                 Config.getPref().putList("toolbar", t);
     517                Config.getPref().putList(TOOLBAR, t);
    516518                MainApplication.getToolbar().refreshToolbarControl();
    517519            }
     
    522524            public void actionPerformed(ActionEvent e) {
    523525                final PreferenceDialog p = new PreferenceDialog(MainApplication.getMainFrame());
    524                 SwingUtilities.invokeLater(() -> p.selectPreferencesTabByName("toolbar"));
     526                SwingUtilities.invokeLater(() -> p.selectPreferencesTabByName(TOOLBAR));
    525527                p.setVisible(true);
    526528            }
     
    796798         */
    797799        public Settings(DefaultMutableTreeNode rootActionsNode) {
    798             super(/* ICON(preferences/) */ "toolbar", tr("Toolbar"), tr("Customize the elements on the toolbar."));
     800            super(/* ICON(preferences/) */ TOOLBAR, tr("Toolbar"), tr("Customize the elements on the toolbar."));
    799801            actionsTreeModel = new DefaultTreeModel(rootActionsNode);
    800802            actionsTree = new JTree(actionsTreeModel);
     
    805807            switch (name) {
    806808                case "up":
    807                     b.setIcon(ImageProvider.get("dialogs", "up", ImageSizes.LARGEICON));
     809                    b.setIcon(ImageProvider.get(DIALOGS, "up", ImageSizes.LARGEICON));
    808810                    b.setToolTipText(tr("Move the currently selected members up"));
    809811                    break;
    810812                case "down":
    811                     b.setIcon(ImageProvider.get("dialogs", "down", ImageSizes.LARGEICON));
     813                    b.setIcon(ImageProvider.get(DIALOGS, "down", ImageSizes.LARGEICON));
    812814                    b.setToolTipText(tr("Move the currently selected members down"));
    813815                    break;
     
    817819                    break;
    818820                case ">":
    819                     b.setIcon(ImageProvider.get("dialogs", "delete", ImageSizes.LARGEICON));
     821                    b.setIcon(ImageProvider.get(DIALOGS, "delete", ImageSizes.LARGEICON));
    820822                    b.setToolTipText(tr("Remove"));
    821823                    break;
     
    10141016                t = Collections.singletonList(EMPTY_TOOLBAR_MARKER);
    10151017            }
    1016             Config.getPref().putList("toolbar", t);
     1018            Config.getPref().putList(TOOLBAR, t);
    10171019            MainApplication.getToolbar().refreshToolbarControl();
    10181020            return false;
     
    10501052                    Action action = menuItem.getAction();
    10511053                    userObject = action;
    1052                     Object tb = action.getValue("toolbar");
     1054                    Object tb = action.getValue(TOOLBAR);
    10531055                    if (tb == null) {
    10541056                        Logging.info(tr("Toolbar action without name: {0}",
     
    11011103
    11021104    public static Collection<String> getToolString() {
    1103         Collection<String> toolStr = Config.getPref().getList("toolbar", Arrays.asList(deftoolbar));
     1105        Collection<String> toolStr = Config.getPref().getList(TOOLBAR, Arrays.asList(deftoolbar));
    11041106        if (Utils.isEmpty(toolStr)) {
    11051107            toolStr = Arrays.asList(deftoolbar);
     
    11411143     */
    11421144    public Action register(Action action) {
    1143         String toolbar = (String) action.getValue("toolbar");
     1145        String toolbar = (String) action.getValue(TOOLBAR);
    11441146        if (toolbar == null) {
    11451147            Logging.info(tr("Registered toolbar action without name: {0}",
     
    11651167     */
    11661168    public Action unregister(Action action) {
    1167         Object toolbar = action.getValue("toolbar");
     1169        Object toolbar = action.getValue(TOOLBAR);
    11681170        if (toolbar instanceof String) {
    11691171            return regactions.remove(toolbar);
     
    12431245            }
    12441246        }
    1245         Config.getPref().putList("toolbar", t);
     1247        Config.getPref().putList(TOOLBAR, t);
    12461248        MainApplication.getToolbar().refreshToolbarControl();
    12471249    }
     
    12731275
    12741276        if (sc == null || paramCode != 0) {
    1275             String name = Optional.ofNullable((String) action.getAction().getValue("toolbar")).orElseGet(action::getDisplayName);
     1277            String name = Optional.ofNullable((String) action.getAction().getValue(TOOLBAR)).orElseGet(action::getDisplayName);
    12761278            if (paramCode != 0) {
    12771279                name = name+paramCode;
  • trunk/src/org/openstreetmap/josm/gui/preferences/shortcut/PrefJPanel.java

    r18801 r19101  
    1111import java.awt.GridLayout;
    1212import java.awt.Toolkit;
     13import java.awt.event.InputEvent;
    1314import java.awt.event.KeyEvent;
    1415import java.awt.im.InputContext;
     
    5657    // independent from the keyboard's labelling. But the operation system's locale
    5758    // usually matches the keyboard. This even works with my English Windows and my German keyboard.
    58     private static final String SHIFT = KeyEvent.getModifiersExText(KeyStroke.getKeyStroke(KeyEvent.VK_A,
    59             KeyEvent.SHIFT_DOWN_MASK).getModifiers());
    60     private static final String CTRL = KeyEvent.getModifiersExText(KeyStroke.getKeyStroke(KeyEvent.VK_A,
    61             KeyEvent.CTRL_DOWN_MASK).getModifiers());
    62     private static final String ALT = KeyEvent.getModifiersExText(KeyStroke.getKeyStroke(KeyEvent.VK_A,
    63             KeyEvent.ALT_DOWN_MASK).getModifiers());
    64     private static final String META = KeyEvent.getModifiersExText(KeyStroke.getKeyStroke(KeyEvent.VK_A,
    65             KeyEvent.META_DOWN_MASK).getModifiers());
     59    private static final String SHIFT = InputEvent.getModifiersExText(KeyStroke.getKeyStroke(KeyEvent.VK_A,
     60            InputEvent.SHIFT_DOWN_MASK).getModifiers());
     61    private static final String CTRL = InputEvent.getModifiersExText(KeyStroke.getKeyStroke(KeyEvent.VK_A,
     62            InputEvent.CTRL_DOWN_MASK).getModifiers());
     63    private static final String ALT = InputEvent.getModifiersExText(KeyStroke.getKeyStroke(KeyEvent.VK_A,
     64            InputEvent.ALT_DOWN_MASK).getModifiers());
     65    private static final String META = InputEvent.getModifiersExText(KeyStroke.getKeyStroke(KeyEvent.VK_A,
     66            InputEvent.META_DOWN_MASK).getModifiers());
    6667
    6768    // A list of keys to present the user. Sadly this really is a list of keys Java knows about,
     
    9798                    int i = field.getInt(null);
    9899                    String s = KeyEvent.getKeyText(i);
    99                     if (s != null && !s.isEmpty() && !s.contains(unknown)) {
    100                         list.put(Integer.valueOf(i), s);
     100                    if (!s.isEmpty() && !s.contains(unknown)) {
     101                        list.put(i, s);
    101102                    }
    102103                } catch (IllegalArgumentException | IllegalAccessException e) {
     
    107108        KeyboardUtils.getExtendedKeyCodes(InputContext.getInstance().getLocale())
    108109                .forEach((key, value) -> list.put(key, value.toString()));
    109         list.put(Integer.valueOf(-1), "");
     110        list.put(-1, "");
    110111
    111112        // Remove "look-alike" values. See JOSM #22020 comment 2. These override the standard left/right/up/down keys.
     
    292293                panel.cbDefault.setSelected(!sc.isAssignedUser());
    293294                panel.cbDisable.setSelected(sc.getKeyStroke() == null);
    294                 panel.cbShift.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.SHIFT_DOWN_MASK) != 0);
    295                 panel.cbCtrl.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.CTRL_DOWN_MASK) != 0);
    296                 panel.cbAlt.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.ALT_DOWN_MASK) != 0);
    297                 panel.cbMeta.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.META_DOWN_MASK) != 0);
     295                panel.cbShift.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & InputEvent.SHIFT_DOWN_MASK) != 0);
     296                panel.cbCtrl.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & InputEvent.CTRL_DOWN_MASK) != 0);
     297                panel.cbAlt.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & InputEvent.ALT_DOWN_MASK) != 0);
     298                panel.cbMeta.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & InputEvent.META_DOWN_MASK) != 0);
    298299                if (sc.getKeyStroke() != null) {
    299300                    panel.tfKey.setSelectedItem(keyList.get(sc.getKeyStroke().getKeyCode()));
     
    329330                    } else {
    330331                        sc.setAssignedModifier(
    331                                 (panel.cbShift.isSelected() ? KeyEvent.SHIFT_DOWN_MASK : 0) |
    332                                 (panel.cbCtrl.isSelected() ? KeyEvent.CTRL_DOWN_MASK : 0) |
    333                                 (panel.cbAlt.isSelected() ? KeyEvent.ALT_DOWN_MASK : 0) |
    334                                 (panel.cbMeta.isSelected() ? KeyEvent.META_DOWN_MASK : 0)
     332                                (panel.cbShift.isSelected() ? InputEvent.SHIFT_DOWN_MASK : 0) |
     333                                (panel.cbCtrl.isSelected() ? InputEvent.CTRL_DOWN_MASK : 0) |
     334                                (panel.cbAlt.isSelected() ? InputEvent.ALT_DOWN_MASK : 0) |
     335                                (panel.cbMeta.isSelected() ? InputEvent.META_DOWN_MASK : 0)
    335336                        );
    336337                        for (Map.Entry<Integer, String> entry : keyList.entrySet()) {
  • trunk/src/org/openstreetmap/josm/io/OnlineResource.java

    r18014 r19101  
    3636     * @return the localized name
    3737     */
    38     public final String getLocName() {
     38    public String getLocName() {
    3939        return locName;
    4040    }
     
    4545     * @since 17041
    4646     */
    47     public final String getOfflineIcon() {
     47    public String getOfflineIcon() {
    4848        switch (this) {
    4949            case OSM_API:
     
    6767     * @return whether the given URL matches this online resource
    6868     */
    69     public final boolean matches(String url) {
     69    public boolean matches(String url) {
    7070        final String baseUrl;
    7171        switch (this) {
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r19050 r19101  
    22package org.openstreetmap.josm.io;
    33
     4import static org.openstreetmap.josm.tools.I18n.marktr;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56import static org.openstreetmap.josm.tools.I18n.trn;
     
    6465 */
    6566public class OsmApi extends OsmConnection {
     67    private static final String CHANGESET_STR = "changeset";
     68    private static final String CHANGESET_SLASH = "changeset/";
     69    private static final String ERROR_MESSAGE = marktr("Changeset ID > 0 expected. Got {0}.");
    6670
    6771    /**
     
    465469     */
    466470    public void openChangeset(Changeset changeset, ProgressMonitor progressMonitor) throws OsmTransferException {
    467         CheckParameterUtil.ensureParameterNotNull(changeset, "changeset");
     471        CheckParameterUtil.ensureParameterNotNull(changeset, CHANGESET_STR);
    468472        try {
    469473            progressMonitor.beginTask(tr("Creating changeset..."));
     
    496500     */
    497501    public void updateChangeset(Changeset changeset, ProgressMonitor monitor) throws OsmTransferException {
    498         CheckParameterUtil.ensureParameterNotNull(changeset, "changeset");
     502        CheckParameterUtil.ensureParameterNotNull(changeset, CHANGESET_STR);
    499503        if (monitor == null) {
    500504            monitor = NullProgressMonitor.INSTANCE;
    501505        }
    502506        if (changeset.getId() <= 0)
    503             throw new IllegalArgumentException(tr("Changeset ID > 0 expected. Got {0}.", changeset.getId()));
     507            throw new IllegalArgumentException(tr(ERROR_MESSAGE, changeset.getId()));
    504508        try {
    505509            monitor.beginTask(tr("Updating changeset..."));
    506510            initialize(monitor);
    507511            monitor.setCustomText(tr("Updating changeset {0}...", changeset.getId()));
    508             sendPutRequest("changeset/" + changeset.getId(), toXml(changeset), monitor);
     512            sendPutRequest(CHANGESET_SLASH + changeset.getId(), toXml(changeset), monitor);
    509513        } catch (ChangesetClosedException e) {
    510514            e.setSource(ChangesetClosedException.Source.UPDATE_CHANGESET);
     
    531535     */
    532536    public void closeChangeset(Changeset changeset, ProgressMonitor monitor) throws OsmTransferException {
    533         CheckParameterUtil.ensureParameterNotNull(changeset, "changeset");
     537        CheckParameterUtil.ensureParameterNotNull(changeset, CHANGESET_STR);
    534538        if (monitor == null) {
    535539            monitor = NullProgressMonitor.INSTANCE;
    536540        }
    537541        if (changeset.getId() <= 0)
    538             throw new IllegalArgumentException(tr("Changeset ID > 0 expected. Got {0}.", changeset.getId()));
     542            throw new IllegalArgumentException(tr(ERROR_MESSAGE, changeset.getId()));
    539543        try {
    540544            monitor.beginTask(tr("Closing changeset..."));
    541545            initialize(monitor);
    542546            // send "\r\n" instead of empty string, so we don't send zero payload - workaround bugs in proxy software
    543             sendPutRequest("changeset/" + changeset.getId() + "/close", "\r\n", monitor);
     547            sendPutRequest(CHANGESET_SLASH + changeset.getId() + "/close", "\r\n", monitor);
    544548        } catch (ChangesetClosedException e) {
    545549            e.setSource(ChangesetClosedException.Source.CLOSE_CHANGESET);
     
    565569            throw new IllegalArgumentException(tr("Changeset must be closed in order to add a comment"));
    566570        else if (changeset.getId() <= 0)
    567             throw new IllegalArgumentException(tr("Changeset ID > 0 expected. Got {0}.", changeset.getId()));
    568         sendRequest("POST", "changeset/" + changeset.getId() + "/comment?text="+ Utils.encodeUrl(comment),
     571            throw new IllegalArgumentException(tr(ERROR_MESSAGE, changeset.getId()));
     572        sendRequest("POST", CHANGESET_SLASH + changeset.getId() + "/comment?text="+ Utils.encodeUrl(comment),
    569573                null, monitor, "application/x-www-form-urlencoded", true, false);
    570574    }
     
    599603            monitor.indeterminateSubTask(
    600604                    trn("Uploading {0} object...", "Uploading {0} objects...", list.size(), list.size()));
    601             String diffUploadResponse = sendPostRequest("changeset/" + changeset.getId() + "/upload", diffUploadRequest, monitor);
     605            String diffUploadResponse = sendPostRequest(CHANGESET_SLASH + changeset.getId() + "/upload", diffUploadRequest, monitor);
    602606
    603607            // Process the response from the server
     
    893897        }
    894898        if (changeset.getId() <= 0)
    895             throw new IllegalArgumentException(tr("Changeset ID > 0 expected. Got {0}.", changeset.getId()));
     899            throw new IllegalArgumentException(tr(ERROR_MESSAGE, changeset.getId()));
    896900        if (!changeset.isOpen())
    897901            throw new IllegalArgumentException(tr("Open changeset expected. Got closed changeset with id {0}.", changeset.getId()));
     
    954958            .append("/close");
    955959        if (!encodedMessage.trim().isEmpty()) {
    956             urlBuilder.append("?text=");
    957             urlBuilder.append(encodedMessage);
     960            urlBuilder.append("?text=")
     961                    .append(encodedMessage);
    958962        }
    959963
     
    975979            .append("/reopen");
    976980        if (!encodedMessage.trim().isEmpty()) {
    977             urlBuilder.append("?text=");
    978             urlBuilder.append(encodedMessage);
     981            urlBuilder.append("?text=")
     982                    .append(encodedMessage);
    979983        }
    980984
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/AddTagsDialog.java

    r16960 r19101  
    99import java.awt.GridBagLayout;
    1010import java.awt.event.ActionEvent;
     11import java.awt.event.InputEvent;
    1112import java.awt.event.KeyEvent;
    1213import java.awt.event.MouseEvent;
     
    9899        int addValue(String val) {
    99100            Integer c = valueCount.get(val);
    100             int r = c == null ? 1 : (c.intValue()+1);
     101            int r = c == null ? 1 : (c + 1);
    101102            valueCount.put(val, r);
    102103            return r;
     
    138139            count[i] = 0;
    139140            String key = tags[i][0];
    140             String value = tags[i][1], oldValue;
    141             Boolean b = Boolean.TRUE;
     141            String value = tags[i][1];
     142            String oldValue;
     143            boolean b = Boolean.TRUE;
    142144            ExistingValues old = new ExistingValues(key);
    143145            for (OsmPrimitive osm : sel) {
     
    204206        // get edit results if the table looses the focus, for example if a user clicks "add tags"
    205207        propertyTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    206         propertyTable.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_DOWN_MASK), "shiftenter");
     208        propertyTable.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK), "shiftenter");
    207209        propertyTable.getActionMap().put("shiftenter", new AbstractAction() {
    208210            @Override public void actionPerformed(ActionEvent e) {
     
    242244            TableModel tm = propertyTable.getModel();
    243245            for (int i = 0; i < tm.getRowCount(); i++) {
    244                 if (buttonIndex == 1 || (Boolean) tm.getValueAt(i, 0)) {
     246                if (buttonIndex == 1 || Boolean.TRUE.equals(tm.getValueAt(i, 0))) {
    245247                    String key = (String) tm.getValueAt(i, 1);
    246248                    Object value = tm.getValueAt(i, 2);
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r19050 r19101  
    9090 */
    9191public final class PluginHandler {
     92    private static final String DIALOGS = "dialogs";
     93    private static final String WARNING = marktr("Warning");
     94    private static final String HTML_START = "<html>";
     95    private static final String HTML_END = "</html>";
     96    private static final String UPDATE_PLUGINS = marktr("Update plugins");
     97    private static final String CANCEL = "cancel";
     98    private static final String PLUGINS = "plugins";
     99    private static final String DISABLE_PLUGIN = marktr("Disable plugin");
     100    private static final String PLUGINMANAGER_VERSION_BASED_UPDATE_POLICY = "pluginmanager.version-based-update.policy";
     101    private static final String PLUGINMANAGER_LASTUPDATE = "pluginmanager.lastupdate";
     102    private static final String PLUGINMANAGER_TIME_BASED_UPDATE_POLICY = "pluginmanager.time-based-update.policy";
    92103
    93104    /**
     
    197208            sorted.putAll(info.attr);
    198209            for (Entry<Object, Object> e : sorted.entrySet()) {
    199                 b.append(e.getKey());
    200                 b.append(": ");
    201                 b.append(e.getValue());
    202                 b.append('\n');
     210                b.append(e.getKey())
     211                        .append(": ")
     212                        .append(e.getValue())
     213                        .append('\n');
    203214            }
    204215            return b.toString();
     
    275286     * List of unmaintained plugins. Not really up-to-date as the vast majority of plugins are not maintained after a few months, sadly...
    276287     */
    277     static final List<String> UNMAINTAINED_PLUGINS = Collections.unmodifiableList(Arrays.asList(
     288    static final List<String> UNMAINTAINED_PLUGINS = List.of(
    278289        "irsrectify", // See https://josm.openstreetmap.de/changeset/29404/osm/
    279290        "surveyor2", // See https://josm.openstreetmap.de/changeset/29404/osm/
     
    283294        "LaneConnector",           // See #11468, #11518, https://github.com/TrifanAdrian/LanecConnectorPlugin/issues/1
    284295        "Remove.redundant.points"  // See #11468, #11518, https://github.com/bularcasergiu/RemoveRedundantPoints (not even created an issue...)
    285     ));
     296    );
    286297
    287298    /**
     
    385396            if (plugins.contains(depr.name)) {
    386397                plugins.remove(depr.name);
    387                 PreferencesUtils.removeFromList(Config.getPref(), "plugins", depr.name);
     398                PreferencesUtils.removeFromList(Config.getPref(), PLUGINS, depr.name);
    388399                removedPlugins.add(depr);
    389400            }
     
    397408                parent,
    398409                getRemovedPluginsMessage(removedPlugins),
    399                 tr("Warning"),
     410                tr(WARNING),
    400411                JOptionPane.WARNING_MESSAGE
    401412        );
     
    404415    static String getRemovedPluginsMessage(Collection<DeprecatedPlugin> removedPlugins) {
    405416        StringBuilder sb = new StringBuilder(32);
    406         sb.append("<html>")
     417        sb.append(HTML_START)
    407418          .append(trn(
    408419                "The following plugin is no longer necessary and has been deactivated:",
     
    417428            sb.append("</li>");
    418429        }
    419         sb.append("</ul></html>");
     430        sb.append("</ul>").append(HTML_END);
    420431        return sb.toString();
    421432    }
     
    437448            }
    438449            if (confirmDisablePlugin(parent, getUnmaintainedPluginMessage(unmaintained), unmaintained)) {
    439                 PreferencesUtils.removeFromList(Config.getPref(), "plugins", unmaintained);
     450                PreferencesUtils.removeFromList(Config.getPref(), PLUGINS, unmaintained);
    440451                plugins.remove(unmaintained);
    441452            }
     
    470481        if (Config.getPref().getInt("pluginmanager.version", 0) < v) {
    471482            message =
    472                 "<html>"
     483                HTML_START
    473484                + tr("You updated your JOSM software.<br>"
    474485                        + "To prevent problems the plugins should be updated as well.<br><br>"
    475486                        + "Update plugins now?"
    476487                )
    477                 + "</html>";
    478             togglePreferenceKey = "pluginmanager.version-based-update.policy";
     488                + HTML_END;
     489            togglePreferenceKey = PLUGINMANAGER_VERSION_BASED_UPDATE_POLICY;
    479490        } else {
    480491            long tim = System.currentTimeMillis();
    481             long last = Config.getPref().getLong("pluginmanager.lastupdate", 0);
     492            long last = Config.getPref().getLong(PLUGINMANAGER_LASTUPDATE, 0);
    482493            int maxTime = Config.getPref().getInt("pluginmanager.time-based-update.interval", DEFAULT_TIME_BASED_UPDATE_INTERVAL);
    483494            long d = TimeUnit.MILLISECONDS.toDays(tim - last);
    484495            if ((last <= 0) || (maxTime <= 0)) {
    485                 Config.getPref().put("pluginmanager.lastupdate", Long.toString(tim));
     496                Config.getPref().put(PLUGINMANAGER_LASTUPDATE, Long.toString(tim));
    486497            } else if (d > maxTime) {
    487498                message =
    488                     "<html>"
     499                    HTML_START
    489500                    + tr("Last plugin update more than {0} days ago.", d)
    490                     + "</html>";
    491                 togglePreferenceKey = "pluginmanager.time-based-update.policy";
     501                    + HTML_END;
     502                togglePreferenceKey = PLUGINMANAGER_TIME_BASED_UPDATE_POLICY;
    492503            }
    493504        }
     
    503514        switch (policy) {
    504515        case "never":
    505             if ("pluginmanager.version-based-update.policy".equals(togglePreferenceKey)) {
     516            if (PLUGINMANAGER_VERSION_BASED_UPDATE_POLICY.equals(togglePreferenceKey)) {
    506517                Logging.info(tr("Skipping plugin update after JOSM upgrade. Automatic update at startup is disabled."));
    507             } else if ("pluginmanager.time-based-update.policy".equals(togglePreferenceKey)) {
     518            } else if (PLUGINMANAGER_TIME_BASED_UPDATE_POLICY.equals(togglePreferenceKey)) {
    508519                Logging.info(tr("Skipping plugin update after elapsed update interval. Automatic update at startup is disabled."));
    509520            }
     
    511522
    512523        case "always":
    513             if ("pluginmanager.version-based-update.policy".equals(togglePreferenceKey)) {
     524            if (PLUGINMANAGER_VERSION_BASED_UPDATE_POLICY.equals(togglePreferenceKey)) {
    514525                Logging.info(tr("Running plugin update after JOSM upgrade. Automatic update at startup is enabled."));
    515             } else if ("pluginmanager.time-based-update.policy".equals(togglePreferenceKey)) {
     526            } else if (PLUGINMANAGER_TIME_BASED_UPDATE_POLICY.equals(togglePreferenceKey)) {
    516527                Logging.info(tr("Running plugin update after elapsed update interval. Automatic update at startup is disabled."));
    517528            }
     
    527538        ButtonSpec[] options = {
    528539                new ButtonSpec(
    529                         tr("Update plugins"),
    530                         new ImageProvider("dialogs", "refresh"),
     540                        tr(UPDATE_PLUGINS),
     541                        new ImageProvider(DIALOGS, "refresh"),
    531542                        tr("Click to update the activated plugins"),
    532543                        null /* no specific help context */
     
    534545                new ButtonSpec(
    535546                        tr("Skip update"),
    536                         new ImageProvider("cancel"),
     547                        new ImageProvider(CANCEL),
    537548                        tr("Click to skip updating the activated plugins"),
    538549                        null /* no specific help context */
     
    543554                parent,
    544555                pnlMessage,
    545                 tr("Update plugins"),
     556                tr(UPDATE_PLUGINS),
    546557                JOptionPane.WARNING_MESSAGE,
    547558                null,
     
    577588    private static void alertMissingRequiredPlugin(Component parent, String plugin, Set<String> missingRequiredPlugin) {
    578589        StringBuilder sb = new StringBuilder(48);
    579         sb.append("<html>")
     590        sb.append(HTML_START)
    580591          .append(trn("Plugin {0} requires a plugin which was not found. The missing plugin is:",
    581592                "Plugin {0} requires {1} plugins which were not found. The missing plugins are:",
     
    584595                missingRequiredPlugin.size()))
    585596          .append(Utils.joinAsHtmlUnorderedList(missingRequiredPlugin))
    586           .append("</html>");
     597          .append(HTML_END);
    587598        ButtonSpec[] specs = {
    588599                new ButtonSpec(
     
    636647                    if (!task.getDownloadedPlugins().isEmpty()) {
    637648                        // update plugin list in preferences
    638                         Set<String> plugins = new HashSet<>(Config.getPref().getList("plugins"));
     649                        Set<String> plugins = new HashSet<>(Config.getPref().getList(PLUGINS));
    639650                        for (PluginInformation plugin : task.getDownloadedPlugins()) {
    640651                            plugins.add(plugin.name);
    641652                        }
    642                         Config.getPref().putList("plugins", new ArrayList<>(plugins));
     653                        Config.getPref().putList(PLUGINS, new ArrayList<>(plugins));
    643654                        // restart
    644655                        RestartAction.restartJOSM();
     
    667678        final int selected = HelpAwareOptionPane.showOptionDialog(
    668679                parent,
    669                 "<html>" + tr("Plugin {0} requires Java version {1}. The current Java version is {2}.<br>"
     680                HTML_START + tr("Plugin {0} requires Java version {1}. The current Java version is {2}.<br>"
    670681                                + "You have to update Java in order to use this plugin.",
    671682                        plugin, Integer.toString(requiredVersion), Utils.getJavaVersion()
    672                 ) + "</html>",
    673                 tr("Warning"),
     683                ) + HTML_END,
     684                tr(WARNING),
    674685                JOptionPane.WARNING_MESSAGE,
    675686                null,
     
    678689                null
    679690        );
    680         if (selected == 1) {
    681             if (Utils.isRunningJavaWebStart()) {
    682                 OpenBrowser.displayUrl(Config.getPref().get("openwebstart.download.url", "https://openwebstart.com/download/"));
    683             } else if (!Utils.isRunningWebStart()) {
    684                 final String javaUrl = PlatformManager.getPlatform().getJavaUrl();
    685                 OpenBrowser.displayUrl(javaUrl);
    686             }
     691        if (selected == 1 && !Utils.isRunningWebStart()) {
     692            final String javaUrl = PlatformManager.getPlatform().getJavaUrl();
     693            OpenBrowser.displayUrl(javaUrl);
    687694        }
    688695    }
     
    695702                        plugin, Integer.toString(requiredVersion), Version.getInstance().getVersionString()
    696703                ),
    697                 tr("Warning"),
     704                tr(WARNING),
    698705                JOptionPane.WARNING_MESSAGE,
    699706                null
     
    861868        }
    862869        if (msg != null && confirmDisablePlugin(parent, msg, plugin.name)) {
    863             PreferencesUtils.removeFromList(Config.getPref(), "plugins", plugin.name);
     870            PreferencesUtils.removeFromList(Config.getPref(), PLUGINS, plugin.name);
    864871        }
    865872    }
     
    10211028    private static void alertMissingPluginInformation(Component parent, Collection<String> plugins) {
    10221029        StringBuilder sb = new StringBuilder();
    1023         sb.append("<html>")
     1030        sb.append(HTML_START)
    10241031          .append(trn("JOSM could not find information about the following plugin:",
    10251032                "JOSM could not find information about the following plugins:",
     
    10291036                "The plugins are not going to be loaded.",
    10301037                plugins.size()))
    1031           .append("</html>");
     1038          .append(HTML_END);
    10321039        HelpAwareOptionPane.showOptionDialog(
    10331040                parent,
    10341041                sb.toString(),
    1035                 tr("Warning"),
     1042                tr(WARNING),
    10361043                JOptionPane.WARNING_MESSAGE,
    10371044                ht("/Plugin/Loading#MissingPluginInfos")
     
    10541061        try {
    10551062            monitor.beginTask(tr("Determining plugins to load..."));
    1056             Set<String> plugins = new HashSet<>(Config.getPref().getList("plugins", new LinkedList<>()));
     1063            Set<String> plugins = new HashSet<>(Config.getPref().getList(PLUGINS, new LinkedList<>()));
    10571064            Logging.debug("Plugins list initialized to {0}", plugins);
    10581065            String systemProp = Utils.getSystemProperty("josm.plugins");
     
    10881095    private static void alertFailedPluginUpdate(Component parent, Collection<PluginInformation> plugins) {
    10891096        StringBuilder sb = new StringBuilder(128);
    1090         sb.append("<html>")
     1097        sb.append(HTML_START)
    10911098          .append(trn(
    10921099                "Updating the following plugin has failed:",
     
    11021109                "Please open the Preference Dialog after JOSM has started and try to update them manually.",
    11031110                plugins.size()))
    1104           .append("</html>");
     1111          .append(HTML_END);
    11051112        HelpAwareOptionPane.showOptionDialog(
    11061113                parent,
     
    12221229                        monitor.createSubTaskMonitor(1, false),
    12231230                        pluginsToDownload,
    1224                         tr("Update plugins")
     1231                        tr(UPDATE_PLUGINS)
    12251232                        );
    12261233                future = MainApplication.worker.submit(pluginDownloadTask);
     
    12541261            // if all plugins updated, remember the update because it was successful
    12551262            Config.getPref().putInt("pluginmanager.version", Version.getInstance().getVersion());
    1256             Config.getPref().put("pluginmanager.lastupdate", Long.toString(System.currentTimeMillis()));
     1263            Config.getPref().put(PLUGINMANAGER_LASTUPDATE, Long.toString(System.currentTimeMillis()));
    12571264        }
    12581265        return plugins;
     
    12701277        ButtonSpec[] options = {
    12711278                new ButtonSpec(
    1272                         tr("Disable plugin"),
    1273                         new ImageProvider("dialogs", "delete"),
     1279                        tr(DISABLE_PLUGIN),
     1280                        new ImageProvider(DIALOGS, "delete"),
    12741281                        tr("Click to delete the plugin ''{0}''", name),
    12751282                        null /* no specific help context */
     
    12771284                new ButtonSpec(
    12781285                        tr("Keep plugin"),
    1279                         new ImageProvider("cancel"),
     1286                        new ImageProvider(CANCEL),
    12801287                        tr("Click to keep the plugin ''{0}''", name),
    12811288                        null /* no specific help context */
     
    12851292                    parent,
    12861293                    reason,
    1287                     tr("Disable plugin"),
     1294                    tr(DISABLE_PLUGIN),
    12881295                    JOptionPane.WARNING_MESSAGE,
    12891296                    null,
     
    14841491                new ButtonSpec(
    14851492                        tr("Update plugin"),
    1486                         new ImageProvider("dialogs", "refresh"),
     1493                        new ImageProvider(DIALOGS, "refresh"),
    14871494                        tr("Click to update the plugin ''{0}''", plugin.getPluginInformation().name),
    14881495                        null /* no specific help context */
    14891496                ),
    14901497                new ButtonSpec(
    1491                         tr("Disable plugin"),
    1492                         new ImageProvider("dialogs", "delete"),
     1498                        tr(DISABLE_PLUGIN),
     1499                        new ImageProvider(DIALOGS, "delete"),
    14931500                        tr("Click to disable the plugin ''{0}''", plugin.getPluginInformation().name),
    14941501                        null /* no specific help context */
     
    14961503                new ButtonSpec(
    14971504                        tr("Keep plugin"),
    1498                         new ImageProvider("cancel"),
     1505                        new ImageProvider(CANCEL),
    14991506                        tr("Click to keep the plugin ''{0}''", plugin.getPluginInformation().name),
    15001507                        null /* no specific help context */
     
    15031510
    15041511        final StringBuilder msg = new StringBuilder(256);
    1505         msg.append("<html>")
     1512        msg.append(HTML_START)
    15061513           .append(tr("An unexpected exception occurred that may have come from the ''{0}'' plugin.",
    15071514                   Utils.escapeReservedCharactersHTML(plugin.getPluginInformation().name)))
     
    15131520        }
    15141521        msg.append(tr("Try updating to the newest version of this plugin before reporting a bug."))
    1515            .append("</html>");
     1522           .append(HTML_END);
    15161523
    15171524        try {
     
    15191526                    MainApplication.getMainFrame(),
    15201527                    msg.toString(),
    1521                     tr("Update plugins"),
     1528                    tr(UPDATE_PLUGINS),
    15221529                    JOptionPane.QUESTION_MESSAGE,
    15231530                    null,
     
    15901597            return null;
    15911598
    1592         Set<String> plugins = new HashSet<>(Config.getPref().getList("plugins"));
     1599        Set<String> plugins = new HashSet<>(Config.getPref().getList(PLUGINS));
    15931600        final PluginInformation pluginInfo = plugin.getPluginInformation();
    15941601        if (!plugins.contains(pluginInfo.name))
     
    16051612            // deactivate the plugin
    16061613            plugins.remove(plugin.getPluginInformation().name);
    1607             Config.getPref().putList("plugins", new ArrayList<>(plugins));
     1614            Config.getPref().putList(PLUGINS, new ArrayList<>(plugins));
    16081615            GuiHelper.runInEDTAndWait(() -> JOptionPane.showMessageDialog(
    16091616                    MainApplication.getMainFrame(),
     
    16241631     */
    16251632    public static Collection<String> getBugReportInformation() {
    1626         final Collection<String> pl = new TreeSet<>(Config.getPref().getList("plugins", new LinkedList<>()));
     1633        final Collection<String> pl = new TreeSet<>(Config.getPref().getList(PLUGINS, new LinkedList<>()));
    16271634        for (final PluginProxy pp : pluginList) {
    16281635            PluginInformation pi = pp.getPluginInformation();
  • trunk/src/org/openstreetmap/josm/tools/Diff.java

    r12798 r19101  
    104104    private int equivMax = 1;
    105105
    106     private int[] xvec, yvec; /* Vectors being compared. */
     106    /* Vectors being compared. */
     107    private int[] xvec;
     108    private int[] yvec;
    107109    private int[] fdiag;      /* Vector, indexed by diagonal, containing
    108110                   the X coordinate of the point furthest
     
    113115                   along the given diagonal in the backward
    114116                   search of the edit matrix. */
    115     private int fdiagoff, bdiagoff;
     117    private int fdiagoff;
     118    private int bdiagoff;
    116119    private final FileData[] filevec;
    117120    private int cost;
     
    120123     * Find the midpoint of the shortest edit script for a specified
    121124     * portion of the two files.
    122      *
     125     * <p>
    123126     * We scan from the beginnings of the files, and simultaneously from the ends,
    124127     * doing a breadth-first search through the space of edit-sequence.
    125128     * When the two searches meet, we have found the midpoint of the shortest
    126129     * edit sequence.
    127      *
     130     * <p>
    128131     * The value returned is the number of the diagonal on which the midpoint lies.
    129132     * The diagonal number equals the number of inserted lines minus the number
     
    131134     * The edit cost is stored into COST; this is the total number of
    132135     * lines inserted or deleted (counting only lines before the midpoint).
    133      *
     136     * <p>
    134137     * This function assumes that the first lines of the specified portions
    135138     * of the two files do not match, and likewise that the last lines do not
    136139     * match.  The caller must trim matching lines from the beginning and end
    137140     * of the portions it is going to specify.
    138      *
     141     * <p>
    139142     * Note that if we return the "wrong" diagonal value, or if
    140143     * the value of bdiag at that diagonal is "wrong",
     
    156159        final int fmid = xoff - yoff;   // Center diagonal of top-down search.
    157160        final int bmid = xlim - ylim;   // Center diagonal of bottom-up search.
    158         int fmin = fmid, fmax = fmid;   // Limits of top-down search.
    159         int bmin = bmid, bmax = bmid;   // Limits of bottom-up search.
     161        // Limits of top-down search.
     162        int fmin = fmid;
     163        int fmax = fmid;
     164        // Limits of bottom-up search.
     165        int bmin = bmid;
     166        int bmax = bmid;
    160167        // True if southeast corner is on an odd diagonal with respect to the northwest.
    161168        final boolean odd = (fmid - bmid & 1) != 0;
     
    212219            }
    213220            for (d = bmax; d >= bmin; d -= 2) {
    214                 int x, y, tlo = bd[bdiagoff + d - 1], thi = bd[bdiagoff + d + 1];
     221                int x;
     222                int y;
     223                final int tlo = bd[bdiagoff + d - 1];
     224                final int thi = bd[bdiagoff + d + 1];
    215225
    216226                if (tlo < thi) {
     
    235245     * Compare in detail contiguous subsequences of the two files
    236246     * which are known, as a whole, to match each other.
    237      *
     247     * <p>
    238248     * The results are recorded in the vectors filevec[N].changed_flag, by
    239249     * storing a 1 in the element for each line that is an insertion or deletion.
    240      *
     250     * <p>
    241251     * The subsequence of file 0 is [XOFF, XLIM) and likewise for file 1.
    242      *
     252     * <p>
    243253     * Note that XLIM, YLIM are exclusive bounds.
    244254     * All line numbers are origin-0 and discarded lines are not counted.
     
    340350            while (i0 < len0 || i1 < len1) {
    341351                if (changed0[1+i0] || changed1[1+i1]) {
    342                     int line0 = i0, line1 = i1;
     352                    int line0 = i0;
     353                    int line1 = i1;
    343354
    344355                    /* Find # lines changed here in each file.  */
     
    374385            while (i0 >= 0 || i1 >= 0) {
    375386                if (changed0[i0] || changed1[i1]) {
    376                     int line0 = i0, line1 = i1;
     387                    int line0 = i0;
     388                    int line1 = i1;
    377389
    378390                    /* Find # lines changed here in each file.  */
     
    480492         * DELETED is the number of lines deleted here from file 0.
    481493         * INSERTED is the number of lines inserted here in file 1.
    482          *
     494         * <p>
    483495         * If DELETED is 0 then LINE0 is the number of the line before
    484496         * which the insertion was done; vice versa for INSERTED and LINE1.
     
    539551        /**
    540552         * Discard lines that have no matches in another file.
    541          *
     553         * <p>
    542554         * A line which is discarded will not be considered by the actual comparison algorithm;
    543555         * it will be as if that line were not in the file.
     
    747759                    h.put(data[i], equivs[i]);
    748760                } else {
    749                     equivs[i] = ir.intValue();
     761                    equivs[i] = ir;
    750762                }
    751763            }
     
    754766        /**
    755767         * Adjust inserts/deletes of blank lines to join changes as much as possible.
    756          *
     768         * <p>
    757769         * We do something when a run of changed lines include a blank line at one end and have an excluded blank line at the other.
    758770         * We are free to choose which blank line is included.
  • trunk/src/org/openstreetmap/josm/tools/ExifReader.java

    r18315 r19101  
    2323import com.drew.metadata.exif.ExifDirectoryBase;
    2424import com.drew.metadata.exif.ExifIFD0Directory;
    25 import com.drew.metadata.exif.ExifSubIFDDirectory;
    2625import com.drew.metadata.exif.GpsDirectory;
    2726import com.drew.metadata.iptc.IptcDirectory;
     
    7675                }
    7776                for (Tag tag : dirIt.getTags()) {
    78                     if (tag.getTagType() == ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL /* 0x9003 */ &&
    79                             !tag.getDescription().matches("\\[[0-9]+ .+\\]")) {
     77                    if (tag.getTagType() == ExifDirectoryBase.TAG_DATETIME_ORIGINAL /* 0x9003 */ &&
     78                            !tag.getDescription().matches("\\[\\d+ .+]")) {
    8079                        dateTimeOrig = tag.getDescription();
    81                     } else if (tag.getTagType() == ExifIFD0Directory.TAG_DATETIME /* 0x0132 */) {
     80                    } else if (tag.getTagType() == ExifDirectoryBase.TAG_DATETIME /* 0x0132 */) {
    8281                        dateTime = tag.getDescription();
    83                     } else if (tag.getTagType() == ExifSubIFDDirectory.TAG_DATETIME_DIGITIZED /* 0x9004 */) {
     82                    } else if (tag.getTagType() == ExifDirectoryBase.TAG_DATETIME_DIGITIZED /* 0x9004 */) {
    8483                        dateTimeDig = tag.getDescription();
    85                     } else if (tag.getTagType() == ExifSubIFDDirectory.TAG_SUBSECOND_TIME_ORIGINAL /* 0x9291 */) {
     84                    } else if (tag.getTagType() == ExifDirectoryBase.TAG_SUBSECOND_TIME_ORIGINAL /* 0x9291 */) {
    8685                        subSecOrig = tag.getDescription();
    87                     } else if (tag.getTagType() == ExifSubIFDDirectory.TAG_SUBSECOND_TIME /* 0x9290 */) {
     86                    } else if (tag.getTagType() == ExifDirectoryBase.TAG_SUBSECOND_TIME /* 0x9290 */) {
    8887                        subSec = tag.getDescription();
    89                     } else if (tag.getTagType() == ExifSubIFDDirectory.TAG_SUBSECOND_TIME_DIGITIZED /* 0x9292 */) {
     88                    } else if (tag.getTagType() == ExifDirectoryBase.TAG_SUBSECOND_TIME_DIGITIZED /* 0x9292 */) {
    9089                        subSecDig = tag.getDescription();
    9190                    }
     
    145144            final Metadata metadata = JpegMetadataReader.readMetadata(filename);
    146145            final Directory dir = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
    147             return dir == null ? null : dir.getInteger(ExifIFD0Directory.TAG_ORIENTATION);
     146            return dir == null ? null : dir.getInteger(ExifDirectoryBase.TAG_ORIENTATION);
    148147        } catch (JpegProcessingException | IOException e) {
    149148            Logging.error(e);
     
    316315            if (ele != null) {
    317316                final Integer d = dirGps.getInteger(GpsDirectory.TAG_ALTITUDE_REF);
    318                 if (d != null && d.intValue() == 1) {
     317                if (d != null && d == 1) {
    319318                    ele *= -1;
    320319                }
     
    367366    /**
    368367     * Returns a Transform that fixes the image orientation.
    369      *
     368     * <p>
    370369     * Only orientation 1, 3, 6 and 8 are supported. Everything else is treated as 1.
    371370     * @param orientation the exif-orientation of the image
     
    376375    public static AffineTransform getRestoreOrientationTransform(final int orientation, final int width, final int height) {
    377376        final int q;
    378         final double ax, ay;
     377        final double ax;
     378        final double ay;
    379379        switch (orientation) {
    380380        case 8:
     
    404404     * Check, if the given orientation switches width and height of the image.
    405405     * E.g. 90 degree rotation
    406      *
     406     * <p>
    407407     * Only orientation 1, 3, 6 and 8 are supported. Everything else is treated
    408408     * as 1.
     
    416416    /**
    417417     * Check, if the given orientation requires any correction to the image.
    418      *
     418     * <p>
    419419     * Only orientation 1, 3, 6 and 8 are supported. Everything else is treated
    420420     * as 1.
  • trunk/src/org/openstreetmap/josm/tools/LanguageInfo.java

    r19071 r19101  
    9696        } else if (code.matches(".+@.+")) {
    9797            return code.substring(0, 1).toUpperCase(Locale.ENGLISH)
    98                     + code.substring(1, 2)
     98                    + code.charAt(1)
    9999                    + '-'
    100100                    + code.substring(3, 4).toUpperCase(Locale.ENGLISH)
     
    128128    /**
    129129     * Replies the locale code used by JOSM for a given locale.
    130      *
     130     * <p>
    131131     * In most cases JOSM uses the 2-character ISO 639 language code ({@link Locale#getLanguage()}
    132132     * to identify the locale of a localized resource, but in some cases it may use the
    133133     * programmatic name for locales, as replied by {@link Locale#toString()}.
    134      *
     134     * <p>
    135135     * For unknown country codes and variants this function already does fallback to
    136136     * internally known translations.
     
    157157     * Replies the OSM locale codes for the default locale.
    158158     *
     159     * @param prefix a prefix like {@code name:}.
    159160     * @return the OSM locale codes for the default locale
    160161     * @see #getOSMLocaleCodes(String, Locale)
     
    167168    /**
    168169     * Replies the locale codes used by OSM for a given locale.
    169      *
     170     * <p>
    170171     * In most cases OSM uses the 2-character ISO 639 language code ({@link Locale#getLanguage()}
    171172     * to identify the locale of a localized resource, but in some cases it may use the
    172173     * programmatic name for locales, as replied by {@link Locale#toString()}.
    173      *
     174     * <p>
    174175     * For unknown country codes and variants this function already does fallback to
    175176     * internally known translations.
     
    191192                return new String[]{prefix+"zh-Hant-TW", prefix+"zh-Hant", prefix+"zh"};
    192193            default:
    193                 var r = new ArrayList<String>();
     194                ArrayList<String> r = new ArrayList<>();
    194195                for (String s : LanguageInfo.getLanguageCodes(null)) {
    195196                    r.add(prefix + s);
     
    201202    /**
    202203     * Replies the locale code used by Java for a given locale.
    203      *
     204     * <p>
    204205     * In most cases JOSM and Java uses the same codes, but for some exceptions this is needed.
    205206     *
     
    219220            case "id":
    220221                return "in";
    221         }
    222         return localeName;
     222            default:
     223                return localeName;
     224        }
    223225    }
    224226
    225227    /**
    226228     * Replies the display string used by JOSM for a given locale.
    227      *
     229     * <p>
    228230     * In most cases returns text replied by {@link Locale#getDisplayName()}, for some
    229231     * locales an override is used (i.e. when unsupported by Java).
     
    245247    /**
    246248     * Replies the locale used by Java for a given language code.
    247      *
     249     * <p>
    248250     * Accepts JOSM and Java codes as input.
    249251     *
     
    257259    /**
    258260     * Replies the locale used by Java for a given language code.
    259      *
     261     * <p>
    260262     * Accepts JOSM, Java and POSIX codes as input.
    261263     *
  • trunk/src/org/openstreetmap/josm/tools/ListenerList.java

    r19050 r19101  
    4040        @Override
    4141        public boolean equals(Object obj) {
    42             if (obj != null && obj.getClass() == WeakListener.class) {
     42            if (obj instanceof WeakListener) {
    4343                return Objects.equals(listener.get(), ((WeakListener<?>) obj).listener.get());
    4444            } else {
     
    7272    /**
    7373     * Adds a listener. The listener will not prevent the object from being garbage collected.
    74      *
     74     * <p>
    7575     * This should be used with care. It is better to add good cleanup code.
    7676     * @param listener The listener.
     
    7979        if (ensureNotInList(listener)) {
    8080            // clean the weak listeners, just to be sure...
    81             while (weakListeners.remove(new WeakListener<T>(null))) {
    82                 // continue
    83             }
     81            WeakListener<T> nullListener = new WeakListener<>(null);
     82            weakListeners.removeIf(nullListener::equals);
    8483            weakListeners.add(new WeakListener<>(listener));
    8584        }
  • trunk/src/org/openstreetmap/josm/tools/ListeningCollection.java

    r12269 r19101  
    3232    public final Iterator<T> iterator() {
    3333        Iterator<T> it = base.iterator();
    34         return new Iterator<T>() {
     34        return new Iterator<>() {
    3535            private T object;
    3636
  • trunk/src/org/openstreetmap/josm/tools/MultiMap.java

    r15870 r19101  
    1414/**
    1515 * MultiMap - maps keys to multiple values.
    16  *
     16 * <p>
    1717 * Corresponds to Google guava LinkedHashMultimap and Apache Collections MultiValueMap
    1818 * but it is an independent (simple) implementation.
     
    5959    /**
    6060     * Map a key to a value.
    61      *
     61     * <p>
    6262     * Can be called multiple times with the same key, but different value.
    6363     * @param key key with which the specified value is to be associated
     
    7070    /**
    7171     * Put a key that maps to nothing. (Only if it is not already in the map)
    72      *
     72     * <p>
    7373     * Afterwards containsKey(key) will return true and get(key) will return
    7474     * an empty Set instead of null.
     
    7878        if (map.containsKey(key))
    7979            return;
    80         map.put(key, new LinkedHashSet<B>());
     80        map.put(key, new LinkedHashSet<>());
    8181    }
    8282
    8383    /**
    8484     * Map the key to all the given values.
    85      *
     85     * <p>
    8686     * Adds to the mappings that are already there.
    8787     * @param key key with which the specified values are to be associated
     
    104104     * Returns the Set associated with the given key. Result is null if
    105105     * nothing has been mapped to this key.
    106      *
     106     * <p>
    107107     * Modifications of the returned list changes the underling map,
    108108     * but you should better not do that.
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r19094 r19101  
    1616import java.io.InputStream;
    1717import java.io.UnsupportedEncodingException;
    18 import java.lang.reflect.Method;
    1918import java.net.MalformedURLException;
    2019import java.net.URI;
     
    102101    private static final double TO_RADIANS = Math.PI / 180.0;
    103102
    104     /**
    105      * A reference to {@code Map.ofEntries()} available since Java 9
    106      */
    107     static final Method mapOfEntries = mapOfEntriesMethod();
    108 
    109     private static Method mapOfEntriesMethod() {
    110         if (getJavaVersion() >= 9) {
    111             try {
    112                 return Map.class.getMethod("ofEntries", Map.Entry[].class);
    113             } catch (NoSuchMethodException noSuchMethodException) {
    114                 Logging.trace(noSuchMethodException);
    115             }
    116         }
    117         return null;
    118     }
    119 
    120103    private Utils() {
    121104        // Hide default constructor for utils classes
     
    205188     * @deprecated since 15718, use {@link String#join} or {@link Collectors#joining}
    206189     */
    207     @Deprecated
     190    @Deprecated(since = "15718", forRemoval = true)
    208191    public static String join(String sep, Collection<?> values) {
    209192        CheckParameterUtil.ensureParameterNotNull(sep, "sep");
     
    349332     */
    350333    public static boolean deleteFileIfExists(File file) {
    351         if (file.exists()) {
    352             return deleteFile(file);
    353         } else {
    354             return true;
    355         }
     334        return !file.exists() || deleteFile(file);
    356335    }
    357336
     
    590569     */
    591570    public static <A, B> Collection<B> transform(final Collection<? extends A> c, final Function<A, B> f) {
    592         return new AbstractCollection<B>() {
     571        return new AbstractCollection<>() {
    593572
    594573            @Override
     
    599578            @Override
    600579            public Iterator<B> iterator() {
    601                 return new Iterator<B>() {
     580                return new Iterator<>() {
    602581
    603582                    private final Iterator<? extends A> it = c.iterator();
     
    632611     */
    633612    public static <A, B> List<B> transform(final List<? extends A> l, final Function<A, B> f) {
    634         return new AbstractList<B>() {
     613        return new AbstractList<>() {
    635614
    636615            @Override
     
    657636    @SuppressWarnings("unchecked")
    658637    public static <T> List<T> toUnmodifiableList(Collection<T> collection) {
    659         // Java 9: use List.of(...)
    660638        if (isEmpty(collection)) {
    661639            return Collections.emptyList();
     
    663641            return Collections.singletonList(collection.iterator().next());
    664642        } else {
    665             return (List<T>) Arrays.asList(collection.toArray());
     643            // List.copyOf would also work, but if the original collection is immutable, it just returns the original
     644            // collection.
     645            return (List<T>) List.of(collection.toArray());
    666646        }
    667647    }
     
    685665            final Map.Entry<K, V> entry = map.entrySet().iterator().next();
    686666            return Collections.singletonMap(entry.getKey(), entry.getValue());
    687         } else if (mapOfEntries != null) {
    688             try {
    689                 // Java 9: use Map.ofEntries(...)
    690                 return (Map<K, V>) mapOfEntries.invoke(null, (Object) map.entrySet().toArray(new Map.Entry[0]));
    691             } catch (ReflectiveOperationException toLog) {
    692                 Logging.trace(toLog);
    693             }
    694         }
    695         return Collections.unmodifiableMap(map);
     667        }
     668        // Map.copyOf would also work, but if the original map is immutable, it just returns the original map.
     669        return Map.ofEntries(map.entrySet().toArray(new Map.Entry[0]));
    696670    }
    697671
     
    849823    /**
    850824     * Runs an external command and returns the standard output.
    851      *
     825     * <p>
    852826     * The program is expected to execute fast, as this call waits 10 seconds at most.
    853827     *
     
    991965                sb.append(',').append(cur);
    992966            } else {
    993                 sb.append('-').append(last);
    994                 sb.append(',').append(cur);
     967                sb.append('-').append(last)
     968                  .append(',').append(cur);
    995969                cnt = 0;
    996970            }
     
    11291103     * Fixes URL with illegal characters in the query (and fragment) part by
    11301104     * percent encoding those characters.
    1131      *
     1105     * <p>
    11321106     * special characters like &amp; and # are not encoded
    11331107     *
     
    15311505     * @deprecated since 19050 -- use {@link InputStream#readAllBytes()} instead
    15321506     */
    1533     @Deprecated
     1507    @Deprecated(since = "19050", forRemoval = true)
    15341508    public static byte[] readBytesFromStream(InputStream stream) throws IOException {
    15351509        if (stream == null) {
     
    16441618        } else if (val < min) {
    16451619            return min;
    1646         } else if (val > max) {
    1647             return max;
    1648         } else {
    1649             return val;
    1650         }
     1620        }
     1621        return Math.min(val, max);
    16511622    }
    16521623
     
    18601831     * @return true if JOSM has been started via Oracle Java Web Start
    18611832     * @since 15740
    1862      */
     1833     * @deprecated JOSM no longer supports Oracle Java Webstart since Oracle Java Webstart doesn't support Java 9+.
     1834     */
     1835    @Deprecated(since = "19101", forRemoval = true)
    18631836    public static boolean isRunningJavaWebStart() {
    18641837        return isRunningWebStart() && isClassFound("com.sun.javaws.Main");
     
    20712044     */
    20722045    public static Double unitToMeter(String s) throws IllegalArgumentException {
    2073         s = s.replaceAll(" ", "").replaceAll(",", ".");
     2046        s = s.replace(" ", "").replace(",", ".");
    20742047        Matcher m = PATTERN_LENGTH.matcher(s);
    20752048        if (m.matches()) {
    2076             Double v = Double.valueOf(m.group(1));
    2077             if ("cm".equals(m.group(2)))
    2078                 v *= 0.01;
    2079             else if ("mm".equals(m.group(2)))
    2080                 v *= 0.001;
    2081             else if ("km".equals(m.group(2)))
    2082                 v *= 1000.0;
    2083             else if ("nmi".equals(m.group(2)))
    2084                 v *= 1852.0;
    2085             else if ("mi".equals(m.group(2)))
    2086                 v *= 1609.344;
    2087             else if ("ft".equals(m.group(2)) || "'".equals(m.group(2)))
    2088                 v *= 0.3048;
    2089             else if ("in".equals(m.group(2)) || "\"".equals(m.group(2)))
    2090                 v *= 0.0254;
    2091             return v;
     2049            return Double.parseDouble(m.group(1)) * unitToMeterConversion(m.group(2));
    20922050        } else {
    20932051            m = PATTERN_LENGTH2.matcher(s);
     
    20952053                /* NOTE: we assume -a'b" means -(a'+b") and not (-a')+b" - because of such issues SI units have been invented
    20962054                   and have been adopted by the majority of the world */
    2097                 return (Double.valueOf(m.group(2))*0.3048+Double.valueOf(m.group(4))*0.0254)*(m.group(1).isEmpty() ? 1.0 : -1.0);
     2055                return (Double.parseDouble(m.group(2))*0.3048+Double.parseDouble(m.group(4))*0.0254)*(m.group(1).isEmpty() ? 1.0 : -1.0);
    20982056            }
    20992057        }
    21002058        throw new IllegalArgumentException("Invalid length value: " + s);
    21012059    }
     2060
     2061    /**
     2062     * Get the conversion factor for a specified unit to meters
     2063     * @param unit The unit to convert to meters
     2064     * @return The conversion factor or 1.
     2065     * @throws IllegalArgumentException if the unit does not currently have a conversion
     2066     */
     2067    private static double unitToMeterConversion(String unit) throws IllegalArgumentException {
     2068        if (unit == null) {
     2069            return 1;
     2070        }
     2071        switch (unit) {
     2072            case "cm": return 0.01;
     2073            case "mm": return 0.001;
     2074            case "m": return 1;
     2075            case "km": return 1000.0;
     2076            case "nmi": return 1852.0;
     2077            case "mi": return 1609.344;
     2078            case "ft":
     2079            case "'":
     2080                return 0.3048;
     2081            case "in":
     2082            case "\"":
     2083                return 0.0254;
     2084            default: throw new IllegalArgumentException("Invalid length unit: " + unit);
     2085        }
     2086    }
    21022087}
  • trunk/src/org/openstreetmap/josm/tools/bugreport/ReportedException.java

    r17380 r19101  
    3232 * @since 10285
    3333 */
    34 @SuppressWarnings("OverrideThrowableToString")
    3534public class ReportedException extends RuntimeException {
    3635    /**
     
    168167     */
    169168    public boolean isSame(ReportedException e) {
    170         if (!getMessage().equals(e.getMessage())) {
    171             return false;
    172         }
    173 
    174         return hasSameStackTrace(new CauseTraceIterator(), e.getCause());
     169        return getMessage().equals(e.getMessage()) && hasSameStackTrace(new CauseTraceIterator(), e.getCause());
    175170    }
    176171
     
    192187        if ((c1 == null) != (c2 == null)) {
    193188            return false;
    194         } else if (c1 != null) {
    195             return hasSameStackTrace(causeTraceIterator, c2);
    196         } else {
    197             return true;
    198         }
     189        }
     190        return c1 == null || hasSameStackTrace(causeTraceIterator, c2);
    199191    }
    200192
     
    231223                string = makeCollectionNice((Collection<?>) value);
    232224            } else if (value.getClass().isArray()) {
    233                 string = makeCollectionNice(Arrays.asList(value));
     225                string = makeCollectionNice(Collections.singleton(value));
    234226            } else {
    235227                string = value.toString();
     
    283275     */
    284276    public boolean isOutOfMemory() {
    285         return StreamUtils.toStream(CauseTraceIterator::new).anyMatch(t -> t instanceof OutOfMemoryError);
     277        return StreamUtils.toStream(CauseTraceIterator::new).anyMatch(OutOfMemoryError.class::isInstance);
    286278    }
    287279
     
    293285    private final class CauseTraceIterator implements Iterator<Throwable> {
    294286        private Throwable current = getCause();
    295         private final Set<Throwable> dejaVu = Collections.newSetFromMap(new IdentityHashMap<Throwable, Boolean>());
     287        private final Set<Throwable> dejaVu = Collections.newSetFromMap(new IdentityHashMap<>());
    296288
    297289        @Override
  • trunk/src/org/openstreetmap/josm/tools/template_engine/Variable.java

    r16488 r19101  
    6262    @Override
    6363    public boolean isValid(TemplateEngineDataProvider dataProvider) {
    64         if (special && SPECIAL_VALUE_EVERYTHING.equals(variableName))
    65             return true;
    66         else
    67             return dataProvider.getTemplateValue(variableName, special) != null;
     64        return (special && SPECIAL_VALUE_EVERYTHING.equals(variableName))
     65            || dataProvider.getTemplateValue(variableName, special) != null;
    6866    }
    6967
     
    9492            return false;
    9593        Variable other = (Variable) obj;
    96         if (special != other.special)
    97             return false;
    98         if (variableName == null) {
    99             if (other.variableName != null)
    100                 return false;
    101         } else if (!variableName.equals(other.variableName))
    102             return false;
    103         return true;
     94        return this.special == other.special && Objects.equals(this.variableName, other.variableName);
    10495    }
    10596}
Note: See TracChangeset for help on using the changeset viewer.