Skip to content

Commit f358f64

Browse files
author
taylor.smock
committed
Cleanup some new PMD warnings from PMD 7.x (followup of r19101)
git-svn-id: https://josm.openstreetmap.de/svn/trunk@19106 0c6e7542-c601-0410-84e7-c038aed88b3b
1 parent bb7d6fd commit f358f64

39 files changed

+380
-286
lines changed

scripts/SyncEditorLayerIndex.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ public class SyncEditorLayerIndex {
107107
private static String optionJosmXml;
108108
private static String optionEncoding;
109109
private static boolean optionNoEli;
110-
private Map<String, String> skip = new HashMap<>();
111-
private Map<String, String> skipStart = new HashMap<>();
110+
private final Map<String, String> skip = new HashMap<>();
111+
private final Map<String, String> skipStart = new HashMap<>();
112112

113113
/**
114114
* Main method.
@@ -237,7 +237,7 @@ void setupProj() {
237237
}
238238

239239
void loadSkip() throws IOException {
240-
final Pattern pattern = Pattern.compile("^\\|\\| *(ELI|Ignore) *\\|\\| *\\{\\{\\{(.+)\\}\\}\\} *\\|\\|");
240+
final Pattern pattern = Pattern.compile("^\\|\\| *(ELI|Ignore) *\\|\\| *\\{\\{\\{(.+)}}} *\\|\\|");
241241
try (BufferedReader fr = Files.newBufferedReader(Paths.get(ignoreInputFile), UTF_8)) {
242242
String line;
243243

@@ -478,8 +478,8 @@ void printentries(List<?> entries, Writer stream) throws IOException {
478478
}
479479
shapes += sep + "</shape>\n";
480480
}
481-
} catch (IllegalArgumentException ignored) {
482-
Logging.trace(ignored);
481+
} catch (IllegalArgumentException illegalArgumentException) {
482+
Logging.trace(illegalArgumentException);
483483
}
484484
if (!shapes.isEmpty()) {
485485
stream.write(" <bounds min-lat='"+df.format(minlat)
@@ -775,9 +775,9 @@ void doSameUrlButDifferentDates() {
775775
Matcher m = pattern.matcher(ed);
776776
if (m.matches()) {
777777
Calendar cal = Calendar.getInstance();
778-
cal.set(Integer.valueOf(m.group(2)),
779-
m.group(4) == null ? 0 : Integer.valueOf(m.group(4))-1,
780-
m.group(6) == null ? 1 : Integer.valueOf(m.group(6)));
778+
cal.set(Integer.parseInt(m.group(2)),
779+
m.group(4) == null ? 0 : Integer.parseInt(m.group(4))-1,
780+
m.group(6) == null ? 1 : Integer.parseInt(m.group(6)));
781781
cal.add(Calendar.DAY_OF_MONTH, -1);
782782
ed2 = m.group(1) + cal.get(Calendar.YEAR);
783783
if (m.group(4) != null)
@@ -1229,7 +1229,7 @@ void doMiscellaneousChecks() {
12291229
myprintln("~ Strange URL '"+u+"': "+getDescription(j));
12301230
} else {
12311231
try {
1232-
URL jurl = new URL(u.replaceAll("\\{switch:[^\\}]*\\}", "x"));
1232+
URL jurl = new URL(u.replaceAll("\\{switch:[^}]*}", "x"));
12331233
String domain = jurl.getHost();
12341234
int port = jurl.getPort();
12351235
if (!(domain.matches("^\\d+\\.\\d+\\.\\d+\\.\\d+$")) && !dv.isValid(domain))
@@ -1374,11 +1374,9 @@ static List<ImageryInfo> getMirrors(Object e) {
13741374
static List<String> getProjections(Object e) {
13751375
List<String> r = new ArrayList<>();
13761376
List<String> u = getProjectionsUnstripped(e);
1377-
if (u != null) {
1378-
for (String p : u) {
1379-
if (!oldproj.containsKey(p) && !("CRS:84".equals(p) && !(getUrlStripped(e).matches("(?i)version=1\\.3")))) {
1380-
r.add(p);
1381-
}
1377+
for (String p : u) {
1378+
if (!oldproj.containsKey(p) && !("CRS:84".equals(p) && !(getUrlStripped(e).matches("(?i)version=1\\.3")))) {
1379+
r.add(p);
13821380
}
13831381
}
13841382
return r;

src/org/openstreetmap/josm/actions/OrthogonalizeAction.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
/**
4545
* Tools / Orthogonalize
46-
*
46+
* <p>
4747
* Align edges of a way so all angles are angles of 90 or 180 degrees.
4848
* See USAGE String below.
4949
*/
@@ -72,7 +72,7 @@ public OrthogonalizeAction() {
7272
/**
7373
* excepted deviation from an angle of 0, 90, 180, 360 degrees
7474
* maximum value: 45 degrees
75-
*
75+
* <p>
7676
* Current policy is to except just everything, no matter how strange the result would be.
7777
*/
7878
private static final double TOLERANCE1 = Utils.toRadians(45.); // within a way
@@ -85,10 +85,10 @@ public OrthogonalizeAction() {
8585

8686
/**
8787
* Undo the previous orthogonalization for certain nodes.
88-
*
88+
* <p>
8989
* This is useful, if the way shares nodes that you don't like to change, e.g. imports or
9090
* work of another user.
91-
*
91+
* <p>
9292
* This action can be triggered by shortcut only.
9393
*/
9494
public static class Undo extends JosmAction {
@@ -278,7 +278,8 @@ private static Command orthogonalize(List<WayData> wayDataList, Node singleNode)
278278
for (WayData wd : wayDataList) {
279279
int n = wd.wayNodes.size();
280280
int i = wd.wayNodes.indexOf(singleNode);
281-
Node n0, n2;
281+
final Node n0;
282+
final Node n2;
282283
if (i == 0 && n >= 3 && singleNode.equals(wd.wayNodes.get(n-1))) {
283284
n0 = wd.wayNodes.get(n-2);
284285
n2 = wd.wayNodes.get(1);
@@ -427,7 +428,7 @@ private static Collection<Command> orthogonalize(List<WayData> wayDataList, List
427428
double average = 0;
428429
for (Node n : cs) {
429430
s.remove(n);
430-
average += nC.get(n).doubleValue();
431+
average += nC.get(n);
431432
}
432433
average = average / cs.size();
433434

src/org/openstreetmap/josm/gui/animation/DropImage.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.io.File;
99
import java.net.URL;
1010
import java.net.URLDecoder;
11+
import java.nio.charset.StandardCharsets;
1112
import java.util.ArrayList;
1213
import java.util.Enumeration;
1314
import java.util.jar.JarEntry;
@@ -70,7 +71,7 @@ private Image getImage() {
7071
ArrayList<String> result = new ArrayList<>();
7172
String path = "images/presets/";
7273
URL url = DropImage.class.getClassLoader().getResource(path);
73-
if (url != null && url.getProtocol().equals("file")) {
74+
if (url != null && "file".equals(url.getProtocol())) {
7475
ArrayList<File> dirs = new ArrayList<>();
7576
dirs.add(new File(url.toURI()));
7677
do {
@@ -86,9 +87,9 @@ private Image getImage() {
8687
}
8788
} while (!dirs.isEmpty());
8889
name = result.get(seed.nextInt(result.size()));
89-
} else if (url != null && url.getProtocol().equals("jar")) {
90-
String jarPath = url.getPath().substring(5, url.getPath().indexOf("!"));
91-
try (JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8"))) {
90+
} else if (url != null && "jar".equals(url.getProtocol())) {
91+
String jarPath = url.getPath().substring(5, url.getPath().indexOf('!'));
92+
try (JarFile jar = new JarFile(URLDecoder.decode(jarPath, StandardCharsets.UTF_8))) {
9293
Enumeration<JarEntry> entries = jar.entries();
9394
while (entries.hasMoreElements()) {
9495
String fileName = entries.nextElement().getName();

src/org/openstreetmap/josm/gui/conflict/pair/AbstractListMergeModel.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
* A ListMergeModel can be ''frozen''. If it's frozen, it doesn't accept additional merge
6565
* decisions. {@link PropertyChangeListener}s can register for property value changes of
6666
* {@link #FROZEN_PROP}.
67-
*
67+
* <p>
6868
* ListMergeModel is an abstract class. Three methods have to be implemented by subclasses:
6969
* <ul>
7070
* <li>{@link AbstractListMergeModel#cloneEntryForMergedList} - clones an entry of type T</li>
@@ -202,7 +202,7 @@ public int getTheirEntriesSize() {
202202
protected AbstractListMergeModel() {
203203
entries = new EnumMap<>(ListRole.class);
204204
for (ListRole role : ListRole.values()) {
205-
entries.put(role, new ArrayList<T>());
205+
entries.put(role, new ArrayList<>());
206206
}
207207

208208
buildMyEntriesTableModel();
@@ -378,14 +378,13 @@ protected void alertCopyFailedForDeletedPrimitives(List<PrimitiveId> deletedIds)
378378
if (deletedIds.size() > MAX_DELETED_PRIMITIVE_IN_DIALOG) {
379379
items.add(tr("{0} more...", deletedIds.size() - MAX_DELETED_PRIMITIVE_IN_DIALOG));
380380
}
381-
StringBuilder sb = new StringBuilder();
382-
sb.append("<html>")
383-
.append(tr("The following objects could not be copied to the target object<br>because they are deleted in the target dataset:"))
384-
.append(Utils.joinAsHtmlUnorderedList(items))
385-
.append("</html>");
381+
String sb = "<html>" +
382+
tr("The following objects could not be copied to the target object<br>because they are deleted in the target dataset:") +
383+
Utils.joinAsHtmlUnorderedList(items) +
384+
"</html>";
386385
HelpAwareOptionPane.showOptionDialog(
387386
MainApplication.getMainFrame(),
388-
sb.toString(),
387+
sb,
389388
tr("Merging deleted objects failed"),
390389
JOptionPane.WARNING_MESSAGE,
391390
HelpUtil.ht("/Dialog/Conflict#MergingDeletedPrimitivesFailed")

src/org/openstreetmap/josm/gui/conflict/tags/MultiValueCellEditor.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
* This is a table cell editor for selecting a possible tag value from a list of
2828
* proposed tag values. The editor also allows to select all proposed valued or
2929
* to remove the tag.
30-
*
30+
* <p>
3131
* The editor responds intercepts some keys and interprets them as navigation keys. It
3232
* forwards navigation events to {@link NavigationListener}s registered with this editor.
3333
* You should register the parent table using this editor as {@link NavigationListener}.
34-
*
34+
* <p>
3535
* {@link KeyEvent#VK_ENTER} and {@link KeyEvent#VK_TAB} trigger a {@link NavigationListener#gotoNextDecision()}.
3636
*/
3737
public class MultiValueCellEditor extends AbstractCellEditor implements TableCellEditor {
@@ -87,7 +87,7 @@ protected void fireGotoPreviousDecision() {
8787
*/
8888
public MultiValueCellEditor() {
8989
editorModel = new JosmComboBoxModel<>();
90-
editor = new JosmComboBox<Object>(editorModel) {
90+
editor = new JosmComboBox<>(editorModel) {
9191
@Override
9292
public void processKeyEvent(KeyEvent e) {
9393
if (e.getID() == KeyEvent.KEY_PRESSED) {
@@ -215,26 +215,27 @@ protected void renderColors(boolean selected) {
215215
* @param value {@link String} or {@link MultiValueDecisionType}
216216
*/
217217
protected void renderValue(Object value) {
218-
setFont(UIManager.getFont("ComboBox.font"));
218+
final String comboBoxFont = "ComboBox.font";
219+
setFont(UIManager.getFont(comboBoxFont));
219220
if (value instanceof String) {
220221
setText((String) value);
221222
} else if (value instanceof MultiValueDecisionType) {
222223
switch ((MultiValueDecisionType) value) {
223224
case UNDECIDED:
224225
setText(tr("Choose a value"));
225-
setFont(UIManager.getFont("ComboBox.font").deriveFont(Font.ITALIC + Font.BOLD));
226+
setFont(UIManager.getFont(comboBoxFont).deriveFont(Font.ITALIC + Font.BOLD));
226227
break;
227228
case KEEP_NONE:
228229
setText(tr("none"));
229-
setFont(UIManager.getFont("ComboBox.font").deriveFont(Font.ITALIC + Font.BOLD));
230+
setFont(UIManager.getFont(comboBoxFont).deriveFont(Font.ITALIC + Font.BOLD));
230231
break;
231232
case KEEP_ALL:
232233
setText(tr("all"));
233-
setFont(UIManager.getFont("ComboBox.font").deriveFont(Font.ITALIC + Font.BOLD));
234+
setFont(UIManager.getFont(comboBoxFont).deriveFont(Font.ITALIC + Font.BOLD));
234235
break;
235236
case SUM_ALL_NUMERIC:
236237
setText(tr("sum"));
237-
setFont(UIManager.getFont("ComboBox.font").deriveFont(Font.ITALIC + Font.BOLD));
238+
setFont(UIManager.getFont(comboBoxFont).deriveFont(Font.ITALIC + Font.BOLD));
238239
break;
239240
default:
240241
// don't display other values

src/org/openstreetmap/josm/gui/datatransfer/TagTransferable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ private String getStringData() {
5353
if (string.length() > 0) {
5454
string.append('\n');
5555
}
56-
string.append(e.getKey());
57-
string.append('=');
58-
string.append(e.getValue());
56+
string.append(e.getKey())
57+
.append('=')
58+
.append(e.getValue());
5959
}
6060
return string.toString();
6161
}

src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDataText.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ void addRelationMembers(IRelation<?> r) {
222222
for (IRelationMember<?> m : r.getMembers()) {
223223
s.append(INDENT).append(INDENT);
224224
addHeadline(m.getMember());
225-
s.append(tr(" as \"{0}\"", m.getRole()));
226-
s.append(NL);
225+
s.append(tr(" as \"{0}\"", m.getRole()))
226+
.append(NL);
227227
}
228228
}
229229

src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ public void remember(Collection<? extends OsmPrimitive> selection) {
528528
IntStream.range(1, history.size())
529529
.filter(i -> history.get(i).equals(selection))
530530
.findFirst()
531-
.ifPresent(i -> history.remove(i));
531+
.ifPresent(history::remove);
532532
int maxsize = Config.getPref().getInt("select.history-size", SELECTION_HISTORY_SIZE);
533533
while (history.size() > maxsize) {
534534
history.removeLast();

src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.awt.FlowLayout;
1111
import java.awt.Graphics;
1212
import java.awt.GraphicsEnvironment;
13+
import java.awt.GridBagConstraints;
1314
import java.awt.GridBagLayout;
1415
import java.awt.GridLayout;
1516
import java.awt.Rectangle;
@@ -45,6 +46,7 @@
4546
import javax.swing.JScrollPane;
4647
import javax.swing.JToggleButton;
4748
import javax.swing.Scrollable;
49+
import javax.swing.SwingConstants;
4850
import javax.swing.SwingUtilities;
4951

5052
import org.openstreetmap.josm.actions.JosmAction;
@@ -99,25 +101,26 @@ public enum ButtonHidingType {
99101
* @since 6752
100102
*/
101103
public static final BooleanProperty PROP_DYNAMIC_BUTTONS = new BooleanProperty("dialog.dynamic.buttons", false);
104+
private static final String SELECTED = "selected";
102105

103106
private final transient ParametrizedEnumProperty<ButtonHidingType> propButtonHiding =
104-
new ParametrizedEnumProperty<ToggleDialog.ButtonHidingType>(ButtonHidingType.class, ButtonHidingType.DYNAMIC) {
105-
@Override
106-
protected String getKey(String... params) {
107-
return preferencePrefix + ".buttonhiding";
108-
}
107+
new ParametrizedEnumProperty<>(ButtonHidingType.class, ButtonHidingType.DYNAMIC) {
108+
@Override
109+
protected String getKey(String... params) {
110+
return preferencePrefix + ".buttonhiding";
111+
}
109112

110-
@Override
111-
protected ButtonHidingType parse(String s) {
112-
try {
113-
return super.parse(s);
114-
} catch (IllegalArgumentException e) {
115-
// Legacy settings
116-
Logging.trace(e);
117-
return Boolean.parseBoolean(s) ? ButtonHidingType.DYNAMIC : ButtonHidingType.ALWAYS_SHOWN;
118-
}
119-
}
120-
};
113+
@Override
114+
protected ButtonHidingType parse(String s) {
115+
try {
116+
return super.parse(s);
117+
} catch (IllegalArgumentException e) {
118+
// Legacy settings
119+
Logging.trace(e);
120+
return Boolean.parseBoolean(s) ? ButtonHidingType.DYNAMIC : ButtonHidingType.ALWAYS_SHOWN;
121+
}
122+
}
123+
};
121124

122125
/** The action to toggle this dialog */
123126
protected final ToggleDialogAction toggleAction;
@@ -353,8 +356,8 @@ public void showDialog() {
353356
if (windowMenuItem != null) {
354357
windowMenuItem.setState(true);
355358
}
356-
toggleAction.putValue("selected", Boolean.FALSE);
357-
toggleAction.putValue("selected", Boolean.TRUE);
359+
toggleAction.putValue(SELECTED, Boolean.FALSE);
360+
toggleAction.putValue(SELECTED, Boolean.TRUE);
358361
}
359362

360363
/**
@@ -381,7 +384,7 @@ public void unfurlDialog() {
381384

382385
@Override
383386
public void buttonHidden() {
384-
if (Boolean.TRUE.equals(toggleAction.getValue("selected"))) {
387+
if (Boolean.TRUE.equals(toggleAction.getValue(SELECTED))) {
385388
toggleAction.actionPerformed(null);
386389
}
387390
}
@@ -401,7 +404,7 @@ public void hideDialog() {
401404
windowMenuItem.setState(false);
402405
}
403406
setIsShowing(false);
404-
toggleAction.putValue("selected", Boolean.FALSE);
407+
toggleAction.putValue(SELECTED, Boolean.FALSE);
405408
}
406409

407410
/**
@@ -550,7 +553,7 @@ public TitleBar(String toggleDialogName, String iconName) {
550553

551554
// scale down the dialog icon
552555
ImageIcon icon = ImageProvider.get("dialogs", iconName, ImageProvider.ImageSizes.SMALLICON);
553-
lblTitle = new JLabel("", icon, JLabel.TRAILING);
556+
lblTitle = new JLabel("", icon, SwingConstants.TRAILING);
554557
lblTitle.setIconTextGap(8);
555558

556559
JPanel conceal = new JPanel();
@@ -568,7 +571,7 @@ public void paintComponent(Graphics g) {
568571
};
569572
lblTitleWeak.setPreferredSize(new Dimension(Integer.MAX_VALUE, 20));
570573
lblTitleWeak.setMinimumSize(new Dimension(0, 20));
571-
add(lblTitleWeak, GBC.std().fill(GBC.HORIZONTAL));
574+
add(lblTitleWeak, GBC.std().fill(GridBagConstraints.HORIZONTAL));
572575

573576
buttonsHide = new JButton(ImageProvider.get("misc", buttonHiding != ButtonHidingType.ALWAYS_SHOWN
574577
? /* ICON(misc/)*/ "buttonhide" : /* ICON(misc/)*/ "buttonshow"));

src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public void actionPerformed(ActionEvent e) {
175175
fixAction.setEnabled(false);
176176
buttons.add(new SideButton(fixAction));
177177

178-
if (ValidatorPrefHelper.PREF_USE_IGNORE.get()) {
178+
if (Boolean.TRUE.equals(ValidatorPrefHelper.PREF_USE_IGNORE.get())) {
179179
ignoreAction = new AbstractAction() {
180180
{
181181
putValue(NAME, tr("Ignore"));
@@ -429,7 +429,7 @@ private boolean setSelection(Collection<OsmPrimitive> sel, boolean addSelected)
429429
public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
430430
OsmDataLayer editLayer = e.getSource().getEditLayer();
431431
if (editLayer == null) {
432-
tree.setErrorList(new ArrayList<TestError>());
432+
tree.setErrorList(new ArrayList<>());
433433
} else {
434434
tree.setErrorList(editLayer.validationErrors);
435435
}

0 commit comments

Comments
 (0)