From ec09b8c4dbc0a9cad38a1d45b30522a6f6c10933 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 17 Mar 2015 10:17:13 +0100 Subject: fix #4746: getUrl cannot be called on unknown trackables --- main/src/cgeo/geocaching/Trackable.java | 7 +++++++ main/src/cgeo/geocaching/TrackableActivity.java | 2 +- .../connector/trackable/AbstractTrackableConnector.java | 12 ++++++++++++ .../connector/trackable/TrackableConnector.java | 15 +++++++++++++++ .../connector/trackable/UnknownTrackableConnector.java | 6 ++---- 5 files changed, 37 insertions(+), 5 deletions(-) (limited to 'main') diff --git a/main/src/cgeo/geocaching/Trackable.java b/main/src/cgeo/geocaching/Trackable.java index d7d2357..6ec8c0d 100644 --- a/main/src/cgeo/geocaching/Trackable.java +++ b/main/src/cgeo/geocaching/Trackable.java @@ -42,6 +42,13 @@ public class Trackable implements ILogable { private List logs = new ArrayList<>(); private String trackingcode = null; + /** + * Check whether this trackable has a corresponding URL. + */ + public boolean hasUrl() { + return getConnector().hasTrackableUrls(); + } + @NonNull public String getUrl() { return getConnector().getUrl(this); diff --git a/main/src/cgeo/geocaching/TrackableActivity.java b/main/src/cgeo/geocaching/TrackableActivity.java index e04fe9f..7d0ba3a 100644 --- a/main/src/cgeo/geocaching/TrackableActivity.java +++ b/main/src/cgeo/geocaching/TrackableActivity.java @@ -211,7 +211,7 @@ public class TrackableActivity extends AbstractViewPagerActivity getUserActions() { return AbstractConnector.getDefaultUserActions(); } + + @Override + @NonNull + public String getUrl(@NonNull final Trackable trackable) { + throw new IllegalStateException("this trackable does not have a corresponding URL"); + } } diff --git a/main/src/cgeo/geocaching/connector/trackable/TrackableConnector.java b/main/src/cgeo/geocaching/connector/trackable/TrackableConnector.java index 1281683..aea60e6 100644 --- a/main/src/cgeo/geocaching/connector/trackable/TrackableConnector.java +++ b/main/src/cgeo/geocaching/connector/trackable/TrackableConnector.java @@ -16,6 +16,21 @@ public interface TrackableConnector { public boolean canHandleTrackable(final String geocode); + /** + * Check whether the connector has URLs corresponding the the trackable. + * + * @return true if the connector handles URLs, false otherwise + */ + public boolean hasTrackableUrls(); + + /** + * Return the URL for a trackable. Might throw {@link IllegalStateException} if called + * on a connector which does not have URLs for trackables. This might be checked using + * {@link #hasTrackableUrls()}. + * + * @param trackable the trackable + * @return the URL corresponding to this trackable + */ @NonNull public String getUrl(@NonNull final Trackable trackable); diff --git a/main/src/cgeo/geocaching/connector/trackable/UnknownTrackableConnector.java b/main/src/cgeo/geocaching/connector/trackable/UnknownTrackableConnector.java index 5fc7bf1..885df7e 100644 --- a/main/src/cgeo/geocaching/connector/trackable/UnknownTrackableConnector.java +++ b/main/src/cgeo/geocaching/connector/trackable/UnknownTrackableConnector.java @@ -2,7 +2,6 @@ package cgeo.geocaching.connector.trackable; import cgeo.geocaching.Trackable; -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; public class UnknownTrackableConnector extends AbstractTrackableConnector { @@ -13,9 +12,8 @@ public class UnknownTrackableConnector extends AbstractTrackableConnector { } @Override - @NonNull - public String getUrl(@NonNull final Trackable trackable) { - throw new IllegalStateException("getUrl cannot be called on unknown trackables"); + public boolean hasTrackableUrls() { + return false; } @Override -- cgit v1.1