[Git][debian-gis-team/jmapviewer][upstream] New upstream version 2.14+dfsg

Bas Couwenberg gitlab at salsa.debian.org
Sat May 30 06:05:46 BST 2020



Bas Couwenberg pushed to branch upstream at Debian GIS Project / jmapviewer


Commits:
6445c402 by Bas Couwenberg at 2020-05-30T06:56:05+02:00
New upstream version 2.14+dfsg
- - - - -


4 changed files:

- src/org/openstreetmap/gui/jmapviewer/Coordinate.java
- src/org/openstreetmap/gui/jmapviewer/Projected.java
- src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java
- src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java


Changes:

=====================================
src/org/openstreetmap/gui/jmapviewer/Coordinate.java
=====================================
@@ -1,23 +1,24 @@
 // License: GPL. For details, see Readme.txt file.
 package org.openstreetmap.gui.jmapviewer;
 
-import java.awt.geom.Point2D;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.io.Serializable;
 import java.util.Objects;
 
 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
 
 /**
- * This class encapsulates a Point2D.Double and provide access
- * via <code>lat</code> and <code>lon</code>.
+ * A geographical coordinate consisting of latitude and longitude.
  *
  * @author Jan Peter Stotz
  *
  */
-public class Coordinate implements ICoordinate {
-    private transient Point2D.Double data;
+public class Coordinate implements ICoordinate, Serializable {
+    private static final long serialVersionUID = 1L;
+    private double x;
+    private double y;
 
     /**
      * Constructs a new {@code Coordinate}.
@@ -25,57 +26,55 @@ public class Coordinate implements ICoordinate {
      * @param lon longitude in degrees
      */
     public Coordinate(double lat, double lon) {
-        data = new Point2D.Double(lon, lat);
+        setLat(lat);
+        setLon(lon);
     }
 
     @Override
     public double getLat() {
-        return data.y;
+        return y;
     }
 
     @Override
     public void setLat(double lat) {
-        data.y = lat;
+        y = lat;
     }
 
     @Override
     public double getLon() {
-        return data.x;
+        return x;
     }
 
     @Override
     public void setLon(double lon) {
-        data.x = lon;
+        x = lon;
     }
 
     private void writeObject(ObjectOutputStream out) throws IOException {
-        out.writeObject(data.x);
-        out.writeObject(data.y);
+        out.writeObject(x);
+        out.writeObject(y);
     }
 
     private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
-        data = new Point2D.Double();
-        data.x = (Double) in.readObject();
-        data.y = (Double) in.readObject();
+        x = (Double) in.readObject();
+        y = (Double) in.readObject();
     }
 
     @Override
     public String toString() {
-        return "Coordinate[" + data.y + ", " + data.x + ']';
+        return "Coordinate[" + y + ", " + x + ']';
     }
 
     @Override
     public int hashCode() {
-        return Objects.hashCode(data);
+        return Objects.hash(x, y);
     }
 
     @Override
-    public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null || !(obj instanceof Coordinate))
-            return false;
-        final Coordinate other = (Coordinate) obj;
-        return Objects.equals(data, other.data);
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (!(o instanceof Coordinate)) return false;
+        Coordinate that = (Coordinate) o;
+        return Double.compare(that.x, x) == 0 && Double.compare(that.y, y) == 0;
     }
 }


=====================================
src/org/openstreetmap/gui/jmapviewer/Projected.java
=====================================
@@ -5,6 +5,7 @@ import java.awt.geom.Point2D;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.io.Serializable;
 import java.util.Objects;
 
 import org.openstreetmap.gui.jmapviewer.interfaces.IProjected;
@@ -12,7 +13,8 @@ import org.openstreetmap.gui.jmapviewer.interfaces.IProjected;
 /**
  * Projected coordinates represented by an encapsulates a Point2D.Double value.
  */
