Changeset 17453 in josm for trunk/scripts


Ignore:
Timestamp:
2021-01-10T22:25:27+01:00 (3 years ago)
Author:
Don-vip
Message:

better comparison of WMS entries

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/SyncEditorLayerIndex.java

    r17332 r17453  
    539539    }
    540540
    541     // catch reordered arguments and switches to WMS version 1.3.0
     541    // catch reordered arguments, make them uppercase, and switches to WMS version 1.3.0
    542542    String unifyWMS(String url) {
    543         String[] x = url.replaceAll("(?i)VERSION=[0-9.]+", "VERSION=x").replaceAll("(?i)SRS=", "CRS=").split("\\?");
     543        String[] x = url.replaceAll("(?i)VERSION=[0-9.]+", "VERSION=x")
     544                        .replaceAll("(?i)SRS=", "CRS=")
     545                        .replaceAll("(?i)BBOX=", "BBOX=")
     546                        .replaceAll("(?i)FORMAT=", "FORMAT=")
     547                        .replaceAll("(?i)LAYERS=", "LAYERS=")
     548                        .replaceAll("(?i)MAP=", "MAP=")
     549                        .replaceAll("(?i)REQUEST=", "REQUEST=")
     550                        .replaceAll("(?i)SERVICE=", "SERVICE=")
     551                        .replaceAll("(?i)STYLES=", "STYLES=")
     552                        .replaceAll("(?i)TRANSPARENT=FALSE", "TRANSPARENT=FALSE")
     553                        .replaceAll("(?i)TRANSPARENT=TRUE", "TRANSPARENT=TRUE")
     554                        .replaceAll("(?i)WIDTH=", "WIDTH=")
     555                        .replaceAll("(?i)HEIGHT=", "HEIGHT=")
     556                        .split("\\?");
    544557        String[] a = x[1].split("&");
    545558        Arrays.sort(a);
     
    552565        List<String> lj = new LinkedList<>(josmUrls.keySet());
    553566
    554         List<String> ke = new LinkedList<>(le);
    555         for (String url : ke) {
     567        for (String url : new LinkedList<>(le)) {
    556568            if (lj.contains(url)) {
    557569                le.remove(url);
     
    561573
    562574        if (!le.isEmpty() && !lj.isEmpty()) {
    563             ke = new LinkedList<>(le);
     575            List<String> ke = new LinkedList<>(le);
    564576            for (String urle : ke) {
    565577                JsonObject e = eliUrls.get(urle);
     
    573585                    lj.remove(urlhttps);
    574586                } else if (isNotBlank(ide)) {
    575                     List<String> kj = new LinkedList<>(lj);
    576                     for (String urlj : kj) {
    577                         ImageryInfo j = josmUrls.get(urlj);
    578                         String idj = getId(j);
    579 
    580                         if (ide.equals(idj) && Objects.equals(getType(j), getType(e))) {
    581                             if (getType(j).equals("wms") && unifyWMS(urle).equals(unifyWMS(urlj))) {
    582                                 myprintln("# WMS-URL for id "+idj+" modified: "+getDescription(j));
    583                             } else {
    584                                 myprintln("* URL for id "+idj+" differs ("+urle+"): "+getDescription(j));
    585                             }
    586                             le.remove(urle);
    587                             lj.remove(urlj);
    588                             // replace key for this entry with JOSM URL
    589                             eliUrls.remove(urle);
    590                             eliUrls.put(urlj, e);
    591                             break;
    592                         }
    593                         Collection<String> old = j.getOldIds();
    594                         if (old != null) {
    595                             for (String oidj : old) {
    596                                 if (ide.equals(oidj) && Objects.equals(getType(j), getType(e))) {
    597                                     if (getType(j).equals("wms") && unifyWMS(urle).equals(unifyWMS(urlj))) {
    598                                         myprintln("# WMS-URL for oldid "+idj+" modified: "+getDescription(j));
    599                                     } else {
    600                                         myprintln("* URL for oldid "+idj+" differs ("+urle+"): "+getDescription(j));
    601                                     }
    602                                     le.remove(urle);
    603                                     lj.remove(urlj);
    604                                     // replace key for this entry with JOSM URL
    605                                     eliUrls.remove(urle);
    606                                     eliUrls.put(urlj, e);
    607                                     break;
    608                                 }
    609                             }
    610                         }
    611                     }
     587                    checkUrlsEquality(ide, e, urle, le, lj);
    612588                }
    613589            }
     
    628604            }
    629605        }
     606    }
     607
     608    void checkUrlsEquality(String ide, JsonObject e, String urle, List<String> le, List<String> lj) {
     609        for (String urlj : new LinkedList<>(lj)) {
     610            ImageryInfo j = josmUrls.get(urlj);
     611            String idj = getId(j);
     612
     613            if (checkUrlEquality(ide, "id", idj, e, j, urle, urlj, le, lj)) {
     614                return;
     615            }
     616            Collection<String> old = j.getOldIds();
     617            if (old != null) {
     618                for (String oidj : old) {
     619                    if (checkUrlEquality(ide, "oldid", oidj, e, j, urle, urlj, le, lj)) {
     620                        return;
     621                    }
     622                }
     623            }
     624        }
     625    }
     626
     627    boolean checkUrlEquality(
     628            String ide, String idtype, String idj, JsonObject e, ImageryInfo j, String urle, String urlj, List<String> le, List<String> lj) {
     629        if (ide.equals(idj) && Objects.equals(getType(j), getType(e))) {
     630            if (getType(j).equals("wms") && unifyWMS(urle).equals(unifyWMS(urlj))) {
     631                myprintln("# WMS-URL for "+idtype+" "+idj+" modified: "+getDescription(j));
     632            } else {
     633                myprintln("* URL for "+idtype+" "+idj+" differs ("+urle+"): "+getDescription(j));
     634            }
     635            le.remove(urle);
     636            lj.remove(urlj);
     637            // replace key for this entry with JOSM URL
     638            eliUrls.remove(urle);
     639            eliUrls.put(urlj, e);
     640            return true;
     641        }
     642        return false;
    630643    }
    631644
Note: See TracChangeset for help on using the changeset viewer.