Index: trunk/src/org/openstreetmap/josm/data/imagery/GetCapabilitiesParseHelper.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/imagery/GetCapabilitiesParseHelper.java	(revision 11012)
+++ trunk/src/org/openstreetmap/josm/data/imagery/GetCapabilitiesParseHelper.java	(revision 11013)
@@ -18,5 +18,5 @@
  *
  */
-public class GetCapabilitiesParseHelper {
+public final class GetCapabilitiesParseHelper {
     enum TransferMode {
         KVP("KVP"),
@@ -68,10 +68,13 @@
     // CHECKSTYLE.ON: SingleSpaceSeparator
 
+    private GetCapabilitiesParseHelper() {
+        // Hide default constructor for utilities classes
+    }
 
     /**
      * @param in InputStream with pointing to GetCapabilities XML stream
      * @return safe XMLStreamReader, that is not validating external entities, nor loads DTD's
-     * @throws IOException
-     * @throws XMLStreamException
+     * @throws IOException if any I/O error occurs
+     * @throws XMLStreamException if any XML stream error occurs
      */
     public static XMLStreamReader getReader(InputStream in) throws IOException, XMLStreamException {
@@ -93,9 +96,7 @@
         QName tag = reader.getName();
         for (int event = reader.getEventType(); reader.hasNext(); event = reader.next()) {
-            switch (event) {
-            case XMLStreamReader.START_ELEMENT:
+            if (XMLStreamReader.START_ELEMENT == event) {
                 level += 1;
-                break;
-            case XMLStreamReader.END_ELEMENT:
+            } else if (XMLStreamReader.END_ELEMENT == event) {
                 level -= 1;
                 if (level == 0 && tag.equals(reader.getName())) {
@@ -187,7 +188,7 @@
 
     /**
-     * @param url
+     * @param url URL
      * @return normalized URL
-     * @throws MalformedURLException
+     * @throws MalformedURLException in case of malformed URL
      * @since 10993
      */
@@ -199,6 +200,6 @@
 
     /**
-     *
-     * @param crsIdentifier
+     * Convert CRS identifier to plain code
+     * @param crsIdentifier CRS identifier
      * @return CRS Identifier as it is used within JOSM (without prefix)
      */
Index: trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java	(revision 11012)
+++ trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java	(revision 11013)
@@ -141,5 +141,5 @@
         private String baseUrl;
         private String style;
-        public Collection<String> tileMatrixSetLinks = new ArrayList<>();
+        private Collection<String> tileMatrixSetLinks = new ArrayList<>();
 
         Layer(Layer l) {
@@ -266,5 +266,5 @@
     private String handleTemplate(String url) {
         Pattern pattern = Pattern.compile(PATTERN_HEADER);
-        StringBuffer output = new StringBuffer(); // NOSONAR
+        StringBuffer output = new StringBuffer();
         Matcher matcher = pattern.matcher(url);
         while (matcher.find()) {
@@ -513,15 +513,14 @@
                         GetCapabilitiesParseHelper.QN_OWS_OPERATIONS_METADATA.equals(reader.getName()));
                 event = reader.next()) {
-            if (event == XMLStreamReader.START_ELEMENT) {
-                if (GetCapabilitiesParseHelper.QN_OWS_OPERATION.equals(reader.getName()) && "GetTile".equals(reader.getAttributeValue("", "name")) &&
-                        GetCapabilitiesParseHelper.moveReaderToTag(reader, new QName[]{
-                                GetCapabilitiesParseHelper.QN_OWS_DCP,
-                                GetCapabilitiesParseHelper.QN_OWS_HTTP,
-                                GetCapabilitiesParseHelper.QN_OWS_GET,
-
-                        })) {
-                    this.baseUrl = reader.getAttributeValue(GetCapabilitiesParseHelper.XLINK_NS_URL, "href");
-                    this.transferMode = GetCapabilitiesParseHelper.getTransferMode(reader);
-                }
+            if (event == XMLStreamReader.START_ELEMENT &&
+                    GetCapabilitiesParseHelper.QN_OWS_OPERATION.equals(reader.getName()) &&
+                    "GetTile".equals(reader.getAttributeValue("", "name")) &&
+                    GetCapabilitiesParseHelper.moveReaderToTag(reader, new QName[] {
+                            GetCapabilitiesParseHelper.QN_OWS_DCP,
+                            GetCapabilitiesParseHelper.QN_OWS_HTTP,
+                            GetCapabilitiesParseHelper.QN_OWS_GET,
+                    })) {
+                this.baseUrl = reader.getAttributeValue(GetCapabilitiesParseHelper.XLINK_NS_URL, "href");
+                this.transferMode = GetCapabilitiesParseHelper.getTransferMode(reader);
             }
         }
@@ -573,7 +572,7 @@
         // no support for non-square tiles (tileHeight != tileWidth)
         // and for different tile sizes at different zoom levels
-        Collection<Layer> layers = getLayers(null, Main.getProjection().toCode());
-        if (!layers.isEmpty()) {
-            return layers.iterator().next().tileMatrixSet.tileMatrix.get(0).tileHeight;
+        Collection<Layer> projLayers = getLayers(null, Main.getProjection().toCode());
+        if (!projLayers.isEmpty()) {
+            return projLayers.iterator().next().tileMatrixSet.tileMatrix.get(0).tileHeight;
         }
         // if no layers is found, fallback to default mercator tile size. Maybe it will work
@@ -584,9 +583,9 @@
     @Override
     public String getTileUrl(int zoom, int tilex, int tiley) {
-        String url;
         if (currentLayer == null) {
             return "";
         }
 
+        String url;
         if (currentLayer.baseUrl != null && transferMode == null) {
             url = currentLayer.baseUrl;
Index: trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java	(revision 11012)
+++ trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java	(revision 11013)
@@ -87,5 +87,4 @@
 import org.openstreetmap.josm.gui.MapFrame;
 import org.openstreetmap.josm.gui.MapView;
-import org.openstreetmap.josm.gui.MapViewState.MapViewRectangle;
 import org.openstreetmap.josm.gui.NavigatableComponent.ZoomChangeListener;
 import org.openstreetmap.josm.gui.PleaseWaitRunnable;
@@ -107,5 +106,4 @@
 /**
  * Base abstract class that supports displaying images provided by TileSource. It might be TMS source, WMS or WMTS
- *
  * It implements all standard functions of tilesource based layers: autozoom, tile reloads, layer saving, loading,etc.
  *
@@ -119,8 +117,5 @@
 implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeListener, DisplaySettingsChangeListener {
     private static final String PREFERENCE_PREFIX = "imagery.generic";
-    /**
-     * Registers all setting properties
-     */
-    static {
+    static { // Registers all setting properties
         new TileSourceDisplaySettings();
     }
@@ -138,8 +133,5 @@
 
     //public static final BooleanProperty PROP_DRAW_DEBUG = new BooleanProperty(PREFERENCE_PREFIX + ".draw_debug", false);
-    /**
-     * Zoomlevel at which tiles is currently downloaded.
-     * Initial zoom lvl is set to bestZoom
-     */
+    /** Zoomlevel at which tiles is currently downloaded. Initial zoom lvl is set to bestZoom */
     public int currentZoomLevel;
 
@@ -164,7 +156,5 @@
     protected TileLoader tileLoader;
 
-    /**
-     * A timer that is used to delay invalidation events if required.
-     */
+    /** A timer that is used to delay invalidation events if required. */
     private final Timer invalidateLaterTimer = new Timer(100, e -> this.invalidate());
 
@@ -284,6 +274,5 @@
      *
      * If the current tileLoader is an instance of OsmTileLoader, a new
-     * TmsTileClearController is created and passed to the according clearCache
-     * method.
+     * TmsTileClearController is created and passed to the according clearCache method.
      *
      * @param monitor not used in this implementation - as cache clear is instaneus
@@ -387,5 +376,4 @@
          * maps as a imagery layer
          */
-
         int intResult = (int) Math.round(result + 1 + ZOOM_OFFSET.get() / 1.9);
 
@@ -406,6 +394,5 @@
 
         private String getSizeString(int size) {
-            StringBuilder ret = new StringBuilder();
-            return ret.append(size).append('x').append(size).toString();
+            return new StringBuilder().append(size).append('x').append(size).toString();
         }
 
@@ -667,6 +654,5 @@
     @Override
     public void hookUpMapView() {
-        // this needs to be here and not in constructor to allow empty TileSource class construction
-        // using SessionWriter
+        // this needs to be here and not in constructor to allow empty TileSource class construction using SessionWriter
         initializeIfRequired();
 
@@ -685,6 +671,5 @@
         }
 
-        // FIXME: why do we need this? Without this, if you add a WMS layer and do not move the mouse, sometimes, tiles do not
-        // start loading.
+        // FIXME: why do we need this? Without this, if you add a WMS layer and do not move the mouse, sometimes, tiles do not start loading.
         // FIXME: Check if this is still required.
         event.getMapView().repaint(500);
@@ -949,7 +934,5 @@
 
     /*
-     * We use these for quick, hackish calculations.  They
-     * are temporary only and intentionally not inserted
-     * into the tileCache.
+     * We use these for quick, hackish calculations. They are temporary only and intentionally not inserted into the tileCache.
      */
     private Tile tempCornerTile(Tile t) {
@@ -1011,7 +994,5 @@
 
     private TileSet getVisibleTileSet() {
-        MapView mv = Main.map.mapView;
-        MapViewRectangle area = mv.getState().getViewArea();
-        ProjectionBounds bounds = area.getProjectionBounds();
+        ProjectionBounds bounds = Main.map.mapView.getState().getViewArea().getProjectionBounds();
         return getTileSet(bounds.getMin(), bounds.getMax(), currentZoomLevel);
     }
@@ -1085,15 +1066,12 @@
     }
 
-    // 'source' is the pixel coordinates for the area that
-    // the img is capable of filling in.  However, we probably
-    // only want a portion of it.
+    // 'source' is the pixel coordinates for the area that the img is capable of filling in.
+    // However, we probably only want a portion of it.
     //
-    // 'border' is the screen cordinates that need to be drawn.
-    //  We must not draw outside of it.
+    // 'border' is the screen cordinates that need to be drawn. We must not draw outside of it.
     private void drawImageInside(Graphics g, Image sourceImg, Rectangle2D source, Rectangle2D border) {
         Rectangle2D target = source;
 
-        // If a border is specified, only draw the intersection
-        // if what we have combined with what we are supposed to draw.
+        // If a border is specified, only draw the intersection if what we have combined with what we are supposed to draw.
         if (border != null) {
             target = source.createIntersection(border);
@@ -1103,8 +1081,6 @@
         }
 
-        // All of the rectangles are in screen coordinates.  We need
-        // to how these correlate to the sourceImg pixels.  We could
-        // avoid doing this by scaling the image up to the 'source' size,
-        // but this should be cheaper.
+        // All of the rectangles are in screen coordinates. We need to how these correlate to the sourceImg pixels.
+        // We could avoid doing this by scaling the image up to the 'source' size, but this should be cheaper.
         //
         // In some projections, x any y are scaled differently enough to
@@ -1160,21 +1136,18 @@
     }
 
-    // This function is called for several zoom levels, not just
-    // the current one.  It should not trigger any tiles to be
-    // downloaded.  It should also avoid polluting the tile cache
-    // with any tiles since these tiles are not mandatory.
+    // This function is called for several zoom levels, not just the current one.
+    // It should not trigger any tiles to be downloaded.
+    // It should also avoid polluting the tile cache with any tiles since these tiles are not mandatory.
     //
-    // The "border" tile tells us the boundaries of where we may
-    // draw.  It will not be from the zoom level that is being
-    // drawn currently.  If drawing the displayZoomLevel,
-    // border is null and we draw the entire tile set.
+    // The "border" tile tells us the boundaries of where we may drawn.
+    // It will not be from the zoom level that is being drawn currently.
+    // If drawing the displayZoomLevel, border is null and we draw the entire tile set.
     private List<Tile> paintTileImages(Graphics g, TileSet ts, int zoom, Tile border) {
         if (zoom <= 0) return Collections.emptyList();
         Rectangle2D borderRect = coordinateConverter.getRectangleForTile(border);
         List<Tile> missedTiles = new LinkedList<>();
-        // The callers of this code *require* that we return any tiles
-        // that we do not draw in missedTiles.  ts.allExistingTiles() by
-        // default will only return already-existing tiles.  However, we
-        // need to return *all* tiles to the callers, so force creation here.
+        // The callers of this code *require* that we return any tiles that we do not draw in missedTiles.
+        // ts.allExistingTiles() by default will only return already-existing tiles.
+        // However, we need to return *all* tiles to the callers, so force creation here.
         for (Tile tile : ts.allTilesCreate()) {
             Image img = getLoadedTileImage(tile);
@@ -1243,7 +1216,7 @@
                 texty += 1 + fontHeight;
             }
-        }*/
-
-        /*String tileStatus = tile.getStatus();
+        }
+
+        String tileStatus = tile.getStatus();
         if (!tile.isLoaded() && PROP_DRAW_DEBUG.get()) {
             myDrawString(g, tr("image " + tileStatus), p.x + 2, texty);
@@ -1291,5 +1264,4 @@
         return getShiftedLatLon(Main.getProjection().latlon2eastNorth(new LatLon(latLon)));
     }
-
 
     private final TileSet nullTileSet = new TileSet();
@@ -1344,5 +1316,4 @@
      * The position of a single tile.
      * @author Michael Zangl
-     * @since xxx
      */
     private static class TilePosition {
@@ -1351,5 +1322,4 @@
         private final int zoom;
         TilePosition(int x, int y, int zoom) {
-            super();
             this.x = x;
             this.y = y;
@@ -1384,5 +1354,5 @@
         @Override
         public String toString() {
-            return "TilePosition [x=" + x + ", y=" + y + ", zoom=" + zoom + "]";
+            return "TilePosition [x=" + x + ", y=" + y + ", zoom=" + zoom + ']';
         }
     }
@@ -1448,6 +1418,5 @@
         public Stream<TilePosition> tilePositions() {
             if (this.insane()) {
-                // Tileset is either empty or too large
-                return Stream.empty();
+                return Stream.empty(); // Tileset is either empty or too large
             } else {
                 return super.tilePositions();
@@ -1489,6 +1458,5 @@
 
         /**
-         * Call the given paint method for all tiles in this tile set.
-         * <p>
+         * Call the given paint method for all tiles in this tile set.<p>
          * Uses a parallel stream.
          * @param visitor A visitor to call for each tile.
@@ -1711,6 +1679,5 @@
                 Tile t2 = tempCornerTile(missed);
                 TileSet ts2 = getTileSet(getShiftedLatLon(tileSource.tileXYToLatLon(missed)),
-                                         getShiftedLatLon(tileSource.tileXYToLatLon(t2)),
-                                         newzoom);
+                                         getShiftedLatLon(tileSource.tileXYToLatLon(t2)), newzoom);
                 // Instantiating large TileSets is expensive. If there are no loaded tiles, don't bother even trying.
                 if (ts2.allLoadedTiles().isEmpty()) {
@@ -1784,6 +1751,5 @@
         EastNorth topLeft = mv.getEastNorth(0, 0);
         EastNorth botRight = mv.getEastNorth(mv.getWidth(), mv.getHeight());
-        int z = currentZoomLevel;
-        TileSet ts = getTileSet(topLeft, botRight, z);
+        TileSet ts = getTileSet(topLeft, botRight, currentZoomLevel);
 
         if (!ts.tooLarge()) {
@@ -1860,6 +1826,5 @@
     @Override
     public boolean isChanged() {
-        // we use #invalidate()
-        return false;
+        return false; // we use #invalidate()
     }
 
@@ -1946,5 +1911,4 @@
                 (o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getKey(), o2.getKey()));
         for (LatLon point: points) {
-
             TileXY minTile = tileSource.latLonToTileXY(point.lat() - bufferY, point.lon() - bufferX, currentZoomLevel);
             TileXY curTile = tileSource.latLonToTileXY(point.toCoordinate(), currentZoomLevel);
@@ -1991,7 +1955,5 @@
 
     private class TileSourcePainter extends CompatibilityModeLayerPainter {
-        /**
-         * The memory handle that will hold our tile source.
-         */
+        /** The memory handle that will hold our tile source. */
         private MemoryHandle<?> memory;
 
@@ -2005,7 +1967,5 @@
 
         private void doPaint(MapViewGraphics graphics) {
-            ProjectionBounds pb = graphics.getClipBounds().getProjectionBounds();
-
-            drawInViewArea(graphics.getDefaultGraphics(), graphics.getMapView(), pb);
+            drawInViewArea(graphics.getDefaultGraphics(), graphics.getMapView(), graphics.getClipBounds().getProjectionBounds());
         }
 
