diff options
author | Bananeweizen <Bananeweizen@gmx.de> | 2011-12-26 09:31:06 +0100 |
---|---|---|
committer | Bananeweizen <Bananeweizen@gmx.de> | 2011-12-26 09:31:06 +0100 |
commit | 8f749cf471fd30df55c4206d58abe69637988330 (patch) | |
tree | ed112bc2267a5d1439d190ce308193ec6454876d /main/src/cgeo/geocaching/files | |
parent | 85591bf9a7b727536942d7b9c7afe53fc6a026a4 (diff) | |
download | cgeo-8f749cf471fd30df55c4206d58abe69637988330.zip cgeo-8f749cf471fd30df55c4206d58abe69637988330.tar.gz cgeo-8f749cf471fd30df55c4206d58abe69637988330.tar.bz2 |
refactoring for #908: waypoint list of cache is immutable for clients
and never null
* avoids initializations outside of cache
* avoids tempering with internal data outside of cache
* removes redundant code and null checks
Diffstat (limited to 'main/src/cgeo/geocaching/files')
-rw-r--r-- | main/src/cgeo/geocaching/files/GPXParser.java | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java index 9eab5df..72fd63f 100644 --- a/main/src/cgeo/geocaching/files/GPXParser.java +++ b/main/src/cgeo/geocaching/files/GPXParser.java @@ -305,21 +305,20 @@ public abstract class GPXParser extends FileParser { // lookup cache for waypoint in already parsed caches final cgCache cacheForWaypoint = result.get(cacheGeocodeForWaypoint); if (cacheForWaypoint != null) { - final cgWaypoint waypoint = new cgWaypoint(); + final cgWaypoint waypoint = new cgWaypoint(cache.getShortdesc(), convertWaypointSym2Type(sym)); waypoint.setId(-1); - waypoint.setWaypointType(convertWaypointSym2Type(sym)); waypoint.setGeocode(cacheGeocodeForWaypoint); waypoint.setPrefix(cache.getName().substring(0, 2)); waypoint.setLookup("---"); // there is no lookup code in gpx file - waypoint.setName(cache.getShortdesc()); waypoint.setCoords(cache.getCoords()); waypoint.setNote(cache.getDescription()); - if (cacheForWaypoint.getWaypoints() == null) { - cacheForWaypoint.setWaypoints(new ArrayList<cgWaypoint>()); - } - cgWaypoint.mergeWayPoints(cacheForWaypoint.getWaypoints(), Collections.singletonList(waypoint), true); + ArrayList<cgWaypoint> mergedWayPoints = new ArrayList<cgWaypoint>(); + mergedWayPoints.addAll(cacheForWaypoint.getWaypoints()); + + cgWaypoint.mergeWayPoints(mergedWayPoints, Collections.singletonList(waypoint), true); + cacheForWaypoint.setWaypoints(mergedWayPoints); result.put(cacheGeocodeForWaypoint, cacheForWaypoint); showProgressMessage(progressHandler, progressStream.getProgress()); } |