aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/Geocache.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/Geocache.java')
-rw-r--r--main/src/cgeo/geocaching/Geocache.java58
1 files changed, 32 insertions, 26 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java
index 69babc4..c842a7f 100644
--- a/main/src/cgeo/geocaching/Geocache.java
+++ b/main/src/cgeo/geocaching/Geocache.java
@@ -98,7 +98,7 @@ public class Geocache implements IWaypoint {
* lazy initialized
*/
private String hint = null;
- private CacheSize size = CacheSize.UNKNOWN;
+ @NonNull private CacheSize size = CacheSize.UNKNOWN;
private float difficulty = 0;
private float terrain = 0;
private Float direction = null;
@@ -271,7 +271,7 @@ public class Geocache implements IWaypoint {
if (!detailed && StringUtils.isBlank(getHint())) {
hint = other.getHint();
}
- if (size == null || CacheSize.UNKNOWN == size) {
+ if (size == CacheSize.UNKNOWN) {
size = other.size;
}
if (difficulty == 0) {
@@ -479,6 +479,7 @@ public class Geocache implements IWaypoint {
notifyChange();
}
+ @NonNull
public List<LogType> getPossibleLogTypes() {
return getConnector().getPossibleLogTypes(this);
}
@@ -502,19 +503,11 @@ public class Geocache implements IWaypoint {
}
}
-
- private String getCacheUrl() {
- return getConnector().getCacheUrl(this);
- }
-
+ @NonNull
private IConnector getConnector() {
return ConnectorFactory.getConnector(this);
}
- public boolean canOpenInBrowser() {
- return getCacheUrl() != null;
- }
-
public boolean supportsRefresh() {
return getConnector() instanceof ISearchByGeocode;
}
@@ -539,6 +532,7 @@ public class Geocache implements IWaypoint {
return getConnector().supportsOwnCoordinates();
}
+ @NonNull
public ILoggingManager getLoggingManager(final LogCacheActivity activity) {
return getConnector().getLoggingManager(activity, this);
}
@@ -559,10 +553,8 @@ public class Geocache implements IWaypoint {
return ownerDisplayName;
}
+ @NonNull
public CacheSize getSize() {
- if (size == null) {
- return CacheSize.UNKNOWN;
- }
return size;
}
@@ -597,7 +589,8 @@ public class Geocache implements IWaypoint {
/**
* @return GC username of the (actual) owner, might differ from the owner. Never empty.
*/
- @NonNull public String getOwnerUserId() {
+ @NonNull
+ public String getOwnerUserId() {
return ownerUserId;
}
@@ -706,6 +699,8 @@ public class Geocache implements IWaypoint {
fromActivity.startActivity(Intent.createChooser(intent, res.getText(R.string.cache_menu_share)));
}
+
+ @NonNull
public Intent getShareIntent() {
final StringBuilder subject = new StringBuilder("Geocache ");
subject.append(geocode);
@@ -721,15 +716,20 @@ public class Geocache implements IWaypoint {
return intent;
}
+ @NonNull
public String getUrl() {
return getConnector().getCacheUrl(this);
}
+ @NonNull
public String getLongUrl() {
return getConnector().getLongCacheUrl(this);
}
- public String getCgeoUrl() { return getConnector().getCacheUrl(this); }
+ @NonNull
+ public String getCgeoUrl() {
+ return getConnector().getCacheUrl(this);
+ }
public boolean supportsGCVote() {
return StringUtils.startsWithIgnoreCase(geocode, "GC");
@@ -760,6 +760,7 @@ public class Geocache implements IWaypoint {
return hidden;
}
+ @NonNull
public List<String> getAttributes() {
return attributes.getUnderlyingList();
}
@@ -775,6 +776,7 @@ public class Geocache implements IWaypoint {
spoilers.add(spoiler);
}
+ @NonNull
public List<Image> getSpoilers() {
return ListUtils.unmodifiableList(ListUtils.emptyIfNull(spoilers));
}
@@ -972,6 +974,7 @@ public class Geocache implements IWaypoint {
*
* @return always non <code>null</code>
*/
+ @NonNull
public List<Waypoint> getWaypoints() {
return waypoints.getUnderlyingList();
}
@@ -1079,13 +1082,8 @@ public class Geocache implements IWaypoint {
this.hint = hint;
}
- public void setSize(final CacheSize size) {
- if (size == null) {
- this.size = CacheSize.UNKNOWN;
- }
- else {
- this.size = size;
- }
+ public void setSize(@NonNull final CacheSize size) {
+ this.size = size;
}
public void setDifficulty(final float difficulty) {
@@ -1368,12 +1366,15 @@ public class Geocache implements IWaypoint {
/**
* Detect coordinates in the personal note and convert them to user defined waypoints. Works by rule of thumb.
*/
- public void parseWaypointsFromNote() {
+ public boolean parseWaypointsFromNote() {
+ boolean changed = false;
for (final Waypoint waypoint : Waypoint.parseWaypointsFromNote(StringUtils.defaultString(getPersonalNote()))) {
if (!hasIdenticalWaypoint(waypoint.getCoords())) {
addOrChangeWaypoint(waypoint, false);
+ changed = true;
}
}
+ return changed;
}
private boolean hasIdenticalWaypoint(final Geopoint point) {
@@ -1475,7 +1476,7 @@ public class Geocache implements IWaypoint {
warnIncorrectParsingIfBlank(getOwnerUserId(), "owner");
warnIncorrectParsingIf(getHiddenDate() == null, "hidden");
warnIncorrectParsingIf(getFavoritePoints() < 0, "favoriteCount");
- warnIncorrectParsingIf(getSize() == null, "size");
+ warnIncorrectParsingIf(getSize() == CacheSize.UNKNOWN, "size");
warnIncorrectParsingIf(getType() == null || getType() == CacheType.UNKNOWN, "type");
warnIncorrectParsingIf(getCoords() == null, "coordinates");
warnIncorrectParsingIfBlank(getLocation(), "location");
@@ -1617,6 +1618,7 @@ public class Geocache implements IWaypoint {
*
* @return start time in minutes after midnight
*/
+ @Nullable
public String guessEventTimeMinutes() {
if (!isEventCache()) {
return null;
@@ -1666,6 +1668,7 @@ public class Geocache implements IWaypoint {
}
};
+ @NonNull
public Collection<Image> getImages() {
final LinkedList<Image> result = new LinkedList<>();
result.addAll(getSpoilers());
@@ -1735,6 +1738,7 @@ public class Geocache implements IWaypoint {
return getConnector().getWaypointGpxId(prefix, geocode);
}
+ @NonNull
public String getWaypointPrefix(final String name) {
return getConnector().getWaypointPrefix(name);
}
@@ -1757,6 +1761,7 @@ public class Geocache implements IWaypoint {
return (getType().applyDistanceRule() || hasUserModifiedCoords()) && getConnector() == GCConnector.getInstance();
}
+ @NonNull
public LogType getDefaultLogType() {
if (isEventCache()) {
final Date eventDate = getHiddenDate();
@@ -1782,7 +1787,8 @@ public class Geocache implements IWaypoint {
* @param caches a collection of caches
* @return the non-blank geocodes of the caches
*/
- public static Set<String> getGeocodes(final Collection<Geocache> caches) {
+ @NonNull
+ public static Set<String> getGeocodes(@NonNull final Collection<Geocache> caches) {
final Set<String> geocodes = new HashSet<>(caches.size());
for (final Geocache cache : caches) {
final String geocode = cache.getGeocode();