Skip to content

Commit

Permalink
use instanceof pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
cpesch committed Jan 21, 2024
1 parent 034cb42 commit d26c788
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,8 @@ private void handleMapAndThemeUpdate(boolean centerAndZoom, boolean alwaysRecent
layers.remove(remove);
remove.onDestroy();

if (remove instanceof TileLayer)
//noinspection rawtypes
((TileLayer) remove).getTileCache().destroy();
if (remove instanceof TileLayer tileLayer)
tileLayer.getTileCache().destroy();
}
mapsToLayers.clear();

Expand All @@ -562,8 +561,8 @@ private void handleMapAndThemeUpdate(boolean centerAndZoom, boolean alwaysRecent
handleOverlays();

// then start download layer threads
if (layer instanceof TileDownloadLayer)
((TileDownloadLayer) layer).start();
if (layer instanceof TileDownloadLayer tileDownloadLayer)
tileDownloadLayer.start();

// center and zoom: if map is initialized, doesn't contain route or there is no route
BoundingBox mapBoundingBox = getMapBoundingBox();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ public void setShowCoordinates(boolean showCoordinates) {

private JFrame getFrame() {
Application application = Application.getInstance();
if (!(application instanceof SingleFrameApplication))
if (application instanceof SingleFrameApplication singleFrameApplication)
return singleFrameApplication.getFrame();
else
return null;
return ((SingleFrameApplication) application).getFrame();
}

private void display(Point locationOnScreen, int mouseX, int mouseY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ private MarkerAndDelta getMarkerFor(MouseEvent e) {
continue;

org.mapsforge.core.model.Point layerXY = projection.toPixels(layer.getPosition());
if (layer.onTap(tapLatLong, layerXY, tapXY)) {
return new MarkerAndDelta((DraggableMarker) layer, layerXY.x - tapXY.x, layerXY.y - tapXY.y);
if (layer.onTap(tapLatLong, layerXY, tapXY) && layer instanceof DraggableMarker draggableMarker) {
return new MarkerAndDelta(draggableMarker, layerXY.x - tapXY.x, layerXY.y - tapXY.y);
}
}
}
Expand Down

0 comments on commit d26c788

Please sign in to comment.