diff options
| author | Bananeweizen <Bananeweizen@gmx.de> | 2012-11-27 08:27:35 +0100 |
|---|---|---|
| committer | Bananeweizen <Bananeweizen@gmx.de> | 2012-11-27 08:30:39 +0100 |
| commit | 06608af852274ce5c394e647795c1763e2509080 (patch) | |
| tree | 3063ea69bf981320d074f407628cec095d635047 | |
| parent | c12ea0b48ac22c1ca6aec4897eb8eff08a0b747b (diff) | |
| download | cgeo-06608af852274ce5c394e647795c1763e2509080.zip cgeo-06608af852274ce5c394e647795c1763e2509080.tar.gz cgeo-06608af852274ce5c394e647795c1763e2509080.tar.bz2 | |
fix #2202: logs duplicated after importing GPX twice
| -rw-r--r-- | main/src/cgeo/geocaching/cgCache.java | 23 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/files/GPXParser.java | 5 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/files/GPXParserTest.java | 17 |
3 files changed, 40 insertions, 5 deletions
diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java index bb167bd..7035d65 100644 --- a/main/src/cgeo/geocaching/cgCache.java +++ b/main/src/cgeo/geocaching/cgCache.java @@ -19,6 +19,7 @@ import cgeo.geocaching.enumerations.LoadFlags.RemoveFlag; import cgeo.geocaching.enumerations.LoadFlags.SaveFlag; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.enumerations.WaypointType; +import cgeo.geocaching.files.GPXParser; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.network.HtmlImage; import cgeo.geocaching.utils.CancellableHandler; @@ -130,6 +131,26 @@ public class cgCache implements ICache, IWaypoint { private Handler changeNotificationHandler = null; + /** + * Create a new cache. To be used everywhere except for the GPX parser + */ + public cgCache() { + // empty + } + + /** + * Cache constructor to be used by the GPX parser only. This constructor explicitly sets several members to empty + * lists. + * + * @param gpxParser + */ + public cgCache(GPXParser gpxParser) { + setReliableLatLon(true); + setAttributes(Collections.<String> emptyList()); + setWaypoints(Collections.<cgWaypoint> emptyList(), false); + setLogs(Collections.<LogEntry> emptyList()); + } + public void setChangeNotificationHandler(Handler newNotificationHandler) { changeNotificationHandler = newNotificationHandler; } @@ -1612,4 +1633,4 @@ public class cgCache implements ICache, IWaypoint { } return result; } -}
\ No newline at end of file +} diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java index 221aa1e..b9d3f53 100644 --- a/main/src/cgeo/geocaching/files/GPXParser.java +++ b/main/src/cgeo/geocaching/files/GPXParser.java @@ -854,10 +854,7 @@ public abstract class GPXParser extends FileParser { desc = null; cmt = null; - cache = new cgCache(); - cache.setReliableLatLon(true); - cache.setAttributes(new ArrayList<String>()); - cache.setWaypoints(new ArrayList<cgWaypoint>(), false); + cache = new cgCache(this); for (int i = 0; i < userData.length; i++) { userData[i] = null; } diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java index 197de26..6c3c237 100644 --- a/tests/src/cgeo/geocaching/files/GPXParserTest.java +++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java @@ -277,6 +277,23 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase { removeCacheCompletely(geocode); } + public void testDuplicateImport() throws IOException, ParserException { + final String geocode = "GC31J2H"; + removeCacheCompletely(geocode); + + // first import + List<cgCache> caches = readGPX10(R.raw.lazy); + assertEquals(1, caches.size()); + assertEquals(6, caches.get(0).getLogs().size()); + + // second import + caches = readGPX10(R.raw.lazy); + assertEquals(1, caches.size()); + assertEquals(6, caches.get(0).getLogs().size()); + + removeCacheCompletely(geocode); + } + @Override protected void setUp() throws Exception { super.setUp(); |
