aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java7
-rw-r--r--main/src/cgeo/geocaching/ICache.java2
-rw-r--r--main/src/cgeo/geocaching/cgBase.java5
-rw-r--r--main/src/cgeo/geocaching/cgCache.java20
-rw-r--r--main/src/cgeo/geocaching/cgData.java12
-rw-r--r--main/src/cgeo/geocaching/files/GPXParser.java5
-rw-r--r--tests/src/cgeo/geocaching/files/GPXParserTest.java2
7 files changed, 27 insertions, 26 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index 816b094..ac3ecf4 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -1241,11 +1241,10 @@ public class CacheDetailActivity extends AbstractActivity {
TextView attribView = (TextView) descriptions.getChildAt(0);
StringBuilder buffer = new StringBuilder();
- String attribute;
final String packageName = cgeoapplication.getInstance().getBaseContext().getPackageName();
- for (int i = 0; i < cache.getAttributes().size(); i++) {
- attribute = cache.getAttributes().get(i);
+ final List<String> attributes = cache.getAttributes();
+ for (String attribute : attributes) {
// dynamically search for a translation of the attribute
int id = res.getIdentifier("attribute_" + attribute, "string", packageName);
if (id > 0) {
@@ -1463,7 +1462,7 @@ public class CacheDetailActivity extends AbstractActivity {
}
// cache attributes
- if (CollectionUtils.isNotEmpty(cache.getAttributes())) {
+ if (cache.hasAttributes()) {
new AttributeViewBuilder().fillView((LinearLayout) view.findViewById(R.id.attributes_innerbox));
view.findViewById(R.id.attributes_box).setVisibility(View.VISIBLE);
}
diff --git a/main/src/cgeo/geocaching/ICache.java b/main/src/cgeo/geocaching/ICache.java
index 8b0d2aa..31d458b 100644
--- a/main/src/cgeo/geocaching/ICache.java
+++ b/main/src/cgeo/geocaching/ICache.java
@@ -114,6 +114,8 @@ public interface ICache extends IBasicCache {
public Date getHiddenDate();
/**
+ * immutable list of attributes, never <code>null</code>
+ *
* @return the list of attributes for this cache
*/
public List<String> getAttributes();
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java
index 96940f9..37052fd 100644
--- a/main/src/cgeo/geocaching/cgBase.java
+++ b/main/src/cgeo/geocaching/cgBase.java
@@ -960,9 +960,6 @@ public class cgBase {
while (matcherAttributesInside.find()) {
if (matcherAttributesInside.groupCount() > 1 && !matcherAttributesInside.group(2).equalsIgnoreCase("blank")) {
- if (cache.getAttributes() == null) {
- cache.setAttributes(new ArrayList<String>());
- }
// by default, use the tooltip of the attribute
String attribute = matcherAttributesInside.group(2).toLowerCase();
@@ -975,7 +972,7 @@ public class cgBase {
attribute = imageName.substring(start + 1, end).replace('-', '_').toLowerCase();
}
}
- cache.getAttributes().add(attribute);
+ cache.addAttribute(attribute);
}
}
}
diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java
index 30c2f3a..7f6e88c 100644
--- a/main/src/cgeo/geocaching/cgCache.java
+++ b/main/src/cgeo/geocaching/cgCache.java
@@ -198,10 +198,10 @@ public class cgCache implements ICache {
myVote = other.getMyVote();
}
if (attributes == null) {
- attributes = other.getAttributes();
+ attributes = other.attributes;
}
if (waypoints == null) {
- waypoints = other.getWaypoints();
+ waypoints = other.waypoints;
}
else {
cgWaypoint.mergeWayPoints(waypoints, other.getWaypoints(), waypoints == null || waypoints.isEmpty());
@@ -555,7 +555,10 @@ public class cgCache implements ICache {
@Override
public List<String> getAttributes() {
- return attributes;
+ if (attributes == null) {
+ return Collections.emptyList();
+ }
+ return Collections.unmodifiableList(attributes);
}
@Override
@@ -1077,4 +1080,15 @@ public class cgCache implements ICache {
matcher = coordPattern.matcher(note);
}
}
+
+ public void addAttribute(final String attribute) {
+ if (attributes == null) {
+ attributes = new ArrayList<String>();
+ }
+ attributes.add(attribute);
+ }
+
+ public boolean hasAttributes() {
+ return attributes != null && attributes.size() > 0;
+ }
}
diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java
index df98fb0..d84c115 100644
--- a/main/src/cgeo/geocaching/cgData.java
+++ b/main/src/cgeo/geocaching/cgData.java
@@ -1302,7 +1302,7 @@ public class cgData {
boolean statusOk = true;
- if (cache.getAttributes() != null) {
+ if (cache.hasAttributes()) {
if (!saveAttributes(cache.getGeocode(), cache.getAttributes())) {
statusOk = false;
}
@@ -1936,15 +1936,7 @@ public class cgData {
// and the resolution of the "if" statement could be simply
// cache.getAttributes() = attributes
if (loadFlags.contains(LoadFlag.LOADATTRIBUTES)) {
- final List<String> attributes = loadAttributes(cache.getGeocode());
- if (CollectionUtils.isNotEmpty(attributes)) {
- if (cache.getAttributes() == null) {
- cache.setAttributes(new ArrayList<String>());
- } else {
- cache.getAttributes().clear();
- }
- cache.getAttributes().addAll(attributes);
- }
+ cache.setAttributes(loadAttributes(cache.getGeocode()));
}
if (loadFlags.contains(LoadFlag.LOADWAYPOINTS)) {
diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java
index 72fd63f..156fb7e 100644
--- a/main/src/cgeo/geocaching/files/GPXParser.java
+++ b/main/src/cgeo/geocaching/files/GPXParser.java
@@ -517,10 +517,7 @@ public abstract class GPXParser extends FileParser {
boolean attributeActive = Integer.parseInt(attrs.getValue("inc")) != 0;
String internalId = CacheAttributeTranslator.getInternalId(attributeId, attributeActive);
if (internalId != null) {
- if (cache.getAttributes() == null) {
- cache.setAttributes(new ArrayList<String>());
- }
- cache.getAttributes().add(internalId);
+ cache.addAttribute(internalId);
}
}
} catch (NumberFormatException e) {
diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java
index 00fc317..2a5b35c 100644
--- a/tests/src/cgeo/geocaching/files/GPXParserTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java
@@ -136,7 +136,7 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
assertEquals("Sehr schöne Runde und wir haben wieder etwas Neues über Hockenheim gelernt. Super Tarnung.\nTFTC, Geoteufel", log.log);
// following info is not contained in pocket query gpx file
- assertNull(cache.getAttributes());
+ assertEquals(0, cache.getAttributes().size());
}
private static long parseTime(final String time) {