Changeset 9768 in josm for trunk


Ignore:
Timestamp:
2016-02-09T16:14:28+01:00 (9 years ago)
Author:
simon04
Message:

Avoid array creation for every WMTSTileSource.getTileMatrix call

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java

    r9664 r9768  
    1313import java.util.ArrayList;
    1414import java.util.Collection;
     15import java.util.Collections;
    1516import java.util.Comparator;
    1617import java.util.HashSet;
     18import java.util.List;
    1719import java.util.Map;
    1820import java.util.Set;
     
    8082    }
    8183
    82     private static class TileMatrixSet {
     84    private static class TileMatrixSetBuilder {
    8385        SortedSet<TileMatrix> tileMatrix = new TreeSet<>(new Comparator<TileMatrix>() {
    8486            @Override
     
    9193        private String identifier;
    9294
     95        TileMatrixSet build() {
     96            return new TileMatrixSet(this);
     97        }
     98    }
     99
     100    private static class TileMatrixSet {
     101
     102        private final List<TileMatrix> tileMatrix;
     103        private final String crs;
     104        private final String identifier;
     105
    93106        TileMatrixSet(TileMatrixSet tileMatrixSet) {
    94107            if (tileMatrixSet != null) {
    95                 tileMatrix = new TreeSet<>(tileMatrixSet.tileMatrix);
     108                tileMatrix = new ArrayList<>(tileMatrixSet.tileMatrix);
    96109                crs = tileMatrixSet.crs;
    97110                identifier = tileMatrixSet.identifier;
    98             }
    99         }
    100 
    101         TileMatrixSet() {
     111            } else {
     112                tileMatrix = Collections.emptyList();
     113                crs = null;
     114                identifier = null;
     115            }
     116        }
     117
     118        TileMatrixSet(TileMatrixSetBuilder builder) {
     119            tileMatrix = new ArrayList<>(builder.tileMatrix);
     120            crs = builder.crs;
     121            identifier = builder.identifier;
    102122        }
    103123
     
    405425     */
    406426    private static TileMatrixSet parseTileMatrixSet(XMLStreamReader reader) throws XMLStreamException {
    407         TileMatrixSet matrixSet = new TileMatrixSet();
     427        TileMatrixSetBuilder matrixSet = new TileMatrixSetBuilder();
    408428        for (int event = reader.getEventType();
    409429                reader.hasNext() && !(event == XMLStreamReader.END_ELEMENT && new QName(WMTS_NS_URL, "TileMatrixSet").equals(reader.getName()));
     
    421441                    }
    422442        }
    423         return matrixSet;
     443        return matrixSet.build();
    424444    }
    425445
     
    637657        Collection<Layer> layers = getLayers(null, Main.getProjection().toCode());
    638658        if (!layers.isEmpty()) {
    639             return layers.iterator().next().tileMatrixSet.tileMatrix.first().tileHeight;
     659            return layers.iterator().next().tileMatrixSet.tileMatrix.get(0).tileHeight;
    640660        }
    641661        // if no layers is found, fallback to default mercator tile size. Maybe it will work
     
    694714            return null;
    695715        }
    696         return this.currentTileMatrixSet.tileMatrix.toArray(new TileMatrix[]{})[zoom - 1];
     716        return this.currentTileMatrixSet.tileMatrix.get(zoom - 1);
    697717    }
    698718
Note: See TracChangeset for help on using the changeset viewer.