aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/Geocache.java
diff options
context:
space:
mode:
authorrsudev <rasch@munin-soft.de>2013-11-26 23:57:26 +0100
committerrsudev <rasch@munin-soft.de>2013-11-26 23:57:26 +0100
commitc75f89dba2712cba5bc8cec02479cac43197e65c (patch)
tree919caa3bd6cbd74d4e54b26d911bff862c33bce7 /main/src/cgeo/geocaching/Geocache.java
parentdceae79fd9bc1b4f12a5e35390d5be5c209201b7 (diff)
downloadcgeo-c75f89dba2712cba5bc8cec02479cac43197e65c.zip
cgeo-c75f89dba2712cba5bc8cec02479cac43197e65c.tar.gz
cgeo-c75f89dba2712cba5bc8cec02479cac43197e65c.tar.bz2
Fix #3441, 'Visited' not saved for own waypoints
To disambiguate own waypoints in merge, generate a unique prefix on addition to the cache
Diffstat (limited to 'main/src/cgeo/geocaching/Geocache.java')
-rw-r--r--main/src/cgeo/geocaching/Geocache.java33
1 files changed, 32 insertions, 1 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java
index 731f214..c589e9b 100644
--- a/main/src/cgeo/geocaching/Geocache.java
+++ b/main/src/cgeo/geocaching/Geocache.java
@@ -53,9 +53,11 @@ import java.util.Collections;
import java.util.Date;
import java.util.EnumSet;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Set;
import java.util.regex.Pattern;
/**
@@ -63,6 +65,7 @@ import java.util.regex.Pattern;
*/
public class Geocache implements ICache, IWaypoint {
+ private static final int OWN_WP_PREFIX_OFFSET = 17;
private long updated = 0;
private long detailedUpdate = 0;
private long visitedDate = 0;
@@ -1209,6 +1212,7 @@ public class Geocache implements ICache, IWaypoint {
waypoint.setGeocode(geocode);
if (waypoint.getId() < 0) { // this is a new waypoint
+ assignUniquePrefix(waypoint);
waypoints.add(waypoint);
if (waypoint.isFinalWithCoords()) {
finalDefined = true;
@@ -1216,7 +1220,13 @@ public class Geocache implements ICache, IWaypoint {
} else { // this is a waypoint being edited
final int index = getWaypointIndex(waypoint);
if (index >= 0) {
- waypoints.remove(index);
+ Waypoint oldWaypoint = waypoints.remove(index);
+ waypoint.setPrefix(oldWaypoint.getPrefix());
+ //migration
+ if (StringUtils.isBlank(waypoint.getPrefix())
+ || StringUtils.equalsIgnoreCase(waypoint.getPrefix(), Waypoint.PREFIX_OWN)) {
+ assignUniquePrefix(waypoint);
+ }
}
waypoints.add(waypoint);
// when waypoint was edited, finalDefined may have changed
@@ -1225,6 +1235,27 @@ public class Geocache implements ICache, IWaypoint {
return saveToDatabase && DataStore.saveWaypoint(waypoint.getId(), geocode, waypoint);
}
+ /*
+ * Assigns a unique two-digit (compatibility with gc.com)
+ * prefix within the scope of this cache.
+ */
+ private void assignUniquePrefix(Waypoint waypoint) {
+ // gather existing prefixes
+ Set<String> assignedPrefixes = new HashSet<String>();
+ for (Waypoint wp : waypoints) {
+ assignedPrefixes.add(wp.getPrefix());
+ }
+
+ for (int i = OWN_WP_PREFIX_OFFSET; i < 100; i++) {
+ String prefixCandidate = StringUtils.leftPad(String.valueOf(i), 2, '0');
+ if (!assignedPrefixes.contains(prefixCandidate)) {
+ waypoint.setPrefix(prefixCandidate);
+ break;
+ }
+ }
+
+ }
+
public boolean hasWaypoints() {
return !waypoints.isEmpty();
}