diff --git a/scripts/TagInfoExtract.java b/scripts/TagInfoExtract.java index e7c349a10b3..13c4b718e47 100644 --- a/scripts/TagInfoExtract.java +++ b/scripts/TagInfoExtract.java @@ -121,8 +121,6 @@ public static void main(String[] args) throws IOException, OsmTransferException, case EXTERNAL_PRESETS: script.new ExternalPresets().run(); break; - default: - throw new IllegalStateException("Invalid type " + script.options.mode); } if (!script.options.noexit) { System.exit(0); diff --git a/src/org/openstreetmap/josm/actions/AutoScaleAction.java b/src/org/openstreetmap/josm/actions/AutoScaleAction.java index ccbadd22616..229984088bb 100644 --- a/src/org/openstreetmap/josm/actions/AutoScaleAction.java +++ b/src/org/openstreetmap/josm/actions/AutoScaleAction.java @@ -232,8 +232,6 @@ public AutoScaleAction(final AutoScaleMode mode) { case NEXT: setHelpId(ht("/Action/ZoomToNext")); break; - default: - throw new IllegalArgumentException("Unknown mode: " + mode); } installAdapters(); } diff --git a/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java b/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java index 6ef15620ef9..790293029c3 100644 --- a/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java +++ b/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java @@ -246,7 +246,6 @@ private void updateCursor() { case DRAGGING: newCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR); break; - default: throw new AssertionError(); } if (newCursor != null) { mv.setNewCursor(newCursor, this); diff --git a/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java b/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java index fcf5dab5ce0..764cacc10be 100644 --- a/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java +++ b/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java @@ -68,12 +68,12 @@ /** * Move is an action that can move all kind of OsmPrimitives (except keys for now). - * + *
* If an selected object is under the mouse when dragging, move all selected objects. * If an unselected object is under the mouse when dragging, it becomes selected * and will be moved. * If no object is under the mouse, move all selected objects (if any) - * + *
* On Mac OS X, Ctrl + mouse button 1 simulates right click (map move), so the * feature "selection remove" is disabled on this platform. */ @@ -401,9 +401,9 @@ private boolean repaintIfRequired(OsmPrimitive newHighlight) { /** * Look, whether any object is selected. If not, select the nearest node. * If there are no nodes in the dataset, do nothing. - * + *
* If the user did not press the left mouse button, do nothing. - * + *
* Also remember the starting position of the movement and change the mouse
* cursor to movement.
*/
@@ -464,7 +464,6 @@ public void mousePressed(MouseEvent e) {
GuiHelper.scheduleTimer(initialMoveDelay+1, evt -> updateStatusLine(), false);
break;
case SELECT:
- default:
if (!(ctrl && PlatformManager.isPlatformOsx())) {
// start working with rectangle or lasso
selectionManager.register(mv, lassoMode);
diff --git a/src/org/openstreetmap/josm/command/SplitWayCommand.java b/src/org/openstreetmap/josm/command/SplitWayCommand.java
index d3834a7eb33..45e0f2cc377 100644
--- a/src/org/openstreetmap/josm/command/SplitWayCommand.java
+++ b/src/org/openstreetmap/josm/command/SplitWayCommand.java
@@ -366,7 +366,7 @@ public static Optional
* This method detects cyclic dependencies in new relation. Relations with cyclic
* dependencies can't be uploaded.
*
diff --git a/src/org/openstreetmap/josm/data/Bounds.java b/src/org/openstreetmap/josm/data/Bounds.java
index a66d23a9089..78b777151e5 100644
--- a/src/org/openstreetmap/josm/data/Bounds.java
+++ b/src/org/openstreetmap/josm/data/Bounds.java
@@ -277,7 +277,6 @@ public Bounds(String asString, String separator, ParseMethod parseMethod, boolea
this.maxLon = initLon(values[2], roundToOsmPrecision);
break;
case MINLAT_MINLON_MAXLAT_MAXLON:
- default:
this.minLat = initLat(values[0], roundToOsmPrecision);
this.minLon = initLon(values[1], roundToOsmPrecision);
this.maxLat = initLat(values[2], roundToOsmPrecision);
diff --git a/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java b/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java
index 96cba8680f5..32830838e5e 100644
--- a/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java
+++ b/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java
@@ -215,6 +215,8 @@ public void loadingFinished(CacheEntry object, CacheEntryAttributes attributes,
break;
case CANCELED:
tile.loadingCanceled();
+ break;
+ default: // This should be removed when we move to Java 17+
// do nothing
}
diff --git a/src/org/openstreetmap/josm/data/osm/SimplePrimitiveId.java b/src/org/openstreetmap/josm/data/osm/SimplePrimitiveId.java
index 2759592a732..ef5b5d3bcf2 100644
--- a/src/org/openstreetmap/josm/data/osm/SimplePrimitiveId.java
+++ b/src/org/openstreetmap/josm/data/osm/SimplePrimitiveId.java
@@ -166,7 +166,8 @@ public static String toSimpleId(PrimitiveId primitive) {
case MULTIPOLYGON:
case RELATION:
return "r" + primitive.getUniqueId();
+ default:
+ throw new IllegalArgumentException("Unknown primitive type: " + primitive.getType());
}
- throw new IllegalArgumentException("Unknown primitive type: " + primitive.getType());
}
}
diff --git a/src/org/openstreetmap/josm/data/osm/pbf/Blob.java b/src/org/openstreetmap/josm/data/osm/pbf/Blob.java
index 23af549add0..e753013d83e 100644
--- a/src/org/openstreetmap/josm/data/osm/pbf/Blob.java
+++ b/src/org/openstreetmap/josm/data/osm/pbf/Blob.java
@@ -97,8 +97,7 @@ public InputStream inputStream() throws IOException {
throw new IOException(this.compressionType + " pbf is not currently supported");
case zlib:
return new InflaterInputStream(bais);
- default:
- throw new IOException("unknown compression type is not currently supported: " + this.compressionType.name());
}
+ throw new IOException("unknown compression type is not currently supported: " + this.compressionType.name());
}
}
diff --git a/src/org/openstreetmap/josm/data/projection/proj/LambertAzimuthalEqualArea.java b/src/org/openstreetmap/josm/data/projection/proj/LambertAzimuthalEqualArea.java
index f1a0e9774b6..5682d687142 100644
--- a/src/org/openstreetmap/josm/data/projection/proj/LambertAzimuthalEqualArea.java
+++ b/src/org/openstreetmap/josm/data/projection/proj/LambertAzimuthalEqualArea.java
@@ -121,8 +121,6 @@ public void initialize(ProjParameters params) throws ProjectionConfigurationExce
xmf = rq * dd;
ymf = rq / dd;
break;
- default:
- throw new AssertionError(mode);
}
}
@@ -132,7 +130,11 @@ public double[] project(final double phi, final double lambda) {
final double sinlam = Math.sin(lambda);
final double sinphi = Math.sin(phi);
double q = qsfn(sinphi);
- final double sinb, cosb, b, c, x, y;
+ double sinb, cosb, b, c, x, y;
+ // Set c, x, y to 0 until we move to Java 17 where we can use a better switch expression.
+ c = 0;
+ x = 0;
+ y = 0;
switch (mode) {
case OBLIQUE:
sinb = q / qp;
@@ -172,8 +174,6 @@ public double[] project(final double phi, final double lambda) {
x = y = 0.;
}
break;
- default:
- throw new AssertionError(mode);
}
if (Math.abs(c) < EPSILON_LATITUDE) {
return new double[] {0, 0}; // this is an error, we should handle it somehow
@@ -191,9 +191,8 @@ public double[] invproject(double x, double y) {
return invprojectNS(x, -y);
case SOUTH_POLE:
return invprojectNS(x, y);
- default:
- throw new AssertionError(mode);
}
+ throw new AssertionError(mode);
}
private double[] invprojectEO(double x, double y) {
diff --git a/src/org/openstreetmap/josm/data/validation/Test.java b/src/org/openstreetmap/josm/data/validation/Test.java
index 3b2a0052941..8f148480cbf 100644
--- a/src/org/openstreetmap/josm/data/validation/Test.java
+++ b/src/org/openstreetmap/josm/data/validation/Test.java
@@ -41,6 +41,7 @@
*
* @author frsantos
*/
+@SuppressWarnings("PMD.UnitTestShouldUseTestAnnotation")
public class Test implements OsmPrimitiveVisitor {
protected static final Predicate
* It can be used as {@link javax.swing.table.TableModel}.
*/
public class RelationMemberConflictResolverModel extends DefaultTableModel {
@@ -112,8 +112,8 @@ public Object getValueAt(int row, int column) {
case 3: /* original */ return d.getOriginalPrimitive();
case 4: /* decision keep */ return RelationMemberConflictDecisionType.KEEP == d.getDecision();
case 5: /* decision remove */ return RelationMemberConflictDecisionType.REMOVE == d.getDecision();
+ default: return null;
}
- return null;
}
@Override
@@ -211,7 +211,7 @@ public void populate(Collection
* Keep/delete decisions are made if every member has the same role and the members are in consecutive order within the relation.
* For multiple occurrences those conditions are tested stepwise for each occurrence.
*/
@@ -221,7 +221,7 @@ public void prepareDefaultRelationDecisions() {
/**
* Prepare the default decisions for the current model.
- *
+ *
* Keep/delete decisions are made if every member has the same role and the members are in consecutive order within the relation.
* For multiple occurrences those conditions are tested stepwise for each occurrence.
*
@@ -382,6 +382,7 @@ protected Command buildResolveCommand(Relation relation, OsmPrimitive newPrimiti
// do nothing
break;
case UNDECIDED:
+ default:
// FIXME: this is an error
break;
}
@@ -418,6 +419,7 @@ protected boolean isChanged(Relation relation, OsmPrimitive newPrimitive) {
return true;
break;
case UNDECIDED:
+ default:
// FIXME: handle error
}
}
diff --git a/src/org/openstreetmap/josm/gui/dialogs/ConflictResolutionDialog.java b/src/org/openstreetmap/josm/gui/dialogs/ConflictResolutionDialog.java
index 7812c9c86f4..8a663936b4b 100644
--- a/src/org/openstreetmap/josm/gui/dialogs/ConflictResolutionDialog.java
+++ b/src/org/openstreetmap/josm/gui/dialogs/ConflictResolutionDialog.java
@@ -196,11 +196,9 @@ public void actionPerformed(ActionEvent evt) {
options,
options[1]
);
- switch (ret) {
- case JOptionPane.YES_OPTION:
+ if (ret == JOptionPane.YES_OPTION) {
buttonAction(1, evt);
- break;
- default:
+ } else {
return;
}
}
diff --git a/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentTableCellRenderer.java b/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentTableCellRenderer.java
index 881e3adf748..2424985ec69 100644
--- a/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentTableCellRenderer.java
+++ b/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentTableCellRenderer.java
@@ -25,6 +25,7 @@ protected void renderModificationType(ChangesetModificationType type) {
case CREATED: setText(tr("Created")); break;
case UPDATED: setText(tr("Updated")); break;
case DELETED: setText(tr("Deleted")); break;
+ default: throw new IllegalStateException("Unexpected value: " + type);
}
setToolTipText(null);
}
diff --git a/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentTableModel.java b/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentTableModel.java
index d3f70017c67..bf262671a2d 100644
--- a/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentTableModel.java
+++ b/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentTableModel.java
@@ -113,10 +113,10 @@ public int getRowCount() {
@Override
public Object getValueAt(int row, int col) {
- switch (col) {
- case 0: return data.get(row).getModificationType();
- default: return data.get(row).getPrimitive();
+ if (col == 0) {
+ return data.get(row).getModificationType();
}
+ return data.get(row).getPrimitive();
}
/**
diff --git a/src/org/openstreetmap/josm/gui/dialogs/changeset/query/ChangesetQueryDialog.java b/src/org/openstreetmap/josm/gui/dialogs/changeset/query/ChangesetQueryDialog.java
index 5c63b8841cd..be64af83a0b 100644
--- a/src/org/openstreetmap/josm/gui/dialogs/changeset/query/ChangesetQueryDialog.java
+++ b/src/org/openstreetmap/josm/gui/dialogs/changeset/query/ChangesetQueryDialog.java
@@ -203,6 +203,8 @@ public void actionPerformed(ActionEvent arg0) {
pnlAdvancedQueries.displayMessageIfInvalid();
return;
}
+ default:
+ throw new IllegalStateException("Unexpected value: " + tpQueryPanels.getSelectedIndex());
}
setCanceled(false);
setVisible(false);
diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java b/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
index 32d6db84617..d98bae99c68 100644
--- a/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
+++ b/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
@@ -247,9 +247,10 @@ public Object getValueAt(int rowIndex, int columnIndex) {
return members.get(rowIndex).getMember();
case 2:
return getWayConnection(rowIndex);
+ default:
+ // should not happen
+ return null;
}
- // should not happen
- return null;
}
@Override
diff --git a/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java b/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java
index ae2d73f60c2..a7b526d0119 100644
--- a/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java
+++ b/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java
@@ -134,8 +134,7 @@ public static boolean saveUnsavedModifications(Iterable extends Layer> selecte
dialog.setVisible(true);
switch (dialog.getUserAction()) {
case PROCEED: return true;
- case CANCEL:
- default: return false;
+ case CANCEL: return false;
}
}
dialog.closeDialog();
@@ -378,10 +377,14 @@ protected void cancelWhenInEditingModel() {
public void cancel() {
switch (model.getMode()) {
- case EDITING_DATA: cancelWhenInEditingModel();
+ case EDITING_DATA:
+ cancelWhenInEditingModel();
break;
- case UPLOADING_AND_SAVING: cancelSafeAndUploadTask();
+ case UPLOADING_AND_SAVING:
+ cancelSafeAndUploadTask();
break;
+ default:
+ throw new IllegalStateException("Unexpected value: " + model.getMode());
}
}
@@ -427,10 +430,14 @@ public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(SaveLayersModel.MODE_PROP)) {
Mode mode = (Mode) evt.getNewValue();
switch (mode) {
- case EDITING_DATA: setEnabled(true);
+ case EDITING_DATA:
+ setEnabled(true);
break;
- case UPLOADING_AND_SAVING: setEnabled(false);
+ case UPLOADING_AND_SAVING:
+ setEnabled(false);
break;
+ default:
+ throw new IllegalStateException("Unexpected value: " + mode);
}
}
}
@@ -524,10 +531,14 @@ public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(SaveLayersModel.MODE_PROP)) {
SaveLayersModel.Mode mode = (SaveLayersModel.Mode) evt.getNewValue();
switch (mode) {
- case EDITING_DATA: setEnabled(true);
+ case EDITING_DATA:
+ setEnabled(true);
break;
- case UPLOADING_AND_SAVING: setEnabled(false);
+ case UPLOADING_AND_SAVING:
+ setEnabled(false);
break;
+ default:
+ throw new IllegalStateException("Unexpected value: " + mode);
}
}
}
diff --git a/src/org/openstreetmap/josm/gui/io/SaveLayersTable.java b/src/org/openstreetmap/josm/gui/io/SaveLayersTable.java
index 82285eb4e07..224bcd88f76 100644
--- a/src/org/openstreetmap/josm/gui/io/SaveLayersTable.java
+++ b/src/org/openstreetmap/josm/gui/io/SaveLayersTable.java
@@ -26,10 +26,14 @@ public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(SaveLayersModel.MODE_PROP)) {
Mode mode = (Mode) evt.getNewValue();
switch (mode) {
- case EDITING_DATA: setEnabled(true);
- break;
- case UPLOADING_AND_SAVING: setEnabled(false);
- break;
+ case EDITING_DATA:
+ setEnabled(true);
+ break;
+ case UPLOADING_AND_SAVING:
+ setEnabled(false);
+ break;
+ default:
+ throw new IllegalStateException("Unexpected value: " + mode);
}
}
}
diff --git a/src/org/openstreetmap/josm/gui/io/UploadPrimitivesTask.java b/src/org/openstreetmap/josm/gui/io/UploadPrimitivesTask.java
index 22f5eb153b8..5bf34474085 100644
--- a/src/org/openstreetmap/josm/gui/io/UploadPrimitivesTask.java
+++ b/src/org/openstreetmap/josm/gui/io/UploadPrimitivesTask.java
@@ -400,7 +400,6 @@ protected void finish() {
if (e.getSource() == ChangesetClosedException.Source.UPLOAD_DATA) {
switch (strategy.getPolicy()) {
case ABORT:
- break; /* do nothing - we return to map editing */
case AUTOMATICALLY_OPEN_NEW_CHANGESETS:
break; /* do nothing - we return to map editing */
case FILL_ONE_CHANGESET_AND_RETURN_TO_UPLOAD_DIALOG:
@@ -410,6 +409,8 @@ protected void finish() {
UploadDialog.getUploadDialog().setUploadedPrimitives(toUpload);
UploadDialog.getUploadDialog().setVisible(true);
break;
+ default:
+ throw new IllegalStateException("Unexpected value: " + strategy.getPolicy());
}
} else {
handleFailedUpload(lastException);
diff --git a/src/org/openstreetmap/josm/gui/io/UploadStrategySelectionPanel.java b/src/org/openstreetmap/josm/gui/io/UploadStrategySelectionPanel.java
index 96d95e94457..b1e64e1dff6 100644
--- a/src/org/openstreetmap/josm/gui/io/UploadStrategySelectionPanel.java
+++ b/src/org/openstreetmap/josm/gui/io/UploadStrategySelectionPanel.java
@@ -38,7 +38,7 @@
/**
* UploadStrategySelectionPanel is a panel for selecting an upload strategy.
- *
+ *
* Clients can listen for property change events for the property
* {@link #UPLOAD_STRATEGY_SPECIFICATION_PROP}.
*/
@@ -393,6 +393,8 @@ public void itemStateChanged(ItemEvent e) {
tfChunkSize.setEnabled(true);
tfChunkSize.requestFocusInWindow();
break;
+ case SINGLE_REQUEST_STRATEGY:
+ case INDIVIDUAL_OBJECTS_STRATEGY:
default:
tfChunkSize.setEnabled(false);
}
diff --git a/src/org/openstreetmap/josm/gui/layer/CustomizeColor.java b/src/org/openstreetmap/josm/gui/layer/CustomizeColor.java
index 10f3082aabe..76583f3c511 100644
--- a/src/org/openstreetmap/josm/gui/layer/CustomizeColor.java
+++ b/src/org/openstreetmap/josm/gui/layer/CustomizeColor.java
@@ -26,7 +26,7 @@
/**
* Action to show a dialog for picking a color.
- *
+ *
* By calling this action, the user can choose a color to customize the painting
* of a certain {@link GpxLayer} or {@link org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer}.
*/
@@ -83,14 +83,16 @@ public void actionPerformed(ActionEvent e) {
options[0]
);
switch (answer) {
- case 0:
+ case JOptionPane.OK_OPTION:
colorLayers.forEach(l -> l.setColor(c.getColor()));
break;
- case 1:
+ case JOptionPane.NO_OPTION:
return;
- case 2:
+ case JOptionPane.CANCEL_OPTION:
colorLayers.forEach(l -> l.setColor(null));
break;
+ default:
+ throw new IllegalStateException("Unexpected value: " + answer);
}
// TODO: Make the layer dialog listen to property change events so that this is not needed any more.
LayerListDialog.getInstance().repaint();
diff --git a/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java b/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java
index e3efd81259a..ebcb0b63378 100644
--- a/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java
+++ b/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java
@@ -114,15 +114,17 @@ private void showColorDialog(List
* This includes:
*
* How to use:
- *
+ *
*
* short form:
*
* (optional)
* @param archive zip file where the image is located
* @return the current object, for convenience
@@ -383,9 +388,9 @@ public ImageProvider setArchive(File archive) {
/**
* Specify a base path inside the zip file.
- *
+ *
* The subdir and name will be relative to this path.
- *
+ *
* (optional)
* @param inArchiveDir path inside the archive
* @return the current object, for convenience
@@ -412,7 +417,7 @@ public ImageProvider addOverlay(ImageOverlay overlay) {
/**
* Set the dimensions of the image.
- *
+ *
* If not specified, the original size of the image is used.
* The width part of the dimension can be -1. Then it will only set the height but
* keep the aspect ratio. (And the other way around.)
@@ -427,7 +432,7 @@ public ImageProvider setSize(Dimension size) {
/**
* Set the dimensions of the image.
- *
+ *
* If not specified, the original size of the image is used.
* @param size final dimensions of the image
* @return the current object, for convenience
@@ -475,10 +480,10 @@ public ImageProvider setHeight(int height) {
/**
* Limit the maximum size of the image.
- *
+ *
* It will shrink the image if necessary, but keep the aspect ratio.
* The given width or height can be -1 which means this direction is not bounded.
- *
+ *
* 'size' and 'maxSize' are not compatible, you should set only one of them.
* @param maxSize maximum image size
* @return the current object, for convenience
@@ -491,10 +496,10 @@ public ImageProvider setMaxSize(Dimension maxSize) {
/**
* Limit the maximum size of the image.
- *
+ *
* It will shrink the image if necessary, but keep the aspect ratio.
* The given width or height can be -1 which means this direction is not bounded.
- *
+ *
* This function sets value using the most restrictive of the new or existing set of
* values.
*
@@ -514,10 +519,10 @@ public ImageProvider resetMaxSize(Dimension maxSize) {
/**
* Limit the maximum size of the image.
- *
+ *
* It will shrink the image if necessary, but keep the aspect ratio.
* The given width or height can be -1 which means this direction is not bounded.
- *
+ *
* 'size' and 'maxSize' are not compatible, you should set only one of them.
* @param size maximum image size
* @return the current object, for convenience
@@ -560,7 +565,7 @@ public ImageProvider setMaxHeight(int maxHeight) {
/**
* Decide, if an exception should be thrown, when the image cannot be located.
- *
+ *
* Set to true, when the image URL comes from user data and the image may be missing.
*
* @param optional true, if JOSM should not throw a RuntimeException
@@ -574,7 +579,7 @@ public ImageProvider setOptional(boolean optional) {
/**
* Suppresses warning on the command line in case the image cannot be found.
- *
+ *
* In combination with setOptional(true);
* @param suppressWarnings if
* This method returns immediately and runs the image request asynchronously.
* @param action the action that will deal with the image
*
@@ -711,7 +716,7 @@ public ImageResource getResource() {
/**
* Load the image in a background thread.
- *
+ *
* This method returns immediately and runs the image request asynchronously.
* @param action the action that will deal with the image
*
@@ -883,9 +888,7 @@ private ImageResource getIfAvailableImpl() {
} else {
extensions = new String[] {".png", ".svg"};
}
- final int typeArchive = 0;
- final int typeLocal = 1;
- for (int place : new Integer[] {typeArchive, typeLocal}) {
+ for (ImageLocations place : ImageLocations.values()) {
for (String ext : extensions) {
if (".svg".equals(ext)) {
@@ -905,7 +908,7 @@ private ImageResource getIfAvailableImpl() {
}
switch (place) {
- case typeArchive:
+ case ARCHIVE:
if (archive != null) {
cacheName = "zip:" + archive.hashCode() + ':' + cacheName;
ImageResource ir = cache.get(cacheName);
@@ -918,7 +921,7 @@ private ImageResource getIfAvailableImpl() {
}
}
break;
- case typeLocal:
+ case LOCAL:
ImageResource ir = cache.get(cacheName);
if (ir != null) return ir;
@@ -955,7 +958,7 @@ private static ImageResource getIfAvailableHttp(String url, ImageType type) {
InputStream is = cf.getInputStream()) {
switch (type) {
case SVG:
- SVGDiagram svg = null;
+ SVGDiagram svg;
synchronized (getSvgUniverse()) {
URI uri = getSvgUniverse().loadSVG(is, Utils.fileToURL(cf.getFile()).toString());
svg = getSvgUniverse().getDiagram(uri);
@@ -969,13 +972,12 @@ private static ImageResource getIfAvailableHttp(String url, ImageType type) {
Logging.log(Logging.LEVEL_WARN, "Exception while reading HTTP image:", e);
}
return img == null ? null : new ImageResource(img);
- default:
- throw new AssertionError("Unsupported type: " + type);
}
} catch (IOException e) {
Logging.debug(e);
return null;
}
+ throw new AssertionError("Unsupported type: " + type);
}
/**
@@ -1081,6 +1083,7 @@ private static ImageResource getIfAvailableWiki(String name, ImageType type) {
* @return the requested image or null if the request failed
*/
private static ImageResource getIfAvailableZip(String fullName, File archive, String inArchiveDir, ImageType type) {
+ Objects.requireNonNull(type, "ImageType must not be null");
try (ZipFile zipFile = new ZipFile(archive, StandardCharsets.UTF_8)) {
if (inArchiveDir == null || ".".equals(inArchiveDir)) {
inArchiveDir = "";
@@ -1096,7 +1099,7 @@ private static ImageResource getIfAvailableZip(String fullName, File archive, St
try (InputStream is = zipFile.getInputStream(entry)) {
switch (type) {
case SVG:
- SVGDiagram svg = null;
+ SVGDiagram svg;
synchronized (getSvgUniverse()) {
URI uri = getSvgUniverse().loadSVG(is, entryName, true);
svg = getSvgUniverse().getDiagram(uri);
@@ -1115,8 +1118,6 @@ private static ImageResource getIfAvailableZip(String fullName, File archive, St
Logging.warn(e);
}
return img == null ? null : new ImageResource(img);
- default:
- throw new AssertionError("Unknown ImageType: "+type);
}
}
}
@@ -1134,6 +1135,7 @@ private static ImageResource getIfAvailableZip(String fullName, File archive, St
* @return the requested image or null if the request failed
*/
private static ImageResource getIfAvailableLocalURL(URL path, ImageType type) {
+ Objects.requireNonNull(type, "ImageType must not be null");
switch (type) {
case SVG:
SVGDiagram svg = null;
@@ -1173,9 +1175,9 @@ private static ImageResource getIfAvailableLocalURL(URL path, ImageType type) {
Logging.debug(e);
}
return img == null ? null : new ImageResource(img);
- default:
- throw new AssertionError();
}
+ // Default
+ throw new AssertionError();
}
private static URL getImageUrl(String path, String name) {
@@ -1378,8 +1380,8 @@ public static Image createBoundedImage(Image img, int maxSize) {
* This method will use a multi-step scaling technique that provides higher quality than the usual
* one-step technique (only useful in downscaling cases, where {@code targetWidth} or {@code targetHeight} is
* smaller than the original dimensions, and generally only when the {@code BILINEAR} hint is specified).
- *
- * From https://community.oracle.com/docs/DOC-983611: "The Perils of Image.getScaledInstance()"
+ *
+ * From "The Perils of Image.getScaledInstance()"
*
* @param img the original image to be scaled
* @param targetWidth the desired width of the scaled instance, in pixels
diff --git a/src/org/openstreetmap/josm/tools/ImageWarp.java b/src/org/openstreetmap/josm/tools/ImageWarp.java
index a4d3641ea13..023eee22e2d 100644
--- a/src/org/openstreetmap/josm/tools/ImageWarp.java
+++ b/src/org/openstreetmap/josm/tools/ImageWarp.java
@@ -163,6 +163,7 @@ public enum Interpolation {
* @return the warped image
*/
public static BufferedImage warp(BufferedImage srcImg, Dimension targetDim, PointTransform invTransform, Interpolation interpolation) {
+ Objects.requireNonNull(interpolation, "interpolation");
BufferedImage imgTarget = new BufferedImage(targetDim.width, targetDim.height, BufferedImage.TYPE_INT_ARGB);
Rectangle2D srcRect = new Rectangle2D.Double(0, 0, srcImg.getWidth(), srcImg.getHeight());
// These arrays reduce the amount of memory allocations (getRGB and setRGB are
@@ -174,7 +175,8 @@ public static BufferedImage warp(BufferedImage srcImg, Dimension targetDim, Poin
for (int i = 0; i < imgTarget.getWidth(); i++) {
Point2D srcCoord = invTransform.transform(i, j);
if (srcRect.contains(srcCoord)) {
- int rgba;
+ // Convert to switch expression when we switch to Java 17+.
+ int rgba = 0; // Initialized here so the compiler doesn't complain. Otherwise, BILINEAR needs to have it start at 0.
switch (interpolation) {
case NEAREST_NEIGHBOR:
rgba = getColor((int) Math.round(srcCoord.getX()), (int) Math.round(srcCoord.getY()), srcImg, sharedArray);
@@ -188,7 +190,7 @@ public static BufferedImage warp(BufferedImage srcImg, Dimension targetDim, Poin
int c01 = getColor(x0, y0 + 1, srcImg, sharedArray);
int c10 = getColor(x0 + 1, y0, srcImg, sharedArray);
int c11 = getColor(x0 + 1, y0 + 1, srcImg, sharedArray);
- rgba = 0;
+ // rgba
// loop over color components: blue, green, red, alpha
for (int ch = 0; ch <= 3; ch++) {
int shift = 8 * ch;
@@ -198,8 +200,6 @@ public static BufferedImage warp(BufferedImage srcImg, Dimension targetDim, Poin
rgba |= chVal << shift;
}
break;
- default:
- throw new AssertionError(Objects.toString(interpolation));
}
imgTarget.getRaster().setDataElements(i, j, imgTarget.getColorModel().getDataElements(rgba, pixel));
}
*
ImageIcon icon = new ImageProvider(name).setMaxSize(ImageSizes.MAP).get();
* (there are more options, see below)
- *
+ * ImageIcon icon = ImageProvider.get(name);
*
@@ -246,6 +246,11 @@ public Dimension getImageDimension() {
}
}
+ private enum ImageLocations {
+ LOCAL,
+ ARCHIVE
+ }
+
/**
* Property set on {@code BufferedImage} returned by {@link #makeImageTransparent}.
* @since 7132
@@ -371,7 +376,7 @@ public ImageProvider setId(String id) {
/**
* Specify a zip file where the image is located.
- *
+ * true
warnings are suppressed
* @return the current object, for convenience
@@ -666,7 +671,7 @@ public String getDataURL() {
/**
* Load the image in a background thread.
- *
+ *