diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2012-04-12 12:31:11 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2012-04-12 14:44:05 +0200 |
| commit | 65caf4985175662cb1c11314a860506b648d342b (patch) | |
| tree | fc74680068b709c3263c64faa91cc862d80c6ca8 | |
| parent | 1e06aee2435ec34858890b6f14cab554f2c42a84 (diff) | |
| download | cgeo-65caf4985175662cb1c11314a860506b648d342b.zip cgeo-65caf4985175662cb1c11314a860506b648d342b.tar.gz cgeo-65caf4985175662cb1c11314a860506b648d342b.tar.bz2 | |
Refactoring: remove useless null checks
Boundary data ultimately coming to loadInViewport is checked for null
(those are Long fields) while they come from long values, that cannot be
null.
It makes little sense to return null to represent an empty set when we can
return the empty set itself.
Also, the cursor cannot be null, and the method can be made private.
| -rw-r--r-- | main/src/cgeo/geocaching/cgData.java | 38 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeoapplication.java | 8 |
2 files changed, 17 insertions, 29 deletions
diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index 9a6eaf1..24151da 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -2704,12 +2704,12 @@ public class cgData { } /** Retrieve all stored caches from DB */ - public Set<String> loadCachedInViewport(final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final CacheType cacheType) { + public Set<String> loadCachedInViewport(final long centerLat, final long centerLon, final long spanLat, final long spanLon, final CacheType cacheType) { return loadInViewport(false, centerLat, centerLon, spanLat, spanLon, cacheType); } /** Retrieve stored caches from DB with listId >= 1 */ - public Set<String> loadStoredInViewport(final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final CacheType cacheType) { + public Set<String> loadStoredInViewport(final long centerLat, final long centerLon, final long spanLat, final long spanLon, final CacheType cacheType) { return loadInViewport(true, centerLat, centerLon, spanLat, spanLon, cacheType); } @@ -2723,16 +2723,12 @@ public class cgData { * @param spanLat * @param spanLon * @param cacheType - * @return Set with geocodes or null if none have been found + * @return Set with geocodes */ - public Set<String> loadInViewport(final boolean stored, final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final CacheType cacheType) { - if (centerLat == null || centerLon == null || spanLat == null || spanLon == null) { - return null; - } - + private Set<String> loadInViewport(final boolean stored, final long centerLat, final long centerLon, final long spanLat, final long spanLon, final CacheType cacheType) { init(); - Set<String> geocodes = new HashSet<String>(); + final Set<String> geocodes = new HashSet<String>(); // if not stored only, get codes from CacheCache as well if (!stored) { @@ -2757,7 +2753,7 @@ public class cgData { lonMin = llCache; } - StringBuilder where = new StringBuilder(); + final StringBuilder where = new StringBuilder(); where.append("latitude >= "); where.append(String.format((Locale) null, "%.6f", latMin)); where.append(" and latitude <= "); @@ -2780,7 +2776,7 @@ public class cgData { } try { - Cursor cursor = databaseRO.query( + final Cursor cursor = databaseRO.query( dbTableCaches, new String[] { "geocode" }, where.toString(), @@ -2790,22 +2786,14 @@ public class cgData { null, "500"); - if (cursor != null) { - if (cursor.getCount() > 0) { - cursor.moveToFirst(); - int index = cursor.getColumnIndex("geocode"); - - do { - geocodes.add(cursor.getString(index)); - } while (cursor.moveToNext()); - } else { - cursor.close(); + if (cursor.moveToFirst()) { + final int index = cursor.getColumnIndex("geocode"); - return geocodes.isEmpty() ? null : geocodes; - } - - cursor.close(); + do { + geocodes.add(cursor.getString(index)); + } while (cursor.moveToNext()); } + cursor.close(); } catch (Exception e) { Log.e(Settings.tag, "cgData.loadInViewport: " + e.toString()); } diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java index 7e44871..bdad7f0 100644 --- a/main/src/cgeo/geocaching/cgeoapplication.java +++ b/main/src/cgeo/geocaching/cgeoapplication.java @@ -307,14 +307,14 @@ public class cgeoapplication extends Application { return new SearchResult(geocodes, getAllHistoricCachesCount()); } - /** {@link cgData#loadCachedInViewport(Long, Long, Long, Long, CacheType)} */ - public SearchResult getCachedInViewport(final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final CacheType cacheType) { + /** {@link cgData#loadCachedInViewport(long, long, long, long, CacheType)} */ + public SearchResult getCachedInViewport(final long centerLat, final long centerLon, final long spanLat, final long spanLon, final CacheType cacheType) { final Set<String> geocodes = storage.loadCachedInViewport(centerLat, centerLon, spanLat, spanLon, cacheType); return new SearchResult(geocodes); } - /** {@link cgData#loadStoredInViewport(Long, Long, Long, Long, CacheType)} */ - public SearchResult getStoredInViewport(final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final CacheType cacheType) { + /** {@link cgData#loadStoredInViewport(long, long, long, long, CacheType)} */ + public SearchResult getStoredInViewport(final long centerLat, final long centerLon, final long spanLat, final long spanLon, final CacheType cacheType) { final Set<String> geocodes = storage.loadStoredInViewport(centerLat, centerLon, spanLat, spanLon, cacheType); return new SearchResult(geocodes); } |