-public class Projected implements IProjected {
+public class Projected implements IProjected, Serializable {
+    private static final long serialVersionUID = 1L;
     private transient Point2D.Double data;
 
     /**
@@ -59,7 +61,7 @@ public class Projected implements IProjected {
     public boolean equals(Object obj) {
         if (this == obj)
             return true;
-        if (obj == null || !(obj instanceof Projected))
+        if (!(obj instanceof Projected))
             return false;
         final Projected other = (Projected) obj;
         return Objects.equals(data, other.data);


=====================================
src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java
=====================================
@@ -16,6 +16,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.regex.Pattern;
+import java.util.stream.Collectors;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -50,7 +51,7 @@ public class BingAerialTileSource extends TMSTileSource {
     /** Setting key for Bing API key */
     public static final String API_KEY_SETTING = "jmapviewer.bing.api-key";
     /** Placeholder to specify Bing API key in metadata API URL*/
-    public static final String API_KEY_PLACEHOLDER = "{apiKey}";
+    public static final String API_KEY_PLACEHOLDER = "{apikey}";
 
     /** Bing Metadata API URL */
     private static final String METADATA_API_URL =
@@ -289,17 +290,12 @@ public class BingAerialTileSource extends TMSTileSource {
             final List<Attribution> data = getAttribution();
             if (data == null)
                 return "Error loading Bing attribution data";
-            StringBuilder a = new StringBuilder();
-            for (Attribution attr : data) {
-                if (zoom <= attr.maxZoom && zoom >= attr.minZoom) {
-                    if (topLeft.getLon() < attr.max.getLon() && botRight.getLon() > attr.min.getLon()
-                            && topLeft.getLat() > attr.min.getLat() && botRight.getLat() < attr.max.getLat()) {
-                        a.append(attr.attributionText);
-                        a.append(' ');
-                    }
-                }
-            }
-            return a.toString();
+            return data.stream()
+                    .filter(attr -> zoom <= attr.maxZoom && zoom >= attr.minZoom)
+                    .filter(attr -> topLeft.getLon() < attr.max.getLon() && botRight.getLon() > attr.min.getLon())
+                    .filter(attr -> topLeft.getLat() > attr.min.getLat() && botRight.getLat() < attr.max.getLat())
+                    .map(attr -> attr.attributionText)
+                    .collect(Collectors.joining(" "));
         } catch (RuntimeException e) {
             e.printStackTrace();
         }


=====================================
src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java
=====================================
@@ -2,6 +2,7 @@
 package org.openstreetmap.gui.jmapviewer.tilesources;
 
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Random;
@@ -27,7 +28,7 @@ import org.openstreetmap.gui.jmapviewer.interfaces.TemplatedTileSource;
  * {y} - substituted with Y tile number
  * {!y} - substituted with Yahoo Y tile number
  * {-y} - substituted with reversed Y tile number
- * {apiKey} - substituted with API key retrieved for the imagery id
+ * {apikey} - substituted with API key retrieved for the imagery id
  * {switch:VAL_A,VAL_B,VAL_C,...} - substituted with one of VAL_A, VAL_B, VAL_C. Usually
  *                                  used to specify many tile servers
  * {header:(HEADER_NAME,HEADER_VALUE)} - sets the headers to be sent to tile server
@@ -49,7 +50,7 @@ public class TemplatedTMSTileSource extends TMSTileSource implements TemplatedTi
     private static final Pattern PATTERN_NEG_Y   = Pattern.compile("\\{-y\\}");
     private static final Pattern PATTERN_SWITCH  = Pattern.compile("\\{switch:([^}]+)\\}");
     private static final Pattern PATTERN_HEADER  = Pattern.compile("\\{header\\(([^,]+),([^}]+)\\)\\}");
-    private static final Pattern PATTERN_API_KEY = Pattern.compile("\\{apiKey\\}");
+    private static final Pattern PATTERN_API_KEY = Pattern.compile("\\{apikey\\}");
     private static final Pattern PATTERN_PARAM  = Pattern.compile("\\{((?:\\d+-)?z(?:oom)?(:?[+-]\\d+)?|x|y|!y|-y|switch:([^}]+))\\}");
 
     /**
@@ -137,7 +138,7 @@ public class TemplatedTMSTileSource extends TMSTileSource implements TemplatedTi
         StringBuffer url = new StringBuffer(baseUrl.length());
         Matcher matcher = PATTERN_PARAM.matcher(baseUrl);
         while (matcher.find()) {
-            String replacement = "replace";
+            final String replacement;
             switch (matcher.group(1)) {
             case "z": // PATTERN_ZOOM
             case "zoom":
@@ -156,14 +157,14 @@ public class TemplatedTMSTileSource extends TMSTileSource implements TemplatedTi
                 replacement = Integer.toString((int) Math.pow(2, zoom)-1-tiley);
                 break;
             case "switch:":
-                replacement = randomParts[rand.nextInt(randomParts.length)];
+                replacement = getRandomPart(randomParts);
                 break;
             default:
                 // handle switch/zoom here, as group will contain parameters and switch will not work
                 if (PATTERN_ZOOM.matcher("{" + matcher.group(1) + "}").matches()) {
                     replacement = Integer.toString((inverse_zoom ? -1 * zoom : zoom) + zoom_offset);
                 } else if (PATTERN_SWITCH.matcher("{" + matcher.group(1) + "}").matches()) {
-                    replacement = randomParts[rand.nextInt(randomParts.length)];
+                    replacement = getRandomPart(randomParts);
                 } else {
                     replacement = '{' + matcher.group(1) + '}';
                 }
@@ -174,6 +175,10 @@ public class TemplatedTMSTileSource extends TMSTileSource implements TemplatedTi
         return url.toString().replace(" ", "%20");
     }
 
+    protected String getRandomPart(final String[] parts) {
+        return parts[rand.nextInt(parts.length)];
+    }
+
     /**
      * Checks if url is acceptable by this Tile Source
      * @param url URL to check
@@ -182,13 +187,7 @@ public class TemplatedTMSTileSource extends TMSTileSource implements TemplatedTi
         assert url != null && !"".equals(url) : "URL cannot be null or empty";
         Matcher m = Pattern.compile("\\{[^}]*\\}").matcher(url);
         while (m.find()) {
-            boolean isSupportedPattern = false;
-            for (Pattern pattern : ALL_PATTERNS) {
-                if (pattern.matcher(m.group()).matches()) {
-                    isSupportedPattern = true;
-                    break;
-                }
-            }
+            boolean isSupportedPattern = Arrays.stream(ALL_PATTERNS).anyMatch(pattern -> pattern.matcher(m.group()).matches());
             if (!isSupportedPattern) {
                 throw new IllegalArgumentException(
                         m.group() + " is not a valid TMS argument. Please check this server URL:\n" + url);



View it on GitLab: https://salsa.debian.org/debian-gis-team/jmapviewer/-/commit/6445c402b868ea8693d07a590cb19150b3fbc010

-- 
View it on GitLab: https://salsa.debian.org/debian-gis-team/jmapviewer/-/commit/6445c402b868ea8693d07a590cb19150b3fbc010
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-grass-devel/attachments/20200530/f78693b6/attachment-0001.html>


More information about the Pkg-grass-devel mailing list