aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2011-09-15 14:22:12 +0200
committerSamuel Tardieu <sam@rfc1149.net>2011-09-15 14:22:12 +0200
commit42b8d8542e4056ece23af2ff8ee2b5db8abe832b (patch)
tree56c11689351fec9d7366f24ffae4151ea4e69c9f /src
parent5e69149eb306e5f43c7339c68b88dd5b3312010c (diff)
parenta97f03151faed72242a99b70b7f2277e0731c802 (diff)
downloadcgeo-42b8d8542e4056ece23af2ff8ee2b5db8abe832b.zip
cgeo-42b8d8542e4056ece23af2ff8ee2b5db8abe832b.tar.gz
cgeo-42b8d8542e4056ece23af2ff8ee2b5db8abe832b.tar.bz2
Merge branch 'constants-for-cache-size' into upstream
Diffstat (limited to 'src')
-rw-r--r--src/cgeo/geocaching/ICache.java4
-rw-r--r--src/cgeo/geocaching/apps/AbstractLocusApp.java6
-rw-r--r--src/cgeo/geocaching/cgBase.java29
-rw-r--r--src/cgeo/geocaching/cgCache.java7
-rw-r--r--src/cgeo/geocaching/cgCacheListAdapter.java4
-rw-r--r--src/cgeo/geocaching/cgCoord.java3
-rw-r--r--src/cgeo/geocaching/cgData.java5
-rw-r--r--src/cgeo/geocaching/cgeocaches.java22
-rw-r--r--src/cgeo/geocaching/cgeodetail.java7
-rw-r--r--src/cgeo/geocaching/cgeopopup.java8
-rw-r--r--src/cgeo/geocaching/enumerations/CacheSize.java29
-rw-r--r--src/cgeo/geocaching/enumerations/CacheType.java42
-rw-r--r--src/cgeo/geocaching/enumerations/WaypointType.java30
-rw-r--r--src/cgeo/geocaching/files/GPXParser.java3
-rw-r--r--src/cgeo/geocaching/files/LocParser.java17
-rw-r--r--src/cgeo/geocaching/filter/cgFilterBySize.java16
-rw-r--r--src/cgeo/geocaching/sorting/SizeComparator.java35
17 files changed, 132 insertions, 135 deletions
diff --git a/src/cgeo/geocaching/ICache.java b/src/cgeo/geocaching/ICache.java
index 128664d..24dcd7c 100644
--- a/src/cgeo/geocaching/ICache.java
+++ b/src/cgeo/geocaching/ICache.java
@@ -3,6 +3,8 @@
*/
package cgeo.geocaching;
+import cgeo.geocaching.enumerations.CacheSize;
+
/**
* Basic interface for caches
*
@@ -34,7 +36,7 @@ public interface ICache {
/**
* @return Micro, small etc.
*/
- public String getSize();
+ public CacheSize getSize();
/**
* @return Difficulty assessment
diff --git a/src/cgeo/geocaching/apps/AbstractLocusApp.java b/src/cgeo/geocaching/apps/AbstractLocusApp.java
index f57987a..caa9549 100644
--- a/src/cgeo/geocaching/apps/AbstractLocusApp.java
+++ b/src/cgeo/geocaching/apps/AbstractLocusApp.java
@@ -123,11 +123,11 @@ public abstract class AbstractLocusApp extends AbstractApp {
if (cache.hidden != null) {
pg.hidden = ISO8601DATE.format(cache.hidden.getTime());
}
- int locusId = toLocusId(CacheType.FIND_BY_CGEOID.get(cache.type));
+ int locusId = toLocusId(CacheType.FIND_BY_ID.get(cache.type));
if (locusId != NO_LOCUS_ID) {
pg.type = locusId;
}
- locusId = toLocusId(CacheSize.FIND_BY_CGEOID.get(cache.size));
+ locusId = toLocusId(CacheSize.FIND_BY_ID.get(cache.size));
if (locusId != NO_LOCUS_ID) {
pg.container = locusId;
}
@@ -148,7 +148,7 @@ public abstract class AbstractLocusApp extends AbstractApp {
PointGeocachingDataWaypoint wp = new PointGeocachingDataWaypoint();
wp.code = waypoint.geocode;
wp.name = waypoint.name;
- String locusWpId = toLocusId(WaypointType.FIND_BY_CGEOID.get(waypoint.type));
+ String locusWpId = toLocusId(WaypointType.FIND_BY_ID.get(waypoint.type));
if (locusWpId != null) {
wp.type = locusWpId;
}
diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java
index a5f8af7..c1ef6b8 100644
--- a/src/cgeo/geocaching/cgBase.java
+++ b/src/cgeo/geocaching/cgBase.java
@@ -1,7 +1,9 @@
package cgeo.geocaching;
import cgeo.geocaching.activity.ActivityMixin;
+import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
+import cgeo.geocaching.enumerations.WaypointType;
import cgeo.geocaching.files.LocParser;
import cgeo.geocaching.geopoint.DistanceParser;
import cgeo.geocaching.geopoint.Geopoint;
@@ -135,6 +137,7 @@ public class cgBase {
public final static Map<String, String> cacheTypesInv = new HashMap<String, String>();
public final static Map<String, String> cacheIDs = new HashMap<String, String>();
public final static Map<String, String> cacheIDsChoices = new HashMap<String, String>();
+ public final static Map<CacheSize, String> cacheSizesInv = new HashMap<CacheSize, String>();
public final static Map<String, String> waypointTypes = new HashMap<String, String>();
public final static Map<String, Integer> logTypes = new HashMap<String, Integer>();
public final static Map<String, Integer> logTypes0 = new HashMap<String, Integer>();
@@ -224,19 +227,23 @@ public class cgBase {
for (CacheType ct : CacheType.values()) {
String l10n = res.getString(ct.stringId);
- cacheTypes.put(ct.pattern, ct.cgeoId);
- cacheTypesInv.put(ct.cgeoId, l10n);
- cacheIDs.put(ct.cgeoId, ct.guid);
+ cacheTypes.put(ct.pattern, ct.id);
+ cacheTypesInv.put(ct.id, l10n);
+ cacheIDs.put(ct.id, ct.guid);
cacheIDsChoices.put(l10n, ct.guid);
}
+ for (CacheSize cs : CacheSize.values()) {
+ cacheSizesInv.put(cs, res.getString(cs.stringId));
+ }
+
// waypoint types
- waypointTypes.put("flag", res.getString(R.string.wp_final));
- waypointTypes.put("stage", res.getString(R.string.wp_stage));
- waypointTypes.put("puzzle", res.getString(R.string.wp_puzzle));
- waypointTypes.put("pkg", res.getString(R.string.wp_pkg));
- waypointTypes.put("trailhead", res.getString(R.string.wp_trailhead));
- waypointTypes.put("waypoint", res.getString(R.string.wp_waypoint));
+ waypointTypes.put("flag", res.getString(WaypointType.FLAG.stringId));
+ waypointTypes.put("stage", res.getString(WaypointType.STAGE.stringId));
+ waypointTypes.put("puzzle", res.getString(WaypointType.PUZZLE.stringId));
+ waypointTypes.put("pkg", res.getString(WaypointType.PKG.stringId));
+ waypointTypes.put("trailhead", res.getString(WaypointType.TRAILHEAD.stringId));
+ waypointTypes.put("waypoint", res.getString(WaypointType.WAYPOINT.stringId));
// log types
logTypes.put("icon_smile", LOG_FOUND_IT);
@@ -1248,7 +1255,7 @@ public class cgBase {
try {
final Matcher matcherSize = patternSize.matcher(tableInside);
if (matcherSize.find() && matcherSize.groupCount() > 0) {
- cache.size = getMatch(matcherSize.group(1)).toLowerCase();
+ cache.size = CacheSize.FIND_BY_ID.get(getMatch(matcherSize.group(1)).toLowerCase());
}
} catch (Exception e) {
// failed to parse size
@@ -1756,7 +1763,7 @@ public class cgBase {
if (cache.favouriteCnt == null) {
Log.w(cgSettings.tag, "favoriteCount not parsed correctly");
}
- if (StringUtils.isBlank(cache.size)) {
+ if (cache.size == null) {
Log.w(cgSettings.tag, "size not parsed correctly");
}
if (StringUtils.isBlank(cache.type)) {
diff --git a/src/cgeo/geocaching/cgCache.java b/src/cgeo/geocaching/cgCache.java
index 4a2243d..68aaf49 100644
--- a/src/cgeo/geocaching/cgCache.java
+++ b/src/cgeo/geocaching/cgCache.java
@@ -3,6 +3,7 @@ package cgeo.geocaching;
import cgeo.geocaching.activity.IAbstractActivity;
import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.connector.IConnector;
+import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.geopoint.Geopoint;
import org.apache.commons.lang3.StringUtils;
@@ -46,7 +47,7 @@ public class cgCache implements ICache {
public String ownerReal = "";
public Date hidden = null;
public String hint = "";
- public String size = "";
+ public CacheSize size = null;
public Float difficulty = Float.valueOf(0);
public Float terrain = Float.valueOf(0);
public Float direction = null;
@@ -138,7 +139,7 @@ public class cgCache implements ICache {
if (StringUtils.isBlank(hint)) {
hint = other.hint;
}
- if (StringUtils.isBlank(size)) {
+ if (size == null) {
size = other.size;
}
if (difficulty == null || difficulty == 0) {
@@ -398,7 +399,7 @@ public class cgCache implements ICache {
}
@Override
- public String getSize() {
+ public CacheSize getSize() {
return size;
}
diff --git a/src/cgeo/geocaching/cgCacheListAdapter.java b/src/cgeo/geocaching/cgCacheListAdapter.java
index 4e1d4e4..a3563b0 100644
--- a/src/cgeo/geocaching/cgCacheListAdapter.java
+++ b/src/cgeo/geocaching/cgCacheListAdapter.java
@@ -592,11 +592,11 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
if (StringUtils.isNotBlank(cache.geocode)) {
cacheInfo.append(cache.geocode);
}
- if (StringUtils.isNotBlank(cache.size)) {
+ if (cache.size != null) {
if (cacheInfo.length() > 0) {
cacheInfo.append(" | ");
}
- cacheInfo.append(cache.size);
+ cacheInfo.append(cache.size.id);
}
if ((cache.difficulty != null && cache.difficulty > 0f) || (cache.terrain != null && cache.terrain > 0f) || (cache.rating != null && cache.rating > 0f)) {
if (cacheInfo.length() > 0 && ((cache.difficulty != null && cache.difficulty > 0f) || (cache.terrain != null && cache.terrain > 0f))) {
diff --git a/src/cgeo/geocaching/cgCoord.java b/src/cgeo/geocaching/cgCoord.java
index 17520ca..a8e6349 100644
--- a/src/cgeo/geocaching/cgCoord.java
+++ b/src/cgeo/geocaching/cgCoord.java
@@ -1,5 +1,6 @@
package cgeo.geocaching;
+import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.geopoint.Geopoint;
public class cgCoord {
@@ -14,7 +15,7 @@ public class cgCoord {
public Geopoint coords = new Geopoint(0, 0);
public Float difficulty = null;
public Float terrain = null;
- public String size = null;
+ public CacheSize size = null;
public cgCoord() {
}
diff --git a/src/cgeo/geocaching/cgData.java b/src/cgeo/geocaching/cgData.java
index 19e3015..c24d0ff 100644
--- a/src/cgeo/geocaching/cgData.java
+++ b/src/cgeo/geocaching/cgData.java
@@ -1,5 +1,6 @@
package cgeo.geocaching;
+import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.Geopoint.MalformedCoordinateException;
import cgeo.geocaching.utils.CollectionUtils;
@@ -1172,7 +1173,7 @@ public class cgData {
values.put("hidden", cache.hidden.getTime());
}
values.put("hint", cache.hint);
- values.put("size", cache.size);
+ values.put("size", cache.size == null ? "" : cache.size.id);
values.put("difficulty", cache.difficulty);
values.put("terrain", cache.terrain);
values.put("latlon", cache.latlon);
@@ -2012,7 +2013,7 @@ public class cgData {
cache.ownerReal = (String) cursor.getString(cursor.getColumnIndex("owner_real"));
cache.hidden = new Date((long) cursor.getLong(cursor.getColumnIndex("hidden")));
cache.hint = (String) cursor.getString(cursor.getColumnIndex("hint"));
- cache.size = (String) cursor.getString(cursor.getColumnIndex("size"));
+ cache.size = CacheSize.FIND_BY_ID.get((String) cursor.getString(cursor.getColumnIndex("size")));
cache.difficulty = (Float) cursor.getFloat(cursor.getColumnIndex("difficulty"));
index = cursor.getColumnIndex("direction");
if (cursor.isNull(index)) {
diff --git a/src/cgeo/geocaching/cgeocaches.java b/src/cgeo/geocaching/cgeocaches.java
index 0353420..d8e6d84 100644
--- a/src/cgeo/geocaching/cgeocaches.java
+++ b/src/cgeo/geocaching/cgeocaches.java
@@ -5,6 +5,7 @@ import cgeo.geocaching.activity.AbstractListActivity;
import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
import cgeo.geocaching.apps.cachelist.CacheListAppFactory;
+import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.filter.cgFilter;
import cgeo.geocaching.filter.cgFilterBySize;
import cgeo.geocaching.filter.cgFilterByTrackables;
@@ -1206,26 +1207,19 @@ public class cgeocaches extends AbstractListActivity {
return true;
}
else if (id == MENU_FILTER_SIZE_MICRO) {
- return setFilter(new cgFilterBySize(
- res.getString(R.string.caches_filter_size_micro)));
+ return setFilter(new cgFilterBySize(CacheSize.MICRO));
} else if (id == MENU_FILTER_SIZE_SMALL) {
- return setFilter(new cgFilterBySize(
- res.getString(R.string.caches_filter_size_small)));
+ return setFilter(new cgFilterBySize(CacheSize.SMALL));
} else if (id == MENU_FILTER_SIZE_REGULAR) {
- return setFilter(new cgFilterBySize(
- res.getString(R.string.caches_filter_size_regular)));
+ return setFilter(new cgFilterBySize(CacheSize.REGULAR));
} else if (id == MENU_FILTER_SIZE_LARGE) {
- return setFilter(new cgFilterBySize(
- res.getString(R.string.caches_filter_size_large)));
+ return setFilter(new cgFilterBySize(CacheSize.LARGE));
} else if (id == MENU_FILTER_SIZE_OTHER) {
- return setFilter(new cgFilterBySize(
- res.getString(R.string.caches_filter_size_other)));
+ return setFilter(new cgFilterBySize(CacheSize.OTHER));
} else if (id == MENU_FILTER_SIZE_VIRTUAL) {
- return setFilter(new cgFilterBySize(
- res.getString(R.string.caches_filter_size_virtual)));
+ return setFilter(new cgFilterBySize(CacheSize.VIRTUAL));
} else if (id == MENU_FILTER_SIZE_NOT_CHOSEN) {
- return setFilter(new cgFilterBySize(
- res.getString(R.string.caches_filter_size_notchosen)));
+ return setFilter(new cgFilterBySize(CacheSize.NOT_CHOSEN));
} else if (id == MENU_FILTER_TYPE_TRADITIONAL) {
return setFilter(new cgFilterByType("traditional"));
} else if (id == MENU_FILTER_TYPE_MULTI) {
diff --git a/src/cgeo/geocaching/cgeodetail.java b/src/cgeo/geocaching/cgeodetail.java
index 38c5d7e..f8513e1 100644
--- a/src/cgeo/geocaching/cgeodetail.java
+++ b/src/cgeo/geocaching/cgeodetail.java
@@ -4,6 +4,7 @@ import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.apps.cache.GeneralAppsFactory;
import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
import cgeo.geocaching.compatibility.Compatibility;
+import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.utils.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@@ -664,10 +665,10 @@ public class cgeodetail extends AbstractActivity {
itemName.setText(res.getString(R.string.cache_type));
String size = "";
- if (StringUtils.isNotBlank(cache.size)) {
+ if (cache.size != null) {
// don't show "not chosen" for events, that should be the normal case
- if (!(cache.isEventCache() && cache.size.equals("not chosen"))) {
- size = " (" + cache.size + ")";
+ if (!(cache.isEventCache() && cache.size == CacheSize.NOT_CHOSEN)) {
+ size = " (" + cache.size.id + ")";
}
}
diff --git a/src/cgeo/geocaching/cgeopopup.java b/src/cgeo/geocaching/cgeopopup.java
index 49c59b0..af5cd56 100644
--- a/src/cgeo/geocaching/cgeopopup.java
+++ b/src/cgeo/geocaching/cgeopopup.java
@@ -238,14 +238,14 @@ public class cgeopopup extends AbstractActivity {
itemName.setText(res.getString(R.string.cache_type));
if (cgBase.cacheTypesInv.containsKey(cache.type)) { // cache icon
- if (StringUtils.isNotBlank(cache.size)) {
- itemValue.setText(cgBase.cacheTypesInv.get(cache.type) + " (" + cache.size + ")");
+ if (cache.size != null) {
+ itemValue.setText(cgBase.cacheTypesInv.get(cache.type) + " (" + cache.size.id + ")");
} else {
itemValue.setText(cgBase.cacheTypesInv.get(cache.type));
}
} else {
- if (StringUtils.isNotBlank(cache.size)) {
- itemValue.setText(cgBase.cacheTypesInv.get("mystery") + " (" + cache.size + ")");
+ if (cache.size != null) {
+ itemValue.setText(cgBase.cacheTypesInv.get("mystery") + " (" + cache.size.id + ")");
} else {
itemValue.setText(cgBase.cacheTypesInv.get("mystery"));
}
diff --git a/src/cgeo/geocaching/enumerations/CacheSize.java b/src/cgeo/geocaching/enumerations/CacheSize.java
index ee202ad..44d6377 100644
--- a/src/cgeo/geocaching/enumerations/CacheSize.java
+++ b/src/cgeo/geocaching/enumerations/CacheSize.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.enumerations;
+import cgeo.geocaching.R;
+
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -10,28 +12,31 @@ import java.util.Map;
* @author koem
*/
public enum CacheSize {
- MICRO("micro", 1),
- SMALL("small", 2),
- REGULAR("regular", 3),
- LARGE("large", 4),
- NOT_CHOSEN("not chosen", 0),
- OTHER("other", 0);
+ MICRO("micro", 1, R.string.caches_filter_size_micro),
+ SMALL("small", 2, R.string.caches_filter_size_small),
+ REGULAR("regular", 3, R.string.caches_filter_size_regular),
+ LARGE("large", 4, R.string.caches_filter_size_large),
+ VIRTUAL("virtual", 0, R.string.caches_filter_size_virtual),
+ NOT_CHOSEN("not chosen", 0, R.string.caches_filter_size_notchosen),
+ OTHER("other", 0, R.string.caches_filter_size_other);
- public final String cgeoId;
+ public final String id;
public final int comparable;
+ public final int stringId;
- private CacheSize(String cgeoId, int comparable) {
- this.cgeoId = cgeoId;
+ private CacheSize(String id, int comparable, int stringId) {
+ this.id = id;
this.comparable = comparable;
+ this.stringId = stringId;
}
- final public static Map<String, CacheSize> FIND_BY_CGEOID;
+ final public static Map<String, CacheSize> FIND_BY_ID;
static {
final HashMap<String, CacheSize> mapping = new HashMap<String, CacheSize>();
for (CacheSize cs : values()) {
- mapping.put(cs.cgeoId, cs);
+ mapping.put(cs.id, cs);
}
- FIND_BY_CGEOID = Collections.unmodifiableMap(mapping);
+ FIND_BY_ID = Collections.unmodifiableMap(mapping);
}
}
diff --git a/src/cgeo/geocaching/enumerations/CacheType.java b/src/cgeo/geocaching/enumerations/CacheType.java
index 0751a1f..59c774b 100644
--- a/src/cgeo/geocaching/enumerations/CacheType.java
+++ b/src/cgeo/geocaching/enumerations/CacheType.java
@@ -12,41 +12,41 @@ import java.util.Map;
* @author koem
*/
public enum CacheType {
- TRADITIONAL ("traditional", "traditional cache", "32bc9333-5e52-4957-b0f6-5a2c8fc7b257", R.string.traditional),
- MULTI ("multi", "multi-cache", "a5f6d0ad-d2f2-4011-8c14-940a9ebf3c74", R.string.multi),
- MYSTERY ("mystery", "unknown cache", "40861821-1835-4e11-b666-8d41064d03fe", R.string.mystery),
- LETTERBOX ("letterbox", "letterbox hybrid", "4bdd8fb2-d7bc-453f-a9c5-968563b15d24", R.string.letterbox),
- EVENT ("event", "event cache", "69eb8534-b718-4b35-ae3c-a856a55b0874", R.string.event),
- MEGA_EVENT ("mega", "mega-event cache", "69eb8535-b718-4b35-ae3c-a856a55b0874", R.string.mega),
- EARTH ("earth", "earthcache", "c66f5cf3-9523-4549-b8dd-759cd2f18db8", R.string.earth),
- CITO ("cito", "cache in trash out event", "57150806-bc1a-42d6-9cf0-538d171a2d22", R.string.cito),
- WEBCAM ("webcam", "webcam cache", "31d2ae3c-c358-4b5f-8dcd-2185bf472d3d", R.string.webcam),
- VIRTUAL ("virtual", "virtual cache", "294d4360-ac86-4c83-84dd-8113ef678d7e", R.string.virtual),
- WHERIGO ("wherigo", "wherigo cache", "0544fa55-772d-4e5c-96a9-36a51ebcf5c9", R.string.wherigo),
- LOSTANDFOUND ("lostfound", "lost & found", "3ea6533d-bb52-42fe-b2d2-79a3424d4728", R.string.lostfound),
- PROJECT_APE ("ape", "project ape cache", "2555690d-b2bc-4b55-b5ac-0cb704c0b768", R.string.ape),
- GCHQ ("gchq", "groundspeak hq", "416f2494-dc17-4b6a-9bab-1a29dd292d8c", R.string.gchq),
- GPS_EXHIBIT ("gps", "gps cache exhibit", "72e69af2-7986-4990-afd9-bc16cbbb4ce3", R.string.gps);
+ TRADITIONAL("traditional", "traditional cache", "32bc9333-5e52-4957-b0f6-5a2c8fc7b257", R.string.traditional),
+ MULTI("multi", "multi-cache", "a5f6d0ad-d2f2-4011-8c14-940a9ebf3c74", R.string.multi),
+ MYSTERY("mystery", "unknown cache", "40861821-1835-4e11-b666-8d41064d03fe", R.string.mystery),
+ LETTERBOX("letterbox", "letterbox hybrid", "4bdd8fb2-d7bc-453f-a9c5-968563b15d24", R.string.letterbox),
+ EVENT("event", "event cache", "69eb8534-b718-4b35-ae3c-a856a55b0874", R.string.event),
+ MEGA_EVENT("mega", "mega-event cache", "69eb8535-b718-4b35-ae3c-a856a55b0874", R.string.mega),
+ EARTH("earth", "earthcache", "c66f5cf3-9523-4549-b8dd-759cd2f18db8", R.string.earth),
+ CITO("cito", "cache in trash out event", "57150806-bc1a-42d6-9cf0-538d171a2d22", R.string.cito),
+ WEBCAM("webcam", "webcam cache", "31d2ae3c-c358-4b5f-8dcd-2185bf472d3d", R.string.webcam),
+ VIRTUAL("virtual", "virtual cache", "294d4360-ac86-4c83-84dd-8113ef678d7e", R.string.virtual),
+ WHERIGO("wherigo", "wherigo cache", "0544fa55-772d-4e5c-96a9-36a51ebcf5c9", R.string.wherigo),
+ LOSTANDFOUND("lostfound", "lost & found", "3ea6533d-bb52-42fe-b2d2-79a3424d4728", R.string.lostfound),
+ PROJECT_APE("ape", "project ape cache", "2555690d-b2bc-4b55-b5ac-0cb704c0b768", R.string.ape),
+ GCHQ("gchq", "groundspeak hq", "416f2494-dc17-4b6a-9bab-1a29dd292d8c", R.string.gchq),
+ GPS_EXHIBIT("gps", "gps cache exhibit", "72e69af2-7986-4990-afd9-bc16cbbb4ce3", R.string.gps);
- public final String cgeoId;
+ public final String id;
public final String pattern;
public final String guid;
public final int stringId;
- private CacheType(String cgeoId, String pattern, String guid, int stringId) {
- this.cgeoId = cgeoId;
+ private CacheType(String id, String pattern, String guid, int stringId) {
+ this.id = id;
this.pattern = pattern;
this.guid = guid;
this.stringId = stringId;
}
- public final static Map<String, CacheType> FIND_BY_CGEOID;
+ public final static Map<String, CacheType> FIND_BY_ID;
static {
final HashMap<String, CacheType> mapping = new HashMap<String, CacheType>();
for (CacheType ct : values()) {
- mapping.put(ct.cgeoId, ct);
+ mapping.put(ct.id, ct);
}
- FIND_BY_CGEOID = Collections.unmodifiableMap(mapping);
+ FIND_BY_ID = Collections.unmodifiableMap(mapping);
}
}
diff --git a/src/cgeo/geocaching/enumerations/WaypointType.java b/src/cgeo/geocaching/enumerations/WaypointType.java
index 70ef08a..2cb22a0 100644
--- a/src/cgeo/geocaching/enumerations/WaypointType.java
+++ b/src/cgeo/geocaching/enumerations/WaypointType.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.enumerations;
+import cgeo.geocaching.R;
+
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -10,27 +12,29 @@ import java.util.Map;
* @author koem
*/
public enum WaypointType {
- FLAG ("flag"),
- OWN ("own"),
- PKG ("pkg"),
- PUZZLE ("puzzle"),
- STAGE ("stage"),
- TRAILHEAD ("trailhead"),
- WAYPOINT ("waypoint");
+ FLAG("flag", R.string.wp_final),
+ OWN("own", R.string.wp_stage),
+ PKG("pkg", R.string.wp_pkg),
+ PUZZLE("puzzle", R.string.wp_puzzle),
+ STAGE("stage", R.string.wp_stage),
+ TRAILHEAD("trailhead", R.string.wp_trailhead),
+ WAYPOINT("waypoint", R.string.wp_waypoint);
- public final String cgeoId;
+ public final String id;
+ public final int stringId;
- private WaypointType(String cgeoId) {
- this.cgeoId = cgeoId;
+ private WaypointType(String id, int stringId) {
+ this.id = id;
+ this.stringId = stringId;
}
- public static final Map<String, WaypointType> FIND_BY_CGEOID;
+ public static final Map<String, WaypointType> FIND_BY_ID;
static {
final HashMap<String, WaypointType> mapping = new HashMap<String, WaypointType>();
for (WaypointType wt : values()) {
- mapping.put(wt.cgeoId, wt);
+ mapping.put(wt.id, wt);
}
- FIND_BY_CGEOID = Collections.unmodifiableMap(mapping);
+ FIND_BY_ID = Collections.unmodifiableMap(mapping);
}
}
diff --git a/src/cgeo/geocaching/files/GPXParser.java b/src/cgeo/geocaching/files/GPXParser.java
index 1e1458a..a0da184 100644
--- a/src/cgeo/geocaching/files/GPXParser.java
+++ b/src/cgeo/geocaching/files/GPXParser.java
@@ -9,6 +9,7 @@ import cgeo.geocaching.cgSettings;
import cgeo.geocaching.cgTrackable;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.connector.ConnectorFactory;
+import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.geopoint.Geopoint;
import org.apache.commons.lang3.StringUtils;
@@ -448,7 +449,7 @@ public abstract class GPXParser extends FileParser {
@Override
public void end(String body) {
- cache.size = validate(body.toLowerCase());
+ cache.size = CacheSize.FIND_BY_ID.get(validate(body.toLowerCase()));
}
});
diff --git a/src/cgeo/geocaching/files/LocParser.java b/src/cgeo/geocaching/files/LocParser.java
index 0cbb297..34ef7f1 100644
--- a/src/cgeo/geocaching/files/LocParser.java
+++ b/src/cgeo/geocaching/files/LocParser.java
@@ -7,6 +7,7 @@ import cgeo.geocaching.cgCoord;
import cgeo.geocaching.cgSearch;
import cgeo.geocaching.cgSettings;
import cgeo.geocaching.cgeoapplication;
+import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.geopoint.Geopoint;
import org.apache.commons.lang3.StringUtils;
@@ -115,21 +116,21 @@ public final class LocParser extends FileParser {
.trim());
if (size == 1) {
- pointCoord.size = "not chosen";
+ pointCoord.size = CacheSize.NOT_CHOSEN;
} else if (size == 2) {
- pointCoord.size = "micro";
+ pointCoord.size = CacheSize.MICRO;
} else if (size == 3) {
- pointCoord.size = "regular";
+ pointCoord.size = CacheSize.REGULAR;
} else if (size == 4) {
- pointCoord.size = "large";
+ pointCoord.size = CacheSize.LARGE;
} else if (size == 5) {
- pointCoord.size = "virtual";
+ pointCoord.size = CacheSize.VIRTUAL;
} else if (size == 6) {
- pointCoord.size = "other";
+ pointCoord.size = CacheSize.OTHER;
} else if (size == 8) {
- pointCoord.size = "small";
+ pointCoord.size = CacheSize.SMALL;
} else {
- pointCoord.size = "unknown";
+ pointCoord.size = null;
}
}
diff --git a/src/cgeo/geocaching/filter/cgFilterBySize.java b/src/cgeo/geocaching/filter/cgFilterBySize.java
index 818410e..1e9930c 100644
--- a/src/cgeo/geocaching/filter/cgFilterBySize.java
+++ b/src/cgeo/geocaching/filter/cgFilterBySize.java
@@ -1,14 +1,24 @@
package cgeo.geocaching.filter;
+import cgeo.geocaching.cgBase;
import cgeo.geocaching.cgCache;
+import cgeo.geocaching.enumerations.CacheSize;
public class cgFilterBySize extends cgFilter {
- public cgFilterBySize(String size) {
- super(size);
+ private final CacheSize size;
+
+ public cgFilterBySize(CacheSize size) {
+ super(size.id);
+ this.size = size;
}
@Override
boolean applyFilter(cgCache cache) {
- return name.equals(cache.size);
+ return this.size == cache.size;
+ }
+
+ @Override
+ public String getFilterName() {
+ return cgBase.cacheSizesInv.get(this.size);
}
}
diff --git a/src/cgeo/geocaching/sorting/SizeComparator.java b/src/cgeo/geocaching/sorting/SizeComparator.java
index eed8418..a633a06 100644
--- a/src/cgeo/geocaching/sorting/SizeComparator.java
+++ b/src/cgeo/geocaching/sorting/SizeComparator.java
@@ -2,8 +2,6 @@ package cgeo.geocaching.sorting;
import cgeo.geocaching.cgCache;
-import org.apache.commons.lang3.StringUtils;
-
/**
* sorts caches by size
*
@@ -12,40 +10,11 @@ public class SizeComparator extends AbstractCacheComparator {
@Override
protected boolean canCompare(cgCache cache1, cgCache cache2) {
- return StringUtils.isNotBlank(cache1.size) && StringUtils.isNotBlank(cache2.size);
+ return cache1.size != null && cache2.size != null;
}
@Override
protected int compareCaches(cgCache cache1, cgCache cache2) {
- int size1 = getSize(cache1);
- int size2 = getSize(cache2);
- if (size1 < size2) {
- return 1;
- } else if (size2 < size1) {
- return -1;
- }
- return 0;
- }
-
- /**
- * speed optimized comparison of size string
- *
- * @param cache
- * @return
- */
- private static int getSize(final cgCache cache) {
- char c = cache.size.charAt(0);
- switch (c) {
- case 'm': // micro
- return 1;
- case 's': // small
- return 2;
- case 'r': // regular
- return 3;
- case 'l': // large
- return 4;
- default:
- return 0;
- }
+ return cache2.size.comparable - cache1.size.comparable;
}
} \ No newline at end of file