Ignore:
Timestamp:
2010-01-15T21:42:20+01:00 (15 years ago)
Author:
jttt
Message:

Cache route information when dataset didn't changed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/PathBuilder.java

    r17380 r19532  
    1414public class PathBuilder {
    1515
    16         private Map<Way, BitSet> wayRoutes = new HashMap<Way, BitSet>();
     16        private Map<Way, BitSet> wayRoutes = new HashMap<Way, BitSet>();
     17        private Collection<ConvertedWay> convertedWays;
    1718
    1819        public void addWay(Way way, RouteDefinition route) {
     
    3031
    3132        public Collection<ConvertedWay> getConvertedWays() {
    32                 Map<WayEnd, ConvertedWay> ways = new HashMap<WayEnd, ConvertedWay>();
     33                if (convertedWays == null) {
     34                        Map<WayEnd, ConvertedWay> ways = new HashMap<WayEnd, ConvertedWay>();
    3335
    34                 for (Entry<Way, BitSet> wayEntry:wayRoutes.entrySet()) {
    35                         ConvertedWay way = new ConvertedWay(wayEntry.getValue(), wayEntry.getKey());
     36                        for (Entry<Way, BitSet> wayEntry:wayRoutes.entrySet()) {
     37                                ConvertedWay way = new ConvertedWay(wayEntry.getValue(), wayEntry.getKey());
    3638
    37                         ConvertedWay wayBefore = ways.get(way.getStart());
    38                         ConvertedWay wayAfter = ways.get(way.getStop());
     39                                ConvertedWay wayBefore = ways.get(way.getStart());
     40                                ConvertedWay wayAfter = ways.get(way.getStop());
    3941
    40                         if (wayBefore != null) {
    41                                 removeWay(ways, wayBefore);
    42                                 way.connect(wayBefore);
    43                         }
     42                                if (wayBefore != null) {
     43                                        removeWay(ways, wayBefore);
     44                                        way.connect(wayBefore);
     45                                }
    4446
    45                         if (wayAfter != null) {
    46                                 removeWay(ways, wayAfter);
    47                                 way.connect(wayAfter);
     47                                if (wayAfter != null) {
     48                                        removeWay(ways, wayAfter);
     49                                        way.connect(wayAfter);
     50                                }
     51
     52                                ways.put(way.getStart(), way);
     53                                ways.put(way.getStop(), way);
    4854                        }
    4955
    50                         ways.put(way.getStart(), way);
    51                         ways.put(way.getStop(), way);
     56                        Set<ConvertedWay> uniqueWays = new HashSet<ConvertedWay>();
     57                        uniqueWays.addAll(ways.values());
     58                        convertedWays = uniqueWays;
    5259                }
    53 
    54                 Set<ConvertedWay> uniqueWays = new HashSet<ConvertedWay>();
    55                 uniqueWays.addAll(ways.values());
    56                 return uniqueWays;
     60                return convertedWays;
    5761        }
    5862
     
    6367
    6468        public void clear() {
     69                convertedWays = null;
    6570                wayRoutes.clear();
    6671        }
Note: See TracChangeset for help on using the changeset viewer.