diff options
author | Samuel Tardieu <sam@rfc1149.net> | 2014-11-23 14:43:43 +0100 |
---|---|---|
committer | Samuel Tardieu <sam@rfc1149.net> | 2014-11-23 15:05:03 +0100 |
commit | 121d4285d747ce2ec707ad3cb7a9166833699fb6 (patch) | |
tree | 4b430212b3d95f7f05b6bfa0bcc89c4d41d3a96f /main/src | |
parent | f59e23c38c1b6a39fcc55d2d96727372553bdca3 (diff) | |
download | cgeo-121d4285d747ce2ec707ad3cb7a9166833699fb6.zip cgeo-121d4285d747ce2ec707ad3cb7a9166833699fb6.tar.gz cgeo-121d4285d747ce2ec707ad3cb7a9166833699fb6.tar.bz2 |
Remove the ICache interface
Throughout the code, Geocache is used where ICache should be used.
Moreover, except in the tests, ICache is only implemented in Geocache.
Diffstat (limited to 'main/src')
14 files changed, 43 insertions, 228 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java index 54ddf5e..6c8e1b8 100644 --- a/main/src/cgeo/geocaching/Geocache.java +++ b/main/src/cgeo/geocaching/Geocache.java @@ -76,9 +76,9 @@ import java.util.Set; import java.util.regex.Pattern; /** - * Internal c:geo representation of a "cache" + * Internal representation of a "cache" */ -public class Geocache implements ICache, IWaypoint { +public class Geocache implements IWaypoint, ILogable, ICoordinates { private static final int OWN_WP_PREFIX_OFFSET = 17; private long updated = 0; @@ -170,7 +170,7 @@ public class Geocache implements ICache, IWaypoint { * Cache constructor to be used by the GPX parser only. This constructor explicitly sets several members to empty * lists. * - * @param gpxParser + * @param gpxParser ignored parameter allowing to select this constructor */ public Geocache(final GPXParser gpxParser) { setReliableLatLon(true); @@ -543,7 +543,6 @@ public class Geocache implements ICache, IWaypoint { return getConnector().getLoggingManager(activity, this); } - @Override public float getDifficulty() { return difficulty; } @@ -553,12 +552,13 @@ public class Geocache implements ICache, IWaypoint { return geocode; } - @Override + /** + * @return displayed owner, might differ from the real owner + */ public String getOwnerDisplayName() { return ownerDisplayName; } - @Override public CacheSize getSize() { if (size == null) { return CacheSize.UNKNOWN; @@ -566,22 +566,18 @@ public class Geocache implements ICache, IWaypoint { return size; } - @Override public float getTerrain() { return terrain; } - @Override public boolean isArchived() { return BooleanUtils.isTrue(archived); } - @Override public boolean isDisabled() { return BooleanUtils.isTrue(disabled); } - @Override public boolean isPremiumMembersOnly() { return BooleanUtils.isTrue(premiumMembersOnly); } @@ -590,20 +586,26 @@ public class Geocache implements ICache, IWaypoint { this.premiumMembersOnly = members; } - @Override + /** + * + * @return {@code true} if the user is the owner of the cache, {@code false} otherwise + */ public boolean isOwner() { return getConnector().isOwner(this); } - @Override - public String getOwnerUserId() { + /** + * @return GC username of the (actual) owner, might differ from the owner. Never empty. + */ + @NonNull public String getOwnerUserId() { return ownerUserId; } /** * Attention, calling this method may trigger a database access for the cache! + * + * @return the decrypted hint */ - @Override public String getHint() { initializeCacheTexts(); assertTextNotNull(hint, "Hint"); @@ -623,7 +625,6 @@ public class Geocache implements ICache, IWaypoint { /** * Attention, calling this method may trigger a database access for the cache! */ - @Override public String getDescription() { initializeCacheTexts(); assertTextNotNull(description, "Description"); @@ -654,7 +655,6 @@ public class Geocache implements ICache, IWaypoint { /** * Attention, calling this method may trigger a database access for the cache! */ - @Override public String getShortDescription() { initializeCacheTexts(); assertTextNotNull(shortdesc, "Short description"); @@ -666,7 +666,6 @@ public class Geocache implements ICache, IWaypoint { return name; } - @Override public String getCacheId() { if (StringUtils.isBlank(cacheId) && getConnector().equals(GCConnector.getInstance())) { return String.valueOf(GCConstants.gccodeToGCId(geocode)); @@ -675,7 +674,6 @@ public class Geocache implements ICache, IWaypoint { return cacheId; } - @Override public String getGuid() { return guid; } @@ -683,14 +681,12 @@ public class Geocache implements ICache, IWaypoint { /** * Attention, calling this method may trigger a database access for the cache! */ - @Override public String getLocation() { initializeCacheTexts(); assertTextNotNull(location, "Location"); return location; } - @Override public String getPersonalNote() { // non premium members have no personal notes, premium members have an empty string by default. // map both to null, so other code doesn't need to differentiate @@ -743,12 +739,14 @@ public class Geocache implements ICache, IWaypoint { this.description = description; } - @Override public boolean isFound() { return BooleanUtils.isTrue(found); } - @Override + /** + * + * @return {@code true} if the user has put a favorite point onto this cache + */ public boolean isFavorite() { return BooleanUtils.isTrue(favorite); } @@ -757,18 +755,15 @@ public class Geocache implements ICache, IWaypoint { this.favorite = favorite; } - @Override @Nullable public Date getHiddenDate() { return hidden; } - @Override public List<String> getAttributes() { return attributes.getUnderlyingList(); } - @Override public List<Trackable> getInventory() { return inventory; } @@ -780,22 +775,24 @@ public class Geocache implements ICache, IWaypoint { spoilers.add(spoiler); } - @Override public List<Image> getSpoilers() { return ListUtils.unmodifiableList(ListUtils.emptyIfNull(spoilers)); } - @Override + /** + * @return a statistic how often the caches has been found, disabled, archived etc. + */ public Map<LogType, Integer> getLogCounts() { return logCounts; } - @Override public int getFavoritePoints() { return favoritePoints; } - @Override + /** + * @return the normalized cached name to be used for sorting, taking into account the numerical parts in the name + */ public String getNameForSorting() { if (null == nameForSorting) { nameForSorting = name; @@ -896,8 +893,6 @@ public class Geocache implements ICache, IWaypoint { /** * Set reliable coordinates - * - * @param coords */ public void setCoords(final Geopoint coords) { this.coords = new UncertainProperty<>(coords); @@ -905,9 +900,6 @@ public class Geocache implements ICache, IWaypoint { /** * Set unreliable coordinates from a certain map zoom level - * - * @param coords - * @param zoomlevel */ public void setCoords(final Geopoint coords, final int zoomlevel) { this.coords = new UncertainProperty<>(coords, zoomlevel); @@ -964,7 +956,9 @@ public class Geocache implements ICache, IWaypoint { this.inventoryItems = inventoryItems; } - @Override + /** + * @return {@code true} if the cache is on the user's watchlist, {@code false} otherwise + */ public boolean isOnWatchlist() { return BooleanUtils.isTrue(onWatchlist); } @@ -1148,7 +1142,6 @@ public class Geocache implements ICache, IWaypoint { * * @returns Never null */ - @Override public CacheType getType() { return cacheType.getValue(); } @@ -1329,8 +1322,6 @@ public class Geocache implements ICache, IWaypoint { /** * deletes any waypoint - * - * @param waypoint */ public void deleteWaypointForce(final Waypoint waypoint) { @@ -1750,8 +1741,6 @@ public class Geocache implements ICache, IWaypoint { /** * Get number of overall finds for a cache, or 0 if the number of finds is not known. - * - * @return */ public int getFindsCount() { if (getLogCounts().isEmpty()) { diff --git a/main/src/cgeo/geocaching/ICache.java b/main/src/cgeo/geocaching/ICache.java deleted file mode 100644 index b99d877..0000000 --- a/main/src/cgeo/geocaching/ICache.java +++ /dev/null @@ -1,164 +0,0 @@ -/** - * - */ -package cgeo.geocaching; - -import cgeo.geocaching.enumerations.CacheSize; -import cgeo.geocaching.enumerations.CacheType; -import cgeo.geocaching.enumerations.LogType; - -import java.util.Date; -import java.util.List; -import java.util.Map; - -/** - * Basic interface for caches - */ -public interface ICache extends ILogable, ICoordinates { - - /** - * @return Displayed owner, might differ from the real owner - */ - public String getOwnerDisplayName(); - - /** - * @return GC username of the (actual) owner, might differ from the owner. Never empty. - */ - public String getOwnerUserId(); - - /** - * @return true if the user is the owner of the cache, false else - */ - public boolean isOwner(); - - /** - * @return true is the cache is archived, false else - */ - public boolean isArchived(); - - /** - * @return true is the cache is a Premium Member cache only, false else - */ - public boolean isPremiumMembersOnly(); - - /** - * @return Decrypted hint - */ - public String getHint(); - - /** - * @return Description - */ - public String getDescription(); - - /** - * @return Short Description - */ - public String getShortDescription(); - - - /** - * @return Id - */ - public String getCacheId(); - - /** - * @return Guid - */ - public String getGuid(); - - /** - * @return Location - */ - public String getLocation(); - - /** - * @return Personal note - */ - public String getPersonalNote(); - - - /** - * @return true if the user gave a favorite point to the cache - * - */ - public boolean isFavorite(); - - /** - * @return number of favorite points - * - */ - public int getFavoritePoints(); - - /** - * @return true if the cache is on the watchlist of the user - * - */ - public boolean isOnWatchlist(); - - /** - * @return The date the cache has been hidden - * - */ - public Date getHiddenDate(); - - /** - * null safe list of attributes - * - * @return the list of attributes for this cache - */ - public List<String> getAttributes(); - - /** - * @return the list of trackables in this cache - */ - public List<Trackable> getInventory(); - - /** - * @return the list of spoiler images - */ - public List<Image> getSpoilers(); - - /** - * @return a statistic how often the caches has been found, disabled, archived etc. - */ - public Map<LogType, Integer> getLogCounts(); - - /** - * get the name for lexicographical sorting. - * - * @return normalized, cached name which sort also correct for numerical parts in the name - */ - public String getNameForSorting(); - - /** - * @return Tradi, multi etc. - */ - CacheType getType(); - - /** - * @return Micro, small etc. - */ - CacheSize getSize(); - - /** - * @return true if the user already found the cache - * - */ - boolean isFound(); - - /** - * @return true if the cache is disabled, false else - */ - boolean isDisabled(); - - /** - * @return Difficulty assessment - */ - float getDifficulty(); - - /** - * @return Terrain assessment - */ - float getTerrain(); -} diff --git a/main/src/cgeo/geocaching/connector/ConnectorFactory.java b/main/src/cgeo/geocaching/connector/ConnectorFactory.java index 6bbfae0..d4d051f 100644 --- a/main/src/cgeo/geocaching/connector/ConnectorFactory.java +++ b/main/src/cgeo/geocaching/connector/ConnectorFactory.java @@ -1,6 +1,6 @@ package cgeo.geocaching.connector; -import cgeo.geocaching.ICache; +import cgeo.geocaching.Geocache; import cgeo.geocaching.R; import cgeo.geocaching.SearchResult; import cgeo.geocaching.Trackable; @@ -144,7 +144,7 @@ public final class ConnectorFactory { } public static @NonNull - IConnector getConnector(final ICache cache) { + IConnector getConnector(final Geocache cache) { return getConnector(cache.getGeocode()); } diff --git a/main/src/cgeo/geocaching/connector/GeocachingAustraliaConnector.java b/main/src/cgeo/geocaching/connector/GeocachingAustraliaConnector.java index 3992013..3c72c89 100644 --- a/main/src/cgeo/geocaching/connector/GeocachingAustraliaConnector.java +++ b/main/src/cgeo/geocaching/connector/GeocachingAustraliaConnector.java @@ -1,7 +1,6 @@ package cgeo.geocaching.connector; import cgeo.geocaching.Geocache; -import cgeo.geocaching.ICache; import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNull; @@ -24,7 +23,7 @@ public class GeocachingAustraliaConnector extends AbstractConnector { } @Override - public boolean isOwner(final ICache cache) { + public boolean isOwner(final Geocache cache) { return false; } diff --git a/main/src/cgeo/geocaching/connector/GeopeitusConnector.java b/main/src/cgeo/geocaching/connector/GeopeitusConnector.java index aa08485..8b82c1b 100644 --- a/main/src/cgeo/geocaching/connector/GeopeitusConnector.java +++ b/main/src/cgeo/geocaching/connector/GeopeitusConnector.java @@ -1,7 +1,6 @@ package cgeo.geocaching.connector; import cgeo.geocaching.Geocache; -import cgeo.geocaching.ICache; import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNull; @@ -24,7 +23,7 @@ public class GeopeitusConnector extends AbstractConnector { } @Override - public boolean isOwner(final ICache cache) { + public boolean isOwner(final Geocache cache) { return false; } diff --git a/main/src/cgeo/geocaching/connector/IConnector.java b/main/src/cgeo/geocaching/connector/IConnector.java index c235df4..9c1e8fc 100644 --- a/main/src/cgeo/geocaching/connector/IConnector.java +++ b/main/src/cgeo/geocaching/connector/IConnector.java @@ -1,7 +1,6 @@ package cgeo.geocaching.connector; import cgeo.geocaching.Geocache; -import cgeo.geocaching.ICache; import cgeo.geocaching.LogCacheActivity; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.location.Geopoint; @@ -189,7 +188,7 @@ public interface IConnector { * @param cache a cache that this connector must be able to handle * @return <code>true</code> if the current user is the cache owner, <code>false</code> otherwise */ - public boolean isOwner(final ICache cache); + public boolean isOwner(final Geocache cache); /** * Check if the cache information is complete enough to be diff --git a/main/src/cgeo/geocaching/connector/UnknownConnector.java b/main/src/cgeo/geocaching/connector/UnknownConnector.java index 05593d7..a2eb8e4 100644 --- a/main/src/cgeo/geocaching/connector/UnknownConnector.java +++ b/main/src/cgeo/geocaching/connector/UnknownConnector.java @@ -1,7 +1,6 @@ package cgeo.geocaching.connector; import cgeo.geocaching.Geocache; -import cgeo.geocaching.ICache; import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNull; @@ -24,7 +23,7 @@ public class UnknownConnector extends AbstractConnector { } @Override - public boolean isOwner(final ICache cache) { + public boolean isOwner(final Geocache cache) { return false; } diff --git a/main/src/cgeo/geocaching/connector/WaymarkingConnector.java b/main/src/cgeo/geocaching/connector/WaymarkingConnector.java index 282ee31..d6eaab5 100644 --- a/main/src/cgeo/geocaching/connector/WaymarkingConnector.java +++ b/main/src/cgeo/geocaching/connector/WaymarkingConnector.java @@ -1,7 +1,6 @@ package cgeo.geocaching.connector; import cgeo.geocaching.Geocache; -import cgeo.geocaching.ICache; import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNull; @@ -24,7 +23,7 @@ public class WaymarkingConnector extends AbstractConnector { } @Override - public boolean isOwner(ICache cache) { + public boolean isOwner(Geocache cache) { // this connector has no user management return false; } diff --git a/main/src/cgeo/geocaching/connector/ec/ECConnector.java b/main/src/cgeo/geocaching/connector/ec/ECConnector.java index 27b5b54..e884f85 100644 --- a/main/src/cgeo/geocaching/connector/ec/ECConnector.java +++ b/main/src/cgeo/geocaching/connector/ec/ECConnector.java @@ -2,7 +2,6 @@ package cgeo.geocaching.connector.ec; import cgeo.geocaching.CgeoApplication; import cgeo.geocaching.Geocache; -import cgeo.geocaching.ICache; import cgeo.geocaching.LogCacheActivity; import cgeo.geocaching.R; import cgeo.geocaching.SearchResult; @@ -115,7 +114,7 @@ public class ECConnector extends AbstractConnector implements ISearchByGeocode, } @Override - public boolean isOwner(final ICache cache) { + public boolean isOwner(final Geocache cache) { return false; } diff --git a/main/src/cgeo/geocaching/connector/gc/GCConnector.java b/main/src/cgeo/geocaching/connector/gc/GCConnector.java index 8b714c7..099fd79 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCConnector.java +++ b/main/src/cgeo/geocaching/connector/gc/GCConnector.java @@ -3,7 +3,6 @@ package cgeo.geocaching.connector.gc; import cgeo.geocaching.CgeoApplication; import cgeo.geocaching.DataStore; import cgeo.geocaching.Geocache; -import cgeo.geocaching.ICache; import cgeo.geocaching.LogCacheActivity; import cgeo.geocaching.R; import cgeo.geocaching.SearchResult; @@ -193,7 +192,7 @@ public class GCConnector extends AbstractConnector implements ISearchByGeocode, } @Override - public boolean isOwner(final ICache cache) { + public boolean isOwner(final Geocache cache) { final String user = Settings.getUsername(); return StringUtils.isNotEmpty(user) && StringUtils.equalsIgnoreCase(cache.getOwnerUserId(), user); } diff --git a/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java b/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java index b56055a..e8f20c9 100644 --- a/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java +++ b/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java @@ -3,7 +3,6 @@ package cgeo.geocaching.connector.oc; import cgeo.geocaching.CgeoApplication; import cgeo.geocaching.DataStore; import cgeo.geocaching.Geocache; -import cgeo.geocaching.ICache; import cgeo.geocaching.LogCacheActivity; import cgeo.geocaching.SearchResult; import cgeo.geocaching.connector.ILoggingManager; @@ -150,7 +149,7 @@ public class OCApiLiveConnector extends OCApiConnector implements ISearchByCente } @Override - public boolean isOwner(final ICache cache) { + public boolean isOwner(final Geocache cache) { return StringUtils.isNotEmpty(getUserName()) && StringUtils.equals(cache.getOwnerDisplayName(), getUserName()); } diff --git a/main/src/cgeo/geocaching/connector/oc/OCConnector.java b/main/src/cgeo/geocaching/connector/oc/OCConnector.java index 1ba88d5..9c79f71 100644 --- a/main/src/cgeo/geocaching/connector/oc/OCConnector.java +++ b/main/src/cgeo/geocaching/connector/oc/OCConnector.java @@ -1,7 +1,6 @@ package cgeo.geocaching.connector.oc; import cgeo.geocaching.Geocache; -import cgeo.geocaching.ICache; import cgeo.geocaching.R; import cgeo.geocaching.connector.AbstractConnector; import cgeo.geocaching.enumerations.LogType; @@ -54,7 +53,7 @@ public class OCConnector extends AbstractConnector { } @Override - public boolean isOwner(final ICache cache) { + public boolean isOwner(final Geocache cache) { return false; } diff --git a/main/src/cgeo/geocaching/connector/ox/OXConnector.java b/main/src/cgeo/geocaching/connector/ox/OXConnector.java index 6bb5bce..dd048f9 100644 --- a/main/src/cgeo/geocaching/connector/ox/OXConnector.java +++ b/main/src/cgeo/geocaching/connector/ox/OXConnector.java @@ -1,7 +1,6 @@ package cgeo.geocaching.connector.ox; import cgeo.geocaching.Geocache; -import cgeo.geocaching.ICache; import cgeo.geocaching.SearchResult; import cgeo.geocaching.connector.AbstractConnector; import cgeo.geocaching.connector.capability.ISearchByCenter; @@ -56,7 +55,7 @@ public class OXConnector extends AbstractConnector implements ISearchByCenter, I } @Override - public boolean isOwner(final ICache cache) { + public boolean isOwner(final Geocache cache) { return false; } diff --git a/main/src/cgeo/geocaching/enumerations/CacheType.java b/main/src/cgeo/geocaching/enumerations/CacheType.java index 93d7098..995c436 100644 --- a/main/src/cgeo/geocaching/enumerations/CacheType.java +++ b/main/src/cgeo/geocaching/enumerations/CacheType.java @@ -1,7 +1,7 @@ package cgeo.geocaching.enumerations; import cgeo.geocaching.CgeoApplication; -import cgeo.geocaching.ICache; +import cgeo.geocaching.Geocache; import cgeo.geocaching.R; import java.util.Collections; @@ -123,7 +123,7 @@ public enum CacheType { * @param cache * @return true if this is the ALL type or if this type equals the type of the cache. */ - public boolean contains(final ICache cache) { + public boolean contains(final Geocache cache) { if (cache == null) { return false; } |