diff options
Diffstat (limited to 'src/cgeo/geocaching')
49 files changed, 529 insertions, 442 deletions
diff --git a/src/cgeo/geocaching/LogTemplateProvider.java b/src/cgeo/geocaching/LogTemplateProvider.java index 08931a7..296a173 100644 --- a/src/cgeo/geocaching/LogTemplateProvider.java +++ b/src/cgeo/geocaching/LogTemplateProvider.java @@ -4,6 +4,8 @@ import java.util.HashMap; import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.lang3.StringUtils;
+
import android.util.Log;
@@ -118,7 +120,7 @@ public class LogTemplateProvider { }
private static int parseFindCount(String page) {
- if (page == null || page.length() == 0) {
+ if (StringUtils.isBlank(page)) {
return -1;
}
diff --git a/src/cgeo/geocaching/StaticMapsProvider.java b/src/cgeo/geocaching/StaticMapsProvider.java index 927a99c..5962460 100644 --- a/src/cgeo/geocaching/StaticMapsProvider.java +++ b/src/cgeo/geocaching/StaticMapsProvider.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.Locale; +import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -18,6 +19,7 @@ import android.content.Context; import android.util.Log; import android.view.Display; import android.view.WindowManager; +import cgeo.geocaching.utils.CollectionUtils; public class StaticMapsProvider { private static final String MARKERS_URL = "http://cgeo.carnero.cc/_markers/"; @@ -122,7 +124,7 @@ public class StaticMapsProvider { public static void downloadMaps(cgCache cache, cgSettings settings, Activity activity) { if (settings.storeOfflineMaps != 1 || cache.latitude == null - || cache.longitude == null || cache.geocode == null || cache.geocode.length() == 0) { + || cache.longitude == null || StringUtils.isNotBlank(cache.geocode)) { return; } @@ -138,7 +140,7 @@ public class StaticMapsProvider { } final StringBuilder waypoints = new StringBuilder(); - if (cache.waypoints != null && cache.waypoints.size() > 0) { + if (CollectionUtils.isNotEmpty(cache.waypoints)) { for (cgWaypoint waypoint : cache.waypoints) { if (waypoint.latitude == null && waypoint.longitude == null) { continue; diff --git a/src/cgeo/geocaching/activity/ActivityMixin.java b/src/cgeo/geocaching/activity/ActivityMixin.java index 9a50662..6440b4e 100644 --- a/src/cgeo/geocaching/activity/ActivityMixin.java +++ b/src/cgeo/geocaching/activity/ActivityMixin.java @@ -4,6 +4,8 @@ import gnu.android.app.appmanualclient.AppManualReaderClient; import java.util.ArrayList; +import org.apache.commons.lang3.StringUtils; + import android.app.Activity; import android.app.AlertDialog; import android.content.Context; @@ -35,7 +37,7 @@ public final class ActivityMixin { } public final static void goManual(final Context context, final String helpTopic) { - if (helpTopic == null || helpTopic.length() == 0) { + if (StringUtils.isBlank(helpTopic)) { return; } try { @@ -50,7 +52,7 @@ public final class ActivityMixin { } public final static void setTitle(final Activity activity, final String text) { - if (text == null) { + if (StringUtils.isBlank(text)) { return; } @@ -83,7 +85,7 @@ public final class ActivityMixin { } public final static void showToast(final Activity activity, final String text) { - if (text.length() > 0) { + if (StringUtils.isNotBlank(text)) { Toast toast = Toast.makeText(activity, text, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM, 0, 100); @@ -92,7 +94,7 @@ public final class ActivityMixin { } public final static void showShortToast(final Activity activity, final String text) { - if (text.length() > 0) { + if (StringUtils.isNotBlank(text)) { Toast toast = Toast.makeText(activity, text, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM, 0, 100); @@ -101,7 +103,7 @@ public final class ActivityMixin { } public static final void helpDialog(final Activity activity, final String title, final String message) { - if (message == null || message.length() == 0) { + if (StringUtils.isBlank(message)) { return; } diff --git a/src/cgeo/geocaching/apps/AbstractApp.java b/src/cgeo/geocaching/apps/AbstractApp.java index 42ce677..190bf5e 100644 --- a/src/cgeo/geocaching/apps/AbstractApp.java +++ b/src/cgeo/geocaching/apps/AbstractApp.java @@ -8,6 +8,7 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import cgeo.geocaching.cgSettings; +import cgeo.geocaching.utils.CollectionUtils; public abstract class AbstractApp implements App { @@ -60,7 +61,7 @@ public abstract class AbstractApp implements App { final List<ResolveInfo> list = packageManager.queryIntentActivities( intent, PackageManager.MATCH_DEFAULT_ONLY); - return list.size() > 0; + return (CollectionUtils.isNotEmpty(list)); } @Override diff --git a/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java b/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java index 8291365..c184bd0 100644 --- a/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java +++ b/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java @@ -1,5 +1,7 @@ package cgeo.geocaching.apps.cache; +import org.apache.commons.lang3.ArrayUtils; + import android.app.Activity; import android.content.res.Resources; import android.util.Log; @@ -13,7 +15,7 @@ public final class GeneralAppsFactory extends AbstractAppFactory { private static GeneralApp[] apps = new GeneralApp[] {}; private static GeneralApp[] getGeneralApps(Resources res) { - if (null == apps || 0 == apps.length) { + if (ArrayUtils.isEmpty(apps)) { apps = new GeneralApp[] { new GccApp(res), new WhereYouGoApp(res) }; } diff --git a/src/cgeo/geocaching/apps/cache/navi/LocusApp.java b/src/cgeo/geocaching/apps/cache/navi/LocusApp.java index 41b9896..6abcf4a 100644 --- a/src/cgeo/geocaching/apps/cache/navi/LocusApp.java +++ b/src/cgeo/geocaching/apps/cache/navi/LocusApp.java @@ -4,6 +4,8 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.util.ArrayList; +import org.apache.commons.lang3.StringUtils; + import android.app.Activity; import android.content.Intent; import android.content.res.Resources; @@ -15,6 +17,7 @@ import cgeo.geocaching.cgCache; import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgWaypoint; import cgeo.geocaching.apps.AbstractLocusApp; +import cgeo.geocaching.utils.CollectionUtils; class LocusApp extends AbstractLocusApp implements NavigationApp { @@ -83,22 +86,18 @@ class LocusApp extends AbstractLocusApp implements NavigationApp { } // name - if (cache != null && cache.name != null - && cache.name.length() > 0) { + if (cache != null && StringUtils.isNotBlank(cache.name)) { dos.writeUTF(cache.name); - } else if (waypoint != null && waypoint.name != null - && waypoint.name.length() > 0) { + } else if (waypoint != null && StringUtils.isNotBlank(waypoint.name)) { dos.writeUTF(waypoint.name); } else { dos.writeUTF(""); } // description - if (cache != null && cache.geocode != null - && cache.geocode.length() > 0) { + if (cache != null && StringUtils.isNotBlank(cache.geocode)) { dos.writeUTF(cache.geocode.toUpperCase()); - } else if (waypoint != null && waypoint.lookup != null - && waypoint.lookup.length() > 0) { + } else if (waypoint != null && StringUtils.isNotBlank(waypoint.lookup)) { dos.writeUTF(waypoint.lookup.toUpperCase()); } else { dos.writeUTF(""); @@ -106,8 +105,7 @@ class LocusApp extends AbstractLocusApp implements NavigationApp { // additional data :: keyword, button title, package, activity, // data name, data content - if (cache != null && cache.geocode != null - && cache.geocode.length() > 0) { + if (cache != null && StringUtils.isNotBlank(cache.geocode)) { dos.writeUTF("intent;c:geo;cgeo.geocaching;cgeo.geocaching.cgeodetail;geocode;" + cache.geocode); } else if (waypoint != null && waypoint.id != null @@ -132,7 +130,7 @@ class LocusApp extends AbstractLocusApp implements NavigationApp { } // cache waypoints - if (waypoints != null && waypoints.isEmpty() == false) { + if (CollectionUtils.isNotEmpty(waypoints)) { for (cgWaypoint wp : waypoints) { if (wp == null || wp.latitude == null || wp.longitude == null) { @@ -159,14 +157,14 @@ class LocusApp extends AbstractLocusApp implements NavigationApp { } // name - if (wp.lookup != null && wp.lookup.length() > 0) { + if (StringUtils.isNotBlank(wp.lookup)) { dos.writeUTF(wp.lookup.toUpperCase()); } else { dos.writeUTF(""); } // description - if (wp.name != null && wp.name.length() > 0) { + if (StringUtils.isNotBlank(wp.name)) { dos.writeUTF(wp.name); } else { dos.writeUTF(""); diff --git a/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java b/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java index e496e33..0bb13da 100644 --- a/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java +++ b/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java @@ -2,6 +2,8 @@ package cgeo.geocaching.apps.cache.navi; import java.util.ArrayList; +import org.apache.commons.lang3.ArrayUtils; + import android.app.Activity; import android.content.res.Resources; import android.util.Log; @@ -17,7 +19,7 @@ public final class NavigationAppFactory extends AbstractAppFactory { private static NavigationApp[] apps = new NavigationApp[] {}; private static NavigationApp[] getNavigationApps(Resources res) { - if (null == apps || 0 == apps.length) { + if (ArrayUtils.isEmpty(apps)) { apps = new NavigationApp[] { // compass new RadarApp(res), diff --git a/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java b/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java index 416388d..1b85583 100644 --- a/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java +++ b/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java @@ -3,6 +3,8 @@ package cgeo.geocaching.apps.cachelist; import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang3.ArrayUtils; + import android.app.Activity; import android.content.res.Resources; import android.util.Log; @@ -20,7 +22,7 @@ public final class CacheListAppFactory extends AbstractAppFactory { private static CacheListApp[] getMultiPointNavigationApps( Resources res) { - if (null == apps || 0 == apps.length) { + if (ArrayUtils.isEmpty(apps)) { apps = new CacheListApp[] { new InternalCacheListMap(res), new LocusCacheListApp(res) }; diff --git a/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java b/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java index a9c438b..f058e93 100644 --- a/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java +++ b/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java @@ -5,6 +5,8 @@ import java.io.DataOutputStream; import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang3.StringUtils; + import android.app.Activity; import android.content.Intent; import android.content.res.Resources; @@ -61,21 +63,21 @@ class LocusCacheListApp extends AbstractLocusApp implements CacheListApp { } // name - if (cache.geocode != null && cache.geocode.length() > 0) { + if (StringUtils.isNotBlank(cache.geocode)) { dos.writeUTF(cache.geocode.toUpperCase()); } else { dos.writeUTF(""); } // description - if (cache.name != null && cache.name.length() > 0) { + if (StringUtils.isNotBlank(cache.name)) { dos.writeUTF(cache.name); } else { dos.writeUTF(""); } // additional data :: keyword, button title, package, activity, data name, data content - if (cache.geocode != null && cache.geocode.length() > 0) { + if (StringUtils.isNotBlank(cache.geocode)) { dos.writeUTF("intent;c:geo;cgeo.geocaching;cgeo.geocaching.cgeodetail;geocode;" + cache.geocode); } else { dos.writeUTF(""); diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java index 7e52d00..f2eeae8 100644 --- a/src/cgeo/geocaching/cgBase.java +++ b/src/cgeo/geocaching/cgBase.java @@ -46,6 +46,8 @@ import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; import org.json.JSONArray; import org.json.JSONObject; @@ -67,6 +69,7 @@ import android.util.Log; import android.widget.EditText; import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.files.LocParser; +import cgeo.geocaching.utils.CollectionUtils; public class cgBase { @@ -461,7 +464,7 @@ public class cgBase { * put viewstates into request parameters */ private static void setViewstates(String[] viewstates, HashMap<String, String> params) { - if (viewstates == null || viewstates.length == 0) + if (ArrayUtils.isEmpty(viewstates)) return; params.put("__VIEWSTATE", viewstates[0]); if (viewstates.length > 1) { @@ -479,21 +482,6 @@ public class cgBase { setViewstates(getViewstates(page), params); } - /** - * checks if an Array of Strings is empty or not. Empty means: - * - Array is null - * - or all elements are null or empty strings - */ - public static boolean isEmpty(String[] a) { - if (a == null) - return true; - - for (String s: a) - if (s != null && s.length() > 0) - return false; - - return true; - } public class loginThread extends Thread { @@ -519,7 +507,7 @@ public class cgBase { loginResponse = request(true, host, path, "GET", new HashMap<String, String>(), false, false, false); loginData = loginResponse.getData(); - if (loginData != null && loginData.length() > 0) { + if (StringUtils.isNotBlank(loginData)) { if (checkLogin(loginData)) { Log.i(cgSettings.tag, "Already logged in Geocaching.com as " + loginStart.get("username")); @@ -530,7 +518,7 @@ public class cgBase { viewstates = getViewstates(loginData); - if (isEmpty(viewstates)) { + if (ArrayUtils.isEmpty(viewstates)) { Log.e(cgSettings.tag, "cgeoBase.login: Failed to find viewstates"); return -1; // no viewstates } @@ -542,7 +530,7 @@ public class cgBase { final HashMap<String, String> login = settings.getLogin(); final HashMap<String, String> params = new HashMap<String, String>(); - if (login == null || login.get("username") == null || login.get("username").length() == 0 || login.get("password") == null || login.get("password").length() == 0) { + if (login == null || StringUtils.isEmpty(login.get("username")) || StringUtils.isEmpty(login.get("password"))) { Log.e(cgSettings.tag, "cgeoBase.login: No login information stored"); return -3; } @@ -560,7 +548,7 @@ public class cgBase { loginResponse = request(true, host, path, "POST", params, false, false, false); loginData = loginResponse.getData(); - if (loginData != null && loginData.length() > 0) { + if (StringUtils.isNotBlank(loginData)) { if (checkLogin(loginData)) { Log.i(cgSettings.tag, "Successfully logged in Geocaching.com as " + login.get("username")); @@ -595,7 +583,7 @@ public class cgBase { } public static Boolean checkLogin(String page) { - if (page == null || page.length() == 0) { + if (StringUtils.isBlank(page)) { Log.e(cgSettings.tag, "cgeoBase.checkLogin: No page given"); return false; } @@ -628,7 +616,7 @@ public class cgBase { } public cgCacheWrap parseSearch(cgSearchThread thread, String url, String page, boolean showCaptcha) { - if (page == null || page.length() == 0) { + if (StringUtils.isBlank(page)) { Log.e(cgSettings.tag, "cgeoBase.parseSearch: No page given"); return null; } @@ -669,7 +657,7 @@ public class cgBase { if (recaptchaJsParam != null) { final String recaptchaJs = request(false, "www.google.com", "/recaptcha/api/challenge", "GET", "k=" + urlencode_rfc3986(recaptchaJsParam.trim()), 0, true).getData(); - if (recaptchaJs != null && recaptchaJs.length() > 0) { + if (StringUtils.isNotBlank(recaptchaJs)) { final Matcher matcherRecaptchaChallenge = patternRecaptchaChallenge.matcher(recaptchaJs); while (matcherRecaptchaChallenge.find()) { if (matcherRecaptchaChallenge.groupCount() > 0) { @@ -683,7 +671,7 @@ public class cgBase { Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse recaptcha challenge"); } - if (thread != null && recaptchaChallenge != null && recaptchaChallenge.length() > 0) { + if (thread != null && StringUtils.isNotBlank(recaptchaChallenge)) { thread.setChallenge(recaptchaChallenge); thread.notifyNeed(); } @@ -821,7 +809,7 @@ public class cgBase { Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse cache inventory (1)"); } - if (inventoryPre != null && inventoryPre.trim().length() > 0) { + if (StringUtils.isNotBlank(inventoryPre)) { try { final Matcher matcherTbsInside = patternTbsInside.matcher(inventoryPre); while (matcherTbsInside.find()) { @@ -923,7 +911,7 @@ public class cgBase { recaptchaText = thread.getText(); } - if (cids.size() > 0 && (recaptchaChallenge == null || (recaptchaChallenge != null && recaptchaText != null && recaptchaText.length() > 0))) { + if (cids.size() > 0 && (recaptchaChallenge == null || (recaptchaChallenge != null && StringUtils.isNotBlank(recaptchaText)))) { Log.i(cgSettings.tag, "Trying to get .loc for " + cids.size() + " caches"); try { @@ -932,7 +920,7 @@ public class cgBase { final String path = "/seek/nearest.aspx"; final StringBuilder params = new StringBuilder(); params.append("__EVENTTARGET=&__EVENTARGUMENT="); - if (caches.viewstates != null && caches.viewstates.length > 0) { + if (ArrayUtils.isNotEmpty(caches.viewstates)) { params.append("&__VIEWSTATE="); params.append(urlencode_rfc3986(caches.viewstates[0])); if (caches.viewstates.length > 1) { @@ -948,7 +936,7 @@ public class cgBase { params.append(urlencode_rfc3986(cid)); } - if (recaptchaChallenge != null && recaptchaText != null && recaptchaText.length() > 0) { + if (recaptchaChallenge != null && StringUtils.isNotBlank(recaptchaText)) { params.append("&recaptcha_challenge_field="); params.append(urlencode_rfc3986(recaptchaChallenge)); params.append("&recaptcha_response_field="); @@ -958,7 +946,7 @@ public class cgBase { final String coordinates = request(false, host, path, "POST", params.toString(), 0, true).getData(); - if (coordinates != null && coordinates.length() > 0) { + if ( StringUtils.isNotBlank(coordinates)) { if (coordinates.indexOf("You have not agreed to the license agreement. The license agreement is required before you can start downloading GPX or LOC files from Geocaching.com") > -1) { Log.i(cgSettings.tag, "User has not agreed to the license agreement. Can\'t download .loc file."); @@ -991,7 +979,7 @@ public class cgBase { try { final HashMap<String, cgRating> ratings = getRating(guids, null); - if (ratings != null) { + if (CollectionUtils.isNotEmpty(ratings)) { // save found cache coordinates for (cgCache oneCache : caches.cacheList) { if (ratings.containsKey(oneCache.guid)) { @@ -1012,7 +1000,7 @@ public class cgBase { } public static cgCacheWrap parseMapJSON(String url, String data) { - if (data == null || data.length() == 0) { + if (StringUtils.isEmpty(data)) { Log.e(cgSettings.tag, "cgeoBase.parseMapJSON: No page given"); return null; } @@ -1024,14 +1012,14 @@ public class cgBase { final JSONObject yoDawg = new JSONObject(data); final String json = yoDawg.getString("d"); - if (json == null || json.length() == 0) { + if (StringUtils.isBlank(json)) { Log.e(cgSettings.tag, "cgeoBase.parseMapJSON: No JSON inside JSON"); return null; } final JSONObject dataJSON = new JSONObject(json); final JSONObject extra = dataJSON.getJSONObject("cs"); - if (extra != null && extra.length() > 0) { + if ( StringUtils.isNotBlank(data)) { int count = extra.getInt("count"); if (count > 0 && extra.has("cc")) { @@ -1096,7 +1084,7 @@ public class cgBase { } public cgCacheWrap parseCache(String page, int reason) { - if (page == null || page.length() == 0) { + if (StringUtils.isBlank(page)) { Log.e(cgSettings.tag, "cgeoBase.parseCache: No page given"); return null; } @@ -1218,7 +1206,7 @@ public class cgBase { tableInside = tableInside.substring(0, pos); - if (tableInside != null && tableInside.length() > 0) { + if (StringUtils.isNotBlank(tableInside)) { // cache terrain try { final Matcher matcherTerrain = patternTerrain.matcher(tableInside); @@ -1518,7 +1506,7 @@ public class cgBase { if (matcherInventory.groupCount() > 1) { final String inventoryPre = matcherInventory.group(2); - if (inventoryPre != null && inventoryPre.length() > 0) { + if (StringUtils.isNotBlank(inventoryPre)) { final Matcher matcherInventoryInside = patternInventoryInside.matcher(inventoryPre); while (matcherInventoryInside.find()) { @@ -1553,11 +1541,9 @@ public class cgBase { String typeStr = matcherLog.group(1); String countStr = matcherLog.group(2); - if (typeStr != null - && typeStr.length() > 0 + if (StringUtils.isNotBlank(typeStr) && logTypes.containsKey(typeStr.toLowerCase()) - && countStr != null - && countStr.length() > 0) + && StringUtils.isNotBlank(countStr)) { cache.logCounts.put(logTypes.get(typeStr.toLowerCase()), Integer.parseInt(countStr)); } @@ -1713,8 +1699,16 @@ public class cgBase { // waypoint name try { final Matcher matcherWpName = patternWpName.matcher(wp[6]); + while (matcherWpName.find()) { + if (matcherWpName.groupCount() > 0) { + waypoint.name = matcherWpName.group(1); + if (StringUtils.isNotBlank(waypoint.name)) { + waypoint.name = waypoint.name.trim(); + } + } if (matcherWpName.find() && matcherWpName.groupCount() > 0) { waypoint.name = matcherWpName.group(1).trim(); + } } } catch (Exception e) { // failed to parse name @@ -1784,13 +1778,13 @@ public class cgBase { } private static void checkFields(cgCache cache) { - if (cache.geocode == null || cache.geocode.length() == 0) { + if (StringUtils.isEmpty(cache.geocode)) { Log.w(cgSettings.tag, "geo code not parsed correctly"); } - if (cache.name == null || cache.name.length() == 0) { + if (StringUtils.isEmpty(cache.name)) { Log.w(cgSettings.tag, "name not parsed correctly"); } - if (cache.guid == null || cache.guid.length() == 0) { + if (StringUtils.isEmpty(cache.guid)) { Log.w(cgSettings.tag, "guid not parsed correctly"); } if (cache.terrain == null || cache.terrain == 0.0) { @@ -1799,10 +1793,10 @@ public class cgBase { if (cache.difficulty == null || cache.difficulty == 0.0) { Log.w(cgSettings.tag, "difficulty not parsed correctly"); } - if (cache.owner == null || cache.owner.length() == 0) { + if (StringUtils.isEmpty(cache.owner)) { Log.w(cgSettings.tag, "owner not parsed correctly"); } - if (cache.ownerReal == null || cache.ownerReal.length() == 0) { + if (StringUtils.isEmpty(cache.ownerReal)) { Log.w(cgSettings.tag, "owner real not parsed correctly"); } if (cache.hidden == null) { @@ -1811,10 +1805,10 @@ public class cgBase { if (cache.favouriteCnt == null) { Log.w(cgSettings.tag, "favoriteCount not parsed correctly"); } - if (cache.size == null || cache.size.length() == 0) { + if (StringUtils.isEmpty(cache.size)) { Log.w(cgSettings.tag, "size not parsed correctly"); } - if (cache.type == null || cache.type.length() == 0) { + if (StringUtils.isNotBlank(cache.type)) { Log.w(cgSettings.tag, "type not parsed correctly"); } if (cache.latitude == null) { @@ -1823,7 +1817,7 @@ public class cgBase { if (cache.longitude == null) { Log.w(cgSettings.tag, "longitude not parsed correctly"); } - if (cache.location == null || cache.location.length() == 0) { + if (StringUtils.isEmpty(cache.location)) { Log.w(cgSettings.tag, "location not parsed correctly"); } } @@ -1841,7 +1835,7 @@ public class cgBase { public Date parseGcCustomDate(String input) throws ParseException { - if (input == null) + if (StringUtils.isBlank(input)) { throw new ParseException("Input is null", 0); } @@ -1891,10 +1885,10 @@ public class cgBase { ArrayList<String> guids = null; ArrayList<String> geocodes = null; - if (guid != null && guid.length() > 0) { + if (StringUtils.isNotBlank(guid)) { guids = new ArrayList<String>(); guids.add(guid); - } else if (geocode != null && geocode.length() > 0) { + } else if (StringUtils.isNotBlank(geocode)) { geocodes = new ArrayList<String>(); geocodes.add(geocode); } else { @@ -1927,7 +1921,7 @@ public class cgBase { params.put("password", login.get("password")); } } - if (guids != null && guids.size() > 0) { + if (CollectionUtils.isNotEmpty(guids)) { params.put("cacheIds", implode(",", guids.toArray())); } else { params.put("waypoints", implode(",", geocodes.toArray())); @@ -2019,7 +2013,7 @@ public class cgBase { } } - if (guid != null) { + if (StringUtils.isNotBlank(guid)) { ratings.put(guid, rating); } } @@ -2031,7 +2025,7 @@ public class cgBase { } public cgTrackable parseTrackable(String page) { - if (page == null || page.length() == 0) { + if (StringUtils.isBlank(page)) { Log.e(cgSettings.tag, "cgeoBase.parseTrackable: No page given"); return null; } @@ -2083,7 +2077,7 @@ public class cgBase { } // trackable type - if (trackable.name != null && trackable.name.length() > 0) { + if (StringUtils.isNotBlank(trackable.name)) { try { final Matcher matcherType = PATTERN_TRACKABLE_Type.matcher(page); if (matcherType.find() && matcherType.groupCount() > 0) { @@ -2268,7 +2262,7 @@ public class cgBase { } public static ArrayList<Integer> parseTypes(String page) { - if (page == null || page.length() == 0) { + if (StringUtils.isEmpty(page)) { return null; } @@ -2302,7 +2296,7 @@ public class cgBase { } public static ArrayList<cgTrackableLog> parseTrackableLog(String page) { - if (page == null || page.length() == 0) { + if (StringUtils.isEmpty(page)) { return null; } @@ -2384,7 +2378,7 @@ public class cgBase { } public static String stripParagraphs(String text) { - if (text == null) { + if (StringUtils.isBlank(text)) { return ""; } @@ -2400,7 +2394,7 @@ public class cgBase { } public static String stripTags(String text) { - if (text == null) { + if (StringUtils.isBlank(text)) { return ""; } @@ -2412,28 +2406,6 @@ public class cgBase { return text.trim(); } - public static String capitalizeSentence(String sentence) { - if (sentence == null) { - return ""; - } - - final String[] word = sentence.split(" "); - - for (int i = 0; i < word.length; i++) { - word[i] = capitalizeWord(word[i]); - } - - return implode(" ", word); - } - - public static String capitalizeWord(String word) { - if (word.length() == 0) { - return word; - } - - return (word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase()); - } - public static Double parseDistance(String dst) { Double distance = null; @@ -2769,12 +2741,12 @@ public class cgBase { cgCacheWrap caches = new cgCacheWrap(); String url = app.getUrl(searchId); - if (url == null || url.length() == 0) { + if (StringUtils.isBlank(url)) { Log.e(cgSettings.tag, "cgeoBase.searchByNextPage: No url found"); return searchId; } - if (isEmpty(viewstates)) { + if (ArrayUtils.isEmpty(viewstates)) { Log.e(cgSettings.tag, "cgeoBase.searchByNextPage: No viewstate given"); return searchId; } @@ -2823,7 +2795,7 @@ public class cgBase { } } - if (page == null || page.length() == 0) { + if (StringUtils.isBlank(page)) { Log.e(cgSettings.tag, "cgeoBase.searchByNextPage: No data from server"); return searchId; } @@ -2854,13 +2826,13 @@ public class cgBase { String geocode = parameters.get("geocode"); String guid = parameters.get("guid"); - if ((geocode == null || geocode.length() == 0) && ((guid == null || guid.length() == 0))) { + if (StringUtils.isBlank(geocode) && StringUtils.isBlank(guid)) { Log.e(cgSettings.tag, "cgeoBase.searchByGeocode: No geocode nor guid given"); return null; } if (forceReload == false && reason == 0 && (app.isOffline(geocode, guid) || app.isThere(geocode, guid, true, true))) { - if ((geocode == null || geocode.length() == 0) && guid != null && guid.length() > 0) { + if (StringUtils.isBlank(geocode) && StringUtils.isBlank(guid)) { geocode = app.getGeocode(guid); } @@ -2880,9 +2852,9 @@ public class cgBase { final String path = "/seek/cache_details.aspx"; final String method = "GET"; final HashMap<String, String> params = new HashMap<String, String>(); - if (geocode != null && geocode.length() > 0) { + if (StringUtils.isNotBlank(geocode)) { params.put("wp", geocode); - } else if (guid != null && guid.length() > 0) { + } else if (StringUtils.isNotBlank(guid)) { params.put("guid", guid); } params.put("decrypt", "y"); @@ -2891,9 +2863,9 @@ public class cgBase { String page = requestLogged(false, host, path, method, params, false, false, false); - if (page == null || page.length() == 0) { + if (StringUtils.isEmpty(page)) { if (app.isThere(geocode, guid, true, false)) { - if ((geocode == null || geocode.length() == 0) && guid != null && guid.length() > 0) { + if (StringUtils.isBlank(geocode) && StringUtils.isBlank(guid)) { Log.i(cgSettings.tag, "Loading old cache from cache."); geocode = app.getGeocode(guid); @@ -2918,10 +2890,10 @@ public class cgBase { final cgCacheWrap caches = parseCache(page, reason); if (caches == null || caches.cacheList == null || caches.cacheList.isEmpty()) { - if (caches != null && caches.error != null && caches.error.length() > 0) { + if (caches != null && StringUtils.isNotBlank(caches.error)) { search.error = caches.error; } - if (caches != null && caches.url != null && caches.url.length() > 0) { + if (caches != null && StringUtils.isNotBlank(caches.url)) { search.url = caches.url; } @@ -2938,10 +2910,10 @@ public class cgBase { final ArrayList<cgCache> cacheList = new ArrayList<cgCache>(); if (caches != null) { - if (caches.error != null && caches.error.length() > 0) { + if (StringUtils.isNotBlank(caches.error)) { search.error = caches.error; } - if (caches.url != null && caches.url.length() > 0) { + if (StringUtils.isNotBlank(caches.url)) { search.url = caches.url; } search.viewstates = caches.viewstates; @@ -3016,17 +2988,17 @@ public class cgBase { cgCacheWrap caches = new cgCacheWrap(); String cacheType = parameters.get("cachetype"); - if (latitude == null || latitude.length() == 0) { + if (StringUtils.isBlank(latitude)) { Log.e(cgSettings.tag, "cgeoBase.searchByCoords: No latitude given"); return null; } - if (longitude == null || longitude.length() == 0) { + if (StringUtils.isBlank(longitude)) { Log.e(cgSettings.tag, "cgeoBase.searchByCoords: No longitude given"); return null; } - if (cacheType != null && cacheType.length() == 0) { + if (StringUtils.isBlank(latitude)) { cacheType = null; } @@ -3045,7 +3017,7 @@ public class cgBase { final String url = "http://" + host + path + "?" + prepareParameters(params, false, true); String page = requestLogged(false, host, path, method, params, false, false, true); - if (page == null || page.length() == 0) { + if (StringUtils.isBlank(page)) { Log.e(cgSettings.tag, "cgeoBase.searchByCoords: No data from server"); return null; } @@ -3062,10 +3034,10 @@ public class cgBase { final ArrayList<cgCache> cacheList = new ArrayList<cgCache>(); if (caches != null) { - if (caches.error != null && caches.error.length() > 0) { + if (StringUtils.isNotBlank(caches.error)) { search.error = caches.error; } - if (caches.url != null && caches.url.length() > 0) { + if (StringUtils.isNotBlank(caches.url)) { search.url = caches.url; } search.viewstates = caches.viewstates; @@ -3090,12 +3062,12 @@ public class cgBase { cgCacheWrap caches = new cgCacheWrap(); String cacheType = parameters.get("cachetype"); - if (keyword == null || keyword.length() == 0) { + if (StringUtils.isBlank(keyword)) { Log.e(cgSettings.tag, "cgeoBase.searchByKeyword: No keyword given"); return null; } - if (cacheType != null && cacheType.length() == 0) { + if (StringUtils.isBlank(cacheType)) { cacheType = null; } @@ -3113,7 +3085,7 @@ public class cgBase { final String url = "http://" + host + path + "?" + prepareParameters(params, false, true); String page = requestLogged(false, host, path, method, params, false, false, true); - if (page == null || page.length() == 0) { + if (StringUtils.isBlank(page)) { Log.e(cgSettings.tag, "cgeoBase.searchByKeyword: No data from server"); return null; } @@ -3130,10 +3102,10 @@ public class cgBase { final ArrayList<cgCache> cacheList = new ArrayList<cgCache>(); if (caches != null) { - if (caches.error != null && caches.error.length() > 0) { + if (StringUtils.isNotBlank(caches.error)) { search.error = caches.error; } - if (caches.url != null && caches.url.length() > 0) { + if (StringUtils.isNotBlank(caches.url)) { search.url = caches.url; } search.viewstates = caches.viewstates; @@ -3158,12 +3130,12 @@ public class cgBase { cgCacheWrap caches = new cgCacheWrap(); String cacheType = parameters.get("cachetype"); - if (userName == null || userName.length() == 0) { + if (StringUtils.isBlank(userName)) { Log.e(cgSettings.tag, "cgeoBase.searchByUsername: No user name given"); return null; } - if (cacheType != null && cacheType.length() == 0) { + if (StringUtils.isBlank(cacheType)) { cacheType = null; } @@ -3187,7 +3159,7 @@ public class cgBase { final String url = "http://" + host + path + "?" + prepareParameters(params, my, true); String page = requestLogged(false, host, path, method, params, false, my, true); - if (page == null || page.length() == 0) { + if (StringUtils.isBlank(page)) { Log.e(cgSettings.tag, "cgeoBase.searchByUsername: No data from server"); return null; } @@ -3198,16 +3170,16 @@ public class cgBase { } if (app == null) { - Log.e(cgSettings.tag, "cgeoBase.searchByCoords: No application found"); + Log.e(cgSettings.tag, "cgeoBase.searchByUsername: No application found"); return null; } final ArrayList<cgCache> cacheList = new ArrayList<cgCache>(); if (caches != null) { - if (caches.error != null && caches.error.length() > 0) { + if (StringUtils.isNotBlank(caches.error)) { search.error = caches.error; } - if (caches.url != null && caches.url.length() > 0) { + if (StringUtils.isNotBlank(caches.url)) { search.url = caches.url; } search.viewstates = caches.viewstates; @@ -3232,12 +3204,12 @@ public class cgBase { cgCacheWrap caches = new cgCacheWrap(); String cacheType = parameters.get("cachetype"); - if (userName == null || userName.length() == 0) { + if (StringUtils.isBlank(userName)) { Log.e(cgSettings.tag, "cgeoBase.searchByOwner: No user name given"); return null; } - if (cacheType != null && cacheType.length() == 0) { + if (StringUtils.isBlank(cacheType)) { cacheType = null; } @@ -3255,7 +3227,7 @@ public class cgBase { final String url = "http://" + host + path + "?" + prepareParameters(params, false, true); String page = requestLogged(false, host, path, method, params, false, false, true); - if (page == null || page.length() == 0) { + if (StringUtils.isBlank(page)) { Log.e(cgSettings.tag, "cgeoBase.searchByOwner: No data from server"); return null; } @@ -3272,10 +3244,10 @@ public class cgBase { final ArrayList<cgCache> cacheList = new ArrayList<cgCache>(); if (caches != null) { - if (caches.error != null && caches.error.length() > 0) { + if (StringUtils.isNotBlank(caches.error)) { search.error = caches.error; } - if (caches.url != null && caches.url.length() > 0) { + if (StringUtils.isNotBlank(caches.url)) { search.url = caches.url; } search.viewstates = caches.viewstates; @@ -3311,7 +3283,7 @@ public class cgBase { String page = null; - if (latMin == null || latMin.length() == 0 || latMax == null || latMax.length() == 0 || lonMin == null || lonMin.length() == 0 || lonMax == null || lonMax.length() == 0) { + if (StringUtils.isBlank(latMin) || StringUtils.isBlank(latMax) || StringUtils.isBlank(lonMin) || StringUtils.isBlank(lonMax)) { Log.e(cgSettings.tag, "cgeoBase.searchByViewport: Not enough parameters to recognize viewport"); return null; } @@ -3324,7 +3296,7 @@ public class cgBase { final String url = "http://" + host + path + "?" + params; page = requestJSONgc(host, path, params); - if (page == null || page.length() == 0) { + if (StringUtils.isBlank(page)) { Log.e(cgSettings.tag, "cgeoBase.searchByViewport: No data from server"); return null; } @@ -3341,16 +3313,16 @@ public class cgBase { final ArrayList<cgCache> cacheList = new ArrayList<cgCache>(); if (caches != null) { - if (caches.error != null && caches.error.length() > 0) { + if (StringUtils.isNotBlank(caches.error)) { search.error = caches.error; } - if (caches.url != null && caches.url.length() > 0) { + if (StringUtils.isNotBlank(caches.url)) { search.url = caches.url; } search.viewstates = caches.viewstates; search.totalCnt = caches.totalCnt; - if (caches.cacheList != null && caches.cacheList.size() > 0) { + if (CollectionUtils.isNotEmpty(caches.cacheList)) { for (cgCache cache : caches.cacheList) { if ((settings.excludeDisabled == 0 || (settings.excludeDisabled == 1 && cache.disabled == false)) && (settings.excludeMine == 0 || (settings.excludeMine == 1 && cache.own == false)) @@ -3391,7 +3363,7 @@ public class cgBase { final String data = request(false, host, path, method, params, false, false, false).getData(); - if (data == null || data.length() == 0) { + if (StringUtils.isBlank(data)) { Log.e(cgSettings.tag, "cgeoBase.getGeocachersInViewport: No data from server"); return null; } @@ -3438,7 +3410,7 @@ public class cgBase { final String id = parameters.get("id"); cgTrackable trackable = new cgTrackable(); - if ((geocode == null || geocode.length() == 0) && (guid == null || guid.length() == 0) && (id == null || id.length() == 0)) { + if (StringUtils.isBlank(geocode) || StringUtils.isBlank(guid) || StringUtils.isBlank(id)) { Log.e(cgSettings.tag, "cgeoBase.searchTrackable: No geocode nor guid nor id given"); return null; } @@ -3447,17 +3419,17 @@ public class cgBase { final String path = "/track/details.aspx"; final String method = "GET"; final HashMap<String, String> params = new HashMap<String, String>(); - if (geocode != null && geocode.length() > 0) { + if (StringUtils.isNotBlank(geocode)) { params.put("tracker", geocode); - } else if (guid != null && guid.length() > 0) { + } else if (StringUtils.isNotBlank(guid)) { params.put("guid", guid); - } else if (id != null && id.length() > 0) { + } else if (StringUtils.isNotBlank(id)) { params.put("id", id); } String page = requestLogged(false, host, path, method, params, false, false, false); - if (page == null || page.length() == 0) { + if (StringUtils.isBlank(page)) { Log.e(cgSettings.tag, "cgeoBase.searchTrackable: No data from server"); return trackable; } @@ -3473,7 +3445,7 @@ public class cgBase { public int postLog(cgeoapplication app, String geocode, String cacheid, String[] viewstates, int logType, int year, int month, int day, String log, ArrayList<cgTrackableLog> trackables) { - if (isEmpty(viewstates)) { + if (ArrayUtils.isEmpty(viewstates)) { Log.e(cgSettings.tag, "cgeoBase.postLog: No viewstate given"); return 1000; } @@ -3483,7 +3455,7 @@ public class cgBase { return 1000; } - if (log == null || log.length() == 0) { + if (StringUtils.isBlank(log)) { Log.e(cgSettings.tag, "cgeoBase.postLog: No log text given"); return 1001; } @@ -3557,7 +3529,7 @@ public class cgBase { } } - if (page == null || page.length() == 0) { + if (StringUtils.isBlank(page)) { Log.e(cgSettings.tag, "cgeoBase.postLog: No data from server"); return 1002; } @@ -3570,7 +3542,7 @@ public class cgBase { if (matcher.find() && matcher.groupCount() > 0) { final String[] viewstatesConfirm = getViewstates(page); - if (isEmpty(viewstatesConfirm)) { + if (ArrayUtils.isEmpty(viewstatesConfirm)) { Log.e(cgSettings.tag, "cgeoBase.postLog: No viewstate for confirm log"); return 1000; } @@ -3635,7 +3607,7 @@ public class cgBase { public int postLogTrackable(String tbid, String trackingCode, String[] viewstates, int logType, int year, int month, int day, String log) { - if (isEmpty(viewstates)) { + if (ArrayUtils.isEmpty(viewstates)) { Log.e(cgSettings.tag, "cgeoBase.postLogTrackable: No viewstate given"); return 1000; } @@ -3645,7 +3617,7 @@ public class cgBase { return 1000; } - if (log == null || log.length() == 0) { + if (StringUtils.isBlank(log)) { Log.e(cgSettings.tag, "cgeoBase.postLogTrackable: No log text given"); return 1001; } @@ -3689,7 +3661,7 @@ public class cgBase { } } - if (page == null || page.length() == 0) { + if (StringUtils.isBlank(page)) { Log.e(cgSettings.tag, "cgeoBase.postLogTrackable: No data from server"); return 1002; } @@ -3719,7 +3691,7 @@ public class cgBase { String page = requestLogged(false, "www.geocaching.com", "/my/watchlist.aspx?w=" + cache.cacheid, "POST", null, false, false, false); - if (page == null || page.length() == 0) { + if (StringUtils.isBlank(page)) { Log.e(cgSettings.tag, "cgBase.addToWatchlist: No data from server"); return -1; // error } @@ -3747,7 +3719,7 @@ public class cgBase { String page = requestLogged(false, host, path, method, null, false, false, false); - if (page == null || page.length() == 0) { + if (StringUtils.isBlank(page)) { Log.e(cgSettings.tag, "cgBase.removeFromWatchlist: No data from server"); return -1; // error } @@ -3828,7 +3800,7 @@ public class cgBase { if (app == null) { return; } - if (settings == null || settings.tokenPublic == null || settings.tokenPublic.length() == 0 || settings.tokenSecret == null || settings.tokenSecret.length() == 0) { + if (settings == null || StringUtils.isBlank(settings.tokenPublic) || StringUtils.isNotBlank(settings.tokenSecret)) { return; } @@ -4213,7 +4185,7 @@ public class cgBase { response = request(secureRedir, newLocation.getHost(), newLocation.getPath(), "GET", new HashMap<String, String>(), requestId, false, false, false); } } else { - if (buffer != null && buffer.length() > 0) { + if (StringUtils.isNotBlank(buffer)) { replaceWhitespace(buffer); String data = buffer.toString(); buffer = null; @@ -4273,7 +4245,7 @@ public class cgBase { if (cookiesDone == null) { Map<String, ?> prefsValues = prefs.getAll(); - if (prefsValues != null && prefsValues.size() > 0) { + if (CollectionUtils.isNotEmpty(prefsValues)) { final Set<? extends Map.Entry<String, ?>> entrySet = prefsValues.entrySet(); final ArrayList<String> cookiesEncoded = new ArrayList<String>(); @@ -4561,7 +4533,7 @@ public class cgBase { Log.e(cgSettings.tag, "cgeoBase.requestJSON: " + e.toString()); } - if (buffer != null && buffer.length() > 0) { + if (StringUtils.isNotBlank(buffer)) { break; } @@ -4680,13 +4652,13 @@ public class cgBase { // get cache details, they may not yet be complete if (cache != null) { // only reload the cache, if it was already stored or has not all details (by checking the description) - if (cache.reason > 0 || cache.description == null || cache.description.length() == 0) { + if (cache.reason > 0 || StringUtils.isBlank(cache.description)) { final HashMap<String, String> params = new HashMap<String, String>(); params.put("geocode", cache.geocode); final Long searchId = searchByGeocode(params, listId, false); cache = app.getCache(searchId); } - } else if (geocode != null) { + } else if (StringUtils.isNotBlank(geocode)) { final HashMap<String, String> params = new HashMap<String, String>(); params.put("geocode", geocode); final Long searchId = searchByGeocode(params, listId, false); @@ -4704,12 +4676,12 @@ public class cgBase { final cgHtmlImg imgGetter = new cgHtmlImg(activity, cache.geocode, false, listId, true); // store images from description - if (cache.description != null) { + if (StringUtils.isNotBlank(cache.description)) { Html.fromHtml(cache.description, imgGetter, null); } // store spoilers - if (cache.spoilers != null && cache.spoilers.isEmpty() == false) { + if (CollectionUtils.isNotEmpty(cache.spoilers)) { for (cgImage oneSpoiler : cache.spoilers) { imgGetter.getDrawable(oneSpoiler.url); } @@ -4718,7 +4690,7 @@ public class cgBase { // store images from logs if (settings.storelogimages) { for (cgLog log : cache.logs) { - if (log.logImages != null && log.logImages.isEmpty() == false) { + if (CollectionUtils.isNotEmpty(log.logImages)) { for (cgImage oneLogImg : log.logImages) { imgGetter.getDrawable(oneLogImg.url); } @@ -4949,7 +4921,7 @@ public class cgBase { String iconTxt = null; if (cache) { - if (type != null && type.length() > 0) { + if (StringUtils.isNotBlank(type)) { if (own) { iconTxt = type + "-own"; } else if (found) { @@ -4969,7 +4941,7 @@ public class cgBase { icon = gcIcons.get("traditional"); } } else { - if (type != null && type.length() > 0) { + if (StringUtils.isNotBlank(type)) { iconTxt = type; } else { iconTxt = "waypoint"; @@ -5062,6 +5034,7 @@ public class cgBase { gcIcons.put("mystery-disabled", R.drawable.marker_cache_mystery_disabled); gcIcons.put("gchq-disabled", R.drawable.marker_cache_gchq_disabled); } + } public static boolean runNavigation(Activity activity, Resources res, cgSettings settings, Double latitude, Double longitude) { @@ -5114,7 +5087,7 @@ public class cgBase { final String data = response.getData(); String usertoken = null; - if (data != null && data.length() > 0) { + if (StringUtils.isNotBlank(data)) { final Pattern pattern = Pattern.compile("var userToken[^=]*=[^']*'([^']+)';", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); final Matcher matcher = pattern.matcher(data); @@ -5125,7 +5098,7 @@ public class cgBase { } } - if (noTokenHandler != null && (usertoken == null || usertoken.length() == 0)) { + if (noTokenHandler != null && StringUtils.isBlank(usertoken)) { noTokenHandler.sendEmptyMessage(0); } @@ -5142,7 +5115,7 @@ public class cgBase { final String data = requestJSON(host, path, params); - if (data == null || data.length() == 0) { + if (StringUtils.isBlank(data)) { return elv; } diff --git a/src/cgeo/geocaching/cgCache.java b/src/cgeo/geocaching/cgCache.java index 5ffa991..bf3a0c2 100644 --- a/src/cgeo/geocaching/cgCache.java +++ b/src/cgeo/geocaching/cgCache.java @@ -7,6 +7,8 @@ import java.util.HashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.lang3.StringUtils; + import android.app.Activity; import android.content.Intent; import android.content.res.Resources; @@ -122,37 +124,37 @@ public class cgCache implements ICache { if (reason == null || reason == 0) { reason = oldCache.reason; } - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { geocode = oldCache.geocode; } - if (cacheid == null || cacheid.length() == 0) { + if (StringUtils.isBlank(cacheid)) { cacheid = oldCache.cacheid; } - if (guid == null || guid.length() == 0) { + if (StringUtils.isBlank(guid)) { guid = oldCache.guid; } - if (type == null || type.length() == 0) { + if (StringUtils.isBlank(type)) { type = oldCache.type; } - if (name == null || name.length() == 0) { + if (StringUtils.isBlank(name)) { name = oldCache.name; } - if (nameSp == null || nameSp.length() == 0) { + if (StringUtils.isBlank(nameSp)) { nameSp = oldCache.nameSp; } - if (owner == null || owner.length() == 0) { + if (StringUtils.isBlank(owner)) { owner = oldCache.owner; } - if (ownerReal == null || ownerReal.length() == 0) { + if (StringUtils.isBlank(ownerReal)) { ownerReal = oldCache.ownerReal; } if (hidden == null) { hidden = oldCache.hidden; } - if (hint == null || hint.length() == 0) { + if (StringUtils.isBlank(hint)) { hint = oldCache.hint; } - if (size == null || size.length() == 0) { + if (StringUtils.isBlank(size)) { size = oldCache.size; } if (difficulty == null || difficulty == 0) { @@ -167,16 +169,16 @@ public class cgCache implements ICache { if (distance == null) { distance = oldCache.distance; } - if (latlon == null || latlon.length() == 0) { + if (StringUtils.isBlank(latlon)) { latlon = oldCache.latlon; } - if (latitudeString == null || latitudeString.length() == 0) { + if (StringUtils.isBlank(latitudeString)) { latitudeString = oldCache.latitudeString; } - if (longitudeString == null || longitudeString.length() == 0) { + if (StringUtils.isBlank(longitudeString)) { longitudeString = oldCache.longitudeString; } - if (location == null || location.length() == 0) { + if (StringUtils.isBlank(location)) { location = oldCache.location; } if (latitude == null) { @@ -188,13 +190,13 @@ public class cgCache implements ICache { if (elevation == null) { elevation = oldCache.elevation; } - if (personalNote == null || personalNote.length() == 0) { + if (StringUtils.isNotBlank(personalNote)) { personalNote = oldCache.personalNote; } - if (shortdesc == null || shortdesc.length() == 0) { + if (StringUtils.isBlank(shortdesc)) { shortdesc = oldCache.shortdesc; } - if (description == null || description.length() == 0) { + if (StringUtils.isBlank(description)) { description = oldCache.description; } if (favouriteCnt == null) { @@ -266,7 +268,7 @@ public class cgCache implements ICache { */ boolean isGuidContainedInPage(final String page) { // check if the guid of the cache is anywhere in the page - if (guid == null || guid.length() == 0) { + if (StringUtils.isBlank(guid)) { return false; } Pattern patternOk = Pattern.compile(guid, Pattern.CASE_INSENSITIVE); @@ -285,7 +287,7 @@ public class cgCache implements ICache { } public boolean logVisit(IAbstractActivity fromActivity) { - if (cacheid == null || cacheid.length() == 0) { + if (StringUtils.isBlank(cacheid)) { fromActivity.showToast(((Activity)fromActivity).getResources().getString(R.string.err_cannot_log_visit)); return true; } @@ -301,9 +303,8 @@ public class cgCache implements ICache { public boolean logOffline(final IAbstractActivity fromActivity, final int logType, final cgSettings settings, final cgBase base) { String log = ""; - if (settings.getSignature() != null - && settings.signatureAutoinsert - && settings.getSignature().length() > 0) { + if (StringUtils.isNotBlank(settings.getSignature()) + && settings.signatureAutoinsert) { log = LogTemplateProvider.applyTemplates(settings.getSignature(), base); } logOffline(fromActivity, log, Calendar.getInstance(), logType); diff --git a/src/cgeo/geocaching/cgCacheListAdapter.java b/src/cgeo/geocaching/cgCacheListAdapter.java index 8ef1e8f..7070386 100644 --- a/src/cgeo/geocaching/cgCacheListAdapter.java +++ b/src/cgeo/geocaching/cgCacheListAdapter.java @@ -6,6 +6,8 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; +import org.apache.commons.lang3.StringUtils; + import android.app.Activity; import android.content.Intent; import android.content.res.Resources; @@ -35,6 +37,7 @@ import cgeo.geocaching.filter.cgFilter; import cgeo.geocaching.sorting.CacheComparator; import cgeo.geocaching.sorting.DistanceComparator; import cgeo.geocaching.sorting.VisitComparator; +import cgeo.geocaching.utils.CollectionUtils; public class cgCacheListAdapter extends ArrayAdapter<cgCache> { @@ -286,13 +289,13 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { lastSort = System.currentTimeMillis(); } - if (distances != null && distances.size() > 0) { + if (CollectionUtils.isNotEmpty(distances)) { for (cgDistanceView distance : distances) { distance.update(latitudeIn, longitudeIn); } } - if (compasses != null && compasses.size() > 0) { + if (CollectionUtils.isNotEmpty(compasses)) { for (cgCompassMini compass : compasses) { compass.updateCoords(latitudeIn, longitudeIn); } @@ -306,7 +309,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { azimuth = azimuthIn; - if (compasses != null && compasses.size() > 0) { + if (CollectionUtils.isNotEmpty(compasses)) { for (cgCompassMini compass : compasses) { compass.updateAzimuth(azimuth); } @@ -581,10 +584,10 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { cacheInfo.append("; "); cacheInfo.append(base.formatDate(cache.visitedDate)); } else { - if (cache.geocode != null && cache.geocode.length() > 0) { + if (StringUtils.isNotBlank(cache.geocode)) { cacheInfo.append(cache.geocode); } - if (cache.size != null && cache.size.length() > 0) { + if (StringUtils.isNotBlank(cache.size)) { if (cacheInfo.length() > 0) { cacheInfo.append(" | "); } diff --git a/src/cgeo/geocaching/cgData.java b/src/cgeo/geocaching/cgData.java index 64308a2..80516a5 100644 --- a/src/cgeo/geocaching/cgData.java +++ b/src/cgeo/geocaching/cgData.java @@ -17,6 +17,8 @@ import java.util.Locale; import java.util.Map.Entry; import java.util.Set; +import org.apache.commons.lang3.StringUtils; + import android.content.ContentValues; import android.content.Context; import android.content.res.Resources; @@ -27,6 +29,7 @@ import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteStatement; import android.os.Environment; import android.util.Log; +import cgeo.geocaching.utils.CollectionUtils; public class cgData { @@ -881,7 +884,7 @@ public class cgData { int dataDetailed = 0; try { - if (geocode != null && geocode.length() > 0) { + if (StringUtils.isNotBlank(geocode)) { cursor = databaseRO.query( dbTableCaches, new String[]{"_id", "detailed", "detailedupdate", "updated"}, @@ -891,7 +894,7 @@ public class cgData { null, null, "1"); - } else if (guid != null && guid.length() > 0) { + } else if (StringUtils.isNotBlank(guid)) { cursor = databaseRO.query( dbTableCaches, new String[]{"_id", "detailed", "detailedupdate", "updated"}, @@ -959,7 +962,7 @@ public class cgData { long reason = 0; try { - if (geocode != null && geocode.length() > 0) { + if (StringUtils.isNotBlank(geocode)) { cursor = databaseRO.query( dbTableCaches, new String[]{"reason"}, @@ -969,7 +972,7 @@ public class cgData { null, null, "1"); - } else if (guid != null && guid.length() > 0) { + } else if (StringUtils.isNotBlank(guid)) { cursor = databaseRO.query( dbTableCaches, new String[]{"reason"}, @@ -1014,7 +1017,7 @@ public class cgData { int rel = 0; try { - if (geocode != null && geocode.length() > 0) { + if (StringUtils.isNotBlank(geocode)) { cursor = databaseRO.query( dbTableCaches, new String[]{"reliable_latlon"}, @@ -1024,7 +1027,7 @@ public class cgData { null, null, "1"); - } else if (guid != null && guid.length() > 0) { + } else if (StringUtils.isNotBlank(guid)) { cursor = databaseRO.query( dbTableCaches, new String[]{"reliable_latlon"}, @@ -1063,7 +1066,7 @@ public class cgData { } public String getGeocodeForGuid(String guid) { - if (guid == null || guid.length() == 0) { + if (StringUtils.isBlank(guid)) { return null; } @@ -1105,7 +1108,7 @@ public class cgData { } public String getCacheidForGeocode(String geocode) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return null; } @@ -1287,7 +1290,7 @@ public class cgData { public boolean saveAttributes(String geocode, ArrayList<String> attributes) { init(); - if (geocode == null || geocode.length() == 0 || attributes == null) { + if (StringUtils.isBlank(geocode) || attributes == null) { return false; } @@ -1354,7 +1357,7 @@ public class cgData { public boolean saveWaypoints(String geocode, ArrayList<cgWaypoint> waypoints, boolean drop) { init(); - if (geocode == null || geocode.length() == 0 || waypoints == null) { + if (StringUtils.isBlank(geocode) || waypoints == null) { return false; } @@ -1402,7 +1405,7 @@ public class cgData { public boolean saveOwnWaypoint(int id, String geocode, cgWaypoint waypoint) { init(); - if (((geocode == null || geocode.length() == 0) && id <= 0) || waypoint == null) { + if ((StringUtils.isBlank(geocode) && id <= 0) || waypoint == null) { return false; } @@ -1461,7 +1464,7 @@ public class cgData { public boolean saveSpoilers(String geocode, ArrayList<cgImage> spoilers) { init(); - if (geocode == null || geocode.length() == 0 || spoilers == null) { + if (StringUtils.isBlank(geocode) || spoilers == null) { return false; } @@ -1497,7 +1500,7 @@ public class cgData { public boolean saveLogs(String geocode, ArrayList<cgLog> logs, boolean drop) { init(); - if (geocode == null || geocode.length() == 0 || logs == null) { + if (StringUtils.isBlank(geocode) || logs == null) { return false; } @@ -1523,7 +1526,7 @@ public class cgData { long log_id = helper.execute(); - if ((log.logImages != null) && (log.logImages.size() > 0)) { + if (CollectionUtils.isNotEmpty(log.logImages)) { ContentValues values = new ContentValues(); for (cgImage img : log.logImages) { values.clear(); @@ -1551,7 +1554,7 @@ public class cgData { public boolean saveLogCount(String geocode, HashMap<Integer, Integer> logCounts, boolean drop) { init(); - if (geocode == null || geocode.length() == 0 || logCounts == null || logCounts.isEmpty()) { + if (StringUtils.isBlank(geocode) || CollectionUtils.isEmpty(logCounts)) { return false; } @@ -1698,13 +1701,13 @@ public class cgData { Object[] geocodes = new Object[1]; Object[] guids = new Object[1]; - if (geocode != null && geocode.length() > 0) { + if (StringUtils.isNotBlank(geocode)) { geocodes[0] = geocode; } else { geocodes = null; } - if (guid != null && guid.length() > 0) { + if (StringUtils.isNotBlank(guid)) { guids[0] = guid; } else { guids = null; @@ -1986,7 +1989,7 @@ public class cgData { } public ArrayList<String> loadAttributes(String geocode) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return null; } @@ -2052,7 +2055,7 @@ public class cgData { } public ArrayList<cgWaypoint> loadWaypoints(String geocode) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return null; } @@ -2117,7 +2120,7 @@ public class cgData { } public ArrayList<cgImage> loadSpoilers(String geocode) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return null; } @@ -2212,7 +2215,7 @@ public class cgData { } public ArrayList<cgLog> loadLogs(String geocode) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return null; } @@ -2255,7 +2258,7 @@ public class cgData { } public HashMap<Integer, Integer> loadLogCounts(String geocode) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return null; } @@ -2325,7 +2328,7 @@ public class cgData { } public ArrayList<cgTrackable> loadInventory(String geocode) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return null; } @@ -2361,7 +2364,7 @@ public class cgData { } public cgTrackable loadTrackable(String geocode) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return null; } @@ -2710,7 +2713,7 @@ public class cgData { } public void markStored(String geocode, int listId) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return; } @@ -2726,7 +2729,7 @@ public class cgData { } public boolean markDropped(String geocode) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return false; } @@ -2748,7 +2751,7 @@ public class cgData { } public boolean markFound(String geocode) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return false; } @@ -2879,7 +2882,7 @@ public class cgData { cursor.close(); } - if (geocodes.size() > 0) { + if (CollectionUtils.isNotEmpty(geocodes)) { String geocodeList = cgBase.implode(", ", geocodes.toArray()); databaseRW.execSQL("delete from " + dbTableCaches + " where geocode in (" + geocodeList + ")"); databaseRW.execSQL("delete from " + dbTableAttributes + " where geocode in (" + geocodeList + ")"); @@ -2898,10 +2901,10 @@ public class cgData { } public boolean saveLogOffline(String geocode, Date date, int type, String log) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return false; } - if (type <= 0 && (log == null || log.length() == 0)) { + if (type <= 0 && StringUtils.isBlank(log)) { return false; } @@ -2936,7 +2939,7 @@ public class cgData { } public cgLog loadLogOffline(String geocode) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return null; } @@ -2972,7 +2975,7 @@ public class cgData { } public void clearLogOffline(String geocode) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return; } @@ -2982,7 +2985,7 @@ public class cgData { } public boolean hasLogOffline(String geocode) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return false; } @@ -3001,7 +3004,7 @@ public class cgData { } public void saveVisitDate(String geocode) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return; } @@ -3016,7 +3019,7 @@ public class cgData { } public void clearVisitDate(String geocode) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return; } @@ -3123,7 +3126,7 @@ public class cgData { public int createList(String name) { int id = -1; - if (name == null || name.length() == 0) { + if (StringUtils.isBlank(name)) { return id; } @@ -3177,7 +3180,7 @@ public class cgData { } public void moveToList(String geocode, int listId) { - if (geocode == null || geocode.length() == 0 || listId <= 0) { + if (StringUtils.isBlank(geocode) || listId <= 0) { return; } @@ -3203,7 +3206,7 @@ public class cgData { public boolean removeSearchedDestination(cgDestination destination) { boolean success = true; - if(destination == null){ + if (destination == null){ success = false; } else{ init(); diff --git a/src/cgeo/geocaching/cgDirectionImg.java b/src/cgeo/geocaching/cgDirectionImg.java index 573cf47..1f513d3 100644 --- a/src/cgeo/geocaching/cgDirectionImg.java +++ b/src/cgeo/geocaching/cgDirectionImg.java @@ -5,6 +5,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -20,11 +21,11 @@ public class cgDirectionImg { String dirName; String fileName; - if (geocode == null || geocode.length() == 0 || code == null || code.length() == 0) { + if (StringUtils.isBlank(geocode) || StringUtils.isBlank(code)) { return; } - if (geocode != null && geocode.length() > 0) { + if (StringUtils.isNotBlank(geocode)) { dirName = cgSettings.getStorage() + geocode + "/"; fileName = cgSettings.getStorage() + geocode + "/direction.png"; } else { diff --git a/src/cgeo/geocaching/cgGeo.java b/src/cgeo/geocaching/cgGeo.java index 8a191dd..52f92a1 100644 --- a/src/cgeo/geocaching/cgGeo.java +++ b/src/cgeo/geocaching/cgGeo.java @@ -4,6 +4,8 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Locale; +import org.apache.commons.lang3.StringUtils; + import android.content.Context; import android.content.SharedPreferences; import android.location.GpsSatellite; @@ -407,7 +409,7 @@ public class cgGeo { } final String res = base.request(false, host, path, method, params, false, false, false).getData(); - if (res != null && res.length() > 0) { + if (StringUtils.isNotBlank(res)) { lastGo4cacheLat = latitudeNow; lastGo4cacheLon = longitudeNow; } diff --git a/src/cgeo/geocaching/cgHtmlImg.java b/src/cgeo/geocaching/cgHtmlImg.java index e6e5a2e..cfb7cab 100644 --- a/src/cgeo/geocaching/cgHtmlImg.java +++ b/src/cgeo/geocaching/cgHtmlImg.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.Date; +import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -67,7 +68,7 @@ public class cgHtmlImg implements Html.ImageGetter { String fileName = null; String fileNameSec = null; - if (url == null || url.length() == 0) { + if (StringUtils.isBlank(url)) { return null; } @@ -82,7 +83,7 @@ public class cgHtmlImg implements Html.ImageGetter { urlExt = ""; } - if (geocode != null && geocode.length() > 0) { + if (StringUtils.isNotBlank(geocode)) { dirName = cgSettings.getStorage() + geocode + "/"; fileName = cgSettings.getStorage() + geocode + "/" + cgBase.md5(url) + urlExt; fileNameSec = cgSettings.getStorageSec() + geocode + "/" + cgBase.md5(url) + urlExt; diff --git a/src/cgeo/geocaching/cgSettings.java b/src/cgeo/geocaching/cgSettings.java index 57cdf51..404248c 100644 --- a/src/cgeo/geocaching/cgSettings.java +++ b/src/cgeo/geocaching/cgSettings.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.Locale; import java.util.Map; +import org.apache.commons.lang3.StringUtils; import org.mapsforge.android.maps.MapDatabase; import android.content.Context; @@ -16,6 +17,7 @@ import android.util.Log; import cgeo.geocaching.googlemaps.googleMapFactory; import cgeo.geocaching.mapinterfaces.MapFactory; import cgeo.geocaching.mapsforge.mfMapFactory; +import cgeo.geocaching.utils.CollectionUtils; /** * General c:geo preferences/settings set by the user @@ -272,7 +274,7 @@ public class cgSettings { final String preUsername = prefs.getString(KEY_USERNAME, null); final String prePassword = prefs.getString(KEY_PASSWORD, null); - if (preUsername == null || prePassword == null || preUsername.length() == 0 || prePassword.length() == 0) { + if (StringUtils.isBlank(preUsername) || StringUtils.isBlank(prePassword)) { return false; } else { return true; @@ -329,7 +331,7 @@ public class cgSettings { @Override public void edit(Editor edit) { - if (username == null || username.length() == 0 || password == null || password.length() == 0) { + if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) { // erase username and password edit.remove(KEY_USERNAME); edit.remove(KEY_PASSWORD); @@ -346,7 +348,7 @@ public class cgSettings { final String preUsername = prefs.getString(KEY_USERNAME, null); final String prePassword = prefs.getString(KEY_GCVOTE_PASSWORD, null); - if (preUsername == null || prePassword == null || preUsername.length() == 0 || prePassword.length() == 0) { + if (StringUtils.isBlank(preUsername) || StringUtils.isBlank(prePassword)) { return false; } else { return true; @@ -358,7 +360,7 @@ public class cgSettings { @Override public void edit(Editor edit) { - if (password == null || password.length() == 0) { + if (StringUtils.isBlank(password)) { // erase password edit.remove(KEY_GCVOTE_PASSWORD); } else { @@ -397,7 +399,7 @@ public class cgSettings { @Override public void edit(Editor edit) { - if (signature == null || signature.length() == 0) { + if (StringUtils.isBlank(signature)) { // erase signature edit.remove(KEY_SIGNATURE); } else { @@ -431,7 +433,7 @@ public class cgSettings { // delete cookies Map<String, ?> prefsValues = prefs.getAll(); - if (prefsValues != null && prefsValues.size() > 0) { + if (CollectionUtils.isNotEmpty(prefsValues)) { Log.i(cgSettings.tag, "Removing cookies"); for (String key : prefsValues.keySet()) { diff --git a/src/cgeo/geocaching/cgWaypoint.java b/src/cgeo/geocaching/cgWaypoint.java index 7746c2c..6b437f6 100644 --- a/src/cgeo/geocaching/cgWaypoint.java +++ b/src/cgeo/geocaching/cgWaypoint.java @@ -2,6 +2,8 @@ package cgeo.geocaching; import java.util.ArrayList; +import org.apache.commons.lang3.StringUtils; + import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.widget.TextView; @@ -32,22 +34,22 @@ public class cgWaypoint { } public void merge(final cgWaypoint old) { - if (prefix == null || prefix.length() == 0) { + if (StringUtils.isBlank(prefix)) { prefix = old.prefix; } - if (lookup == null || lookup.length() == 0) { + if (StringUtils.isBlank(lookup)) { lookup = old.lookup; } - if (name == null || name.length() == 0) { + if (StringUtils.isBlank(name)) { name = old.name; } - if (latlon == null || latlon.length() == 0) { + if (StringUtils.isBlank(latlon)) { latlon = old.latlon; } - if (latitudeString == null || latitudeString.length() == 0) { + if (StringUtils.isBlank(latitudeString)) { latitudeString = old.latitudeString; } - if (longitudeString == null || longitudeString.length() == 0) { + if (StringUtils.isBlank(longitudeString)) { longitudeString = old.longitudeString; } if (latitude == null) { @@ -56,7 +58,7 @@ public class cgWaypoint { if (longitude == null) { longitude = old.longitude; } - if (note == null || note.length() == 0) { + if (StringUtils.isBlank(note)) { note = old.note; } if (note != null && old.note != null) { diff --git a/src/cgeo/geocaching/cgeo.java b/src/cgeo/geocaching/cgeo.java index 6384fb1..d64d6c8 100644 --- a/src/cgeo/geocaching/cgeo.java +++ b/src/cgeo/geocaching/cgeo.java @@ -7,6 +7,8 @@ import java.util.List; import java.util.Locale; import java.util.Map.Entry; +import org.apache.commons.lang3.StringUtils; + import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -28,6 +30,7 @@ import android.widget.RelativeLayout; import android.widget.TextView; import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.activity.ActivityMixin; +import cgeo.geocaching.utils.CollectionUtils; public class cgeo extends AbstractActivity { @@ -83,7 +86,7 @@ public class cgeo extends AbstractActivity { @Override public void handleMessage(Message msg) { try { - if (addresses != null && addresses.isEmpty() == false) { + if (CollectionUtils.isNotEmpty(addresses)) { final Address address = addresses.get(0); final StringBuilder addText = new StringBuilder(); @@ -286,7 +289,7 @@ public class cgeo extends AbstractActivity { if (requestCode == SCAN_REQUEST_CODE) { if (resultCode == RESULT_OK) { String scan = intent.getStringExtra("SCAN_RESULT"); - if (scan == null || scan.length() == 0) { + if (StringUtils.isBlank(scan)) { return; } String host = "http://coord.info/"; diff --git a/src/cgeo/geocaching/cgeoadvsearch.java b/src/cgeo/geocaching/cgeoadvsearch.java index 1849faa..c7b98f5 100644 --- a/src/cgeo/geocaching/cgeoadvsearch.java +++ b/src/cgeo/geocaching/cgeoadvsearch.java @@ -4,6 +4,8 @@ import java.util.HashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.lang3.StringUtils; + import android.app.SearchManager; import android.content.Intent; import android.content.res.Configuration; @@ -245,7 +247,7 @@ public class cgeoadvsearch extends AbstractActivity { final String latText = latView.getText().toString(); final String lonText = lonView.getText().toString(); - if (latText == null || latText.length() == 0 || lonText == null || lonText.length() == 0) { + if (StringUtils.isEmpty(latText) || StringUtils.isEmpty(lonText)) { latView.setText(cgBase.formatLatitude(geo.latitudeNow, true)); lonView.setText(cgBase.formatLongitude(geo.longitudeNow, true)); } else { @@ -295,7 +297,7 @@ public class cgeoadvsearch extends AbstractActivity { // find caches by coordinates String keyText = ((EditText) findViewById(R.id.keyword)).getText().toString(); - if (keyText == null || keyText.length() == 0) { + if (StringUtils.isBlank(keyText)) { helpDialog(res.getString(R.string.warn_search_help_title), res.getString(R.string.warn_search_help_keyword)); return; } @@ -330,7 +332,7 @@ public class cgeoadvsearch extends AbstractActivity { private void findByAddressFn() { final String addText = ((EditText) findViewById(R.id.address)).getText().toString(); - if (addText == null || addText.length() == 0) { + if (StringUtils.isBlank(addText)) { helpDialog(res.getString(R.string.warn_search_help_title), res.getString(R.string.warn_search_help_address)); return; } @@ -363,7 +365,7 @@ public class cgeoadvsearch extends AbstractActivity { public void findByUsernameFn() { final String usernameText = ((EditText) findViewById(R.id.username)).getText().toString(); - if (usernameText == null || usernameText.length() == 0) { + if (StringUtils.isBlank(usernameText)) { helpDialog(res.getString(R.string.warn_search_help_title), res.getString(R.string.warn_search_help_user)); return; } @@ -398,7 +400,7 @@ public class cgeoadvsearch extends AbstractActivity { private void findByOwnerFn() { final String usernameText = ((EditText) findViewById(R.id.owner)).getText().toString(); - if (usernameText == null || usernameText.length() == 0) { + if (StringUtils.isBlank(usernameText)) { helpDialog(res.getString(R.string.warn_search_help_title), res.getString(R.string.warn_search_help_user)); return; } @@ -433,7 +435,7 @@ public class cgeoadvsearch extends AbstractActivity { private void findByGeocodeFn() { final String geocodeText = ((EditText) findViewById(R.id.geocode)).getText().toString(); - if (geocodeText == null || geocodeText.length() == 0 || geocodeText.equalsIgnoreCase("GC")) { + if (StringUtils.isBlank(geocodeText) || geocodeText.equalsIgnoreCase("GC")) { helpDialog(res.getString(R.string.warn_search_help_title), res.getString(R.string.warn_search_help_gccode)); return; } @@ -464,7 +466,7 @@ public class cgeoadvsearch extends AbstractActivity { private void findTrackableFn() { final String trackableText = ((EditText) findViewById(R.id.trackable)).getText().toString(); - if (trackableText == null || trackableText.length() == 0 || trackableText.equalsIgnoreCase("TB")) { + if (StringUtils.isBlank(trackableText)|| trackableText.equalsIgnoreCase("TB")) { helpDialog(res.getString(R.string.warn_search_help_title), res.getString(R.string.warn_search_help_tb)); return; } diff --git a/src/cgeo/geocaching/cgeoapplication.java b/src/cgeo/geocaching/cgeoapplication.java index fece371..6095271 100644 --- a/src/cgeo/geocaching/cgeoapplication.java +++ b/src/cgeo/geocaching/cgeoapplication.java @@ -6,9 +6,13 @@ import java.util.Date; import java.util.HashMap; import java.util.List; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; + import android.app.Application; import android.content.Context; import android.util.Log; +import cgeo.geocaching.utils.CollectionUtils; public class cgeoapplication extends Application { @@ -265,7 +269,7 @@ public class cgeoapplication extends Application { } public boolean setViewstates(Long searchId, String[] viewstates) { - if (cgBase.isEmpty(viewstates)) { + if (ArrayUtils.isEmpty(viewstates)) { return false; } if (searchId == null || searches.containsKey(searchId) == false) { @@ -316,7 +320,7 @@ public class cgeoapplication extends Application { } public cgCache getCacheByGeocode(String geocode, boolean loadA, boolean loadW, boolean loadS, boolean loadL, boolean loadI, boolean loadO) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return null; } @@ -338,7 +342,7 @@ public class cgeoapplication extends Application { } public cgTrackable getTrackableByGeocode(String geocode) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return null; } @@ -655,7 +659,7 @@ public class cgeoapplication extends Application { } public void addGeocode(Long searchId, String geocode) { - if (this.searches.containsKey(searchId) == false || geocode == null || geocode.length() == 0) { + if (this.searches.containsKey(searchId) == false || StringUtils.isBlank(geocode)) { return; } @@ -673,7 +677,7 @@ public class cgeoapplication extends Application { } public Long addSearch(final cgSearch search, final ArrayList<cgCache> cacheList, final boolean newItem, final int reason) { - if (cacheList == null || cacheList.isEmpty()) { + if (CollectionUtils.isEmpty(cacheList)) { return null; } @@ -770,7 +774,7 @@ public class cgeoapplication extends Application { } public boolean addLog(String geocode, cgLog log) { - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { return false; } if (log == null) { diff --git a/src/cgeo/geocaching/cgeoauth.java b/src/cgeo/geocaching/cgeoauth.java index 1c2e8bb..6dc6aea 100644 --- a/src/cgeo/geocaching/cgeoauth.java +++ b/src/cgeo/geocaching/cgeoauth.java @@ -14,6 +14,8 @@ import java.util.regex.Pattern; import javax.net.ssl.HttpsURLConnection; +import org.apache.commons.lang3.StringUtils; + import android.app.ProgressDialog; import android.content.Intent; import android.content.SharedPreferences; @@ -119,7 +121,7 @@ public class cgeoauth extends AbstractActivity { startButton.setEnabled(true); startButton.setOnClickListener(new startListener()); - if (OAtoken == null || OAtoken.length() == 0 || OAtokenSecret == null || OAtokenSecret.length() == 0) { + if (StringUtils.isNotBlank(OAtoken) && StringUtils.isNotBlank(OAtokenSecret)) { // start authorization process startButton.setText(res.getString(R.string.auth_start)); } else { @@ -185,7 +187,7 @@ public class cgeoauth extends AbstractActivity { final String line = sb.toString(); - if (line != null && line.length() > 0) { + if (StringUtils.isNotBlank(line)) { final Matcher paramsMatcher1 = paramsPattern1.matcher(line); if (paramsMatcher1.find() && paramsMatcher1.groupCount() > 0) { OAtoken = paramsMatcher1.group(1); @@ -195,7 +197,7 @@ public class cgeoauth extends AbstractActivity { OAtokenSecret = paramsMatcher2.group(1); } - if (OAtoken != null && OAtoken.length() > 0 && OAtokenSecret != null && OAtokenSecret.length() > 0) { + if (StringUtils.isNotBlank(OAtoken) && StringUtils.isNotBlank(OAtokenSecret)) { final SharedPreferences.Editor prefsEdit = getSharedPreferences(cgSettings.preferences, 0).edit(); prefsEdit.putString("temp-token-public", OAtoken); prefsEdit.putString("temp-token-secret", OAtokenSecret); @@ -303,7 +305,7 @@ public class cgeoauth extends AbstractActivity { OAtokenSecret = paramsMatcher2.group(1); } - if (OAtoken.length() == 0 || OAtokenSecret.length() == 0) { + if (StringUtils.isBlank(OAtoken) && StringUtils.isBlank(OAtokenSecret)) { OAtoken = ""; OAtokenSecret = ""; diff --git a/src/cgeo/geocaching/cgeocaches.java b/src/cgeo/geocaching/cgeocaches.java index 9953882..b2b1870 100644 --- a/src/cgeo/geocaching/cgeocaches.java +++ b/src/cgeo/geocaching/cgeocaches.java @@ -14,6 +14,8 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; +import org.apache.commons.lang3.StringUtils; + import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.Context; @@ -62,6 +64,7 @@ import cgeo.geocaching.sorting.SizeComparator; import cgeo.geocaching.sorting.StateComparator; import cgeo.geocaching.sorting.TerrainComparator; import cgeo.geocaching.sorting.VoteComparator; +import cgeo.geocaching.utils.CollectionUtils; public class cgeocaches extends AbstractListActivity { @@ -174,7 +177,7 @@ public class cgeocaches extends AbstractListActivity { cacheList.clear(); final ArrayList<cgCache> cacheListTmp = app.getCaches(searchId); - if (cacheListTmp != null && cacheListTmp.isEmpty() == false) { + if (CollectionUtils.isNotEmpty(cacheListTmp)) { cacheList.addAll(cacheListTmp); cacheListTmp.clear(); @@ -225,7 +228,7 @@ public class cgeocaches extends AbstractListActivity { AlertDialog alert = dialog.create(); alert.show(); - } else if (app != null && app.getError(searchId) != null && app.getError(searchId).length() > 0) { + } else if (app != null && StringUtils.isNotBlank(app.getError(searchId))) { showToast(res.getString(R.string.err_download_fail) + app.getError(searchId) + "."); hideLoading(); @@ -272,7 +275,7 @@ public class cgeocaches extends AbstractListActivity { cacheList.clear(); final ArrayList<cgCache> cacheListTmp = app.getCaches(searchId); - if (cacheListTmp != null && cacheListTmp.isEmpty() == false) { + if (CollectionUtils.isNotEmpty(cacheListTmp)) { cacheList.addAll(cacheListTmp); cacheListTmp.clear(); Collections.sort((List<cgCache>)cacheList, gcComparator); @@ -302,7 +305,7 @@ public class cgeocaches extends AbstractListActivity { } } - if (app.getError(searchId) != null && app.getError(searchId).length() > 0) { + if (StringUtils.isNotBlank(app.getError(searchId))) { showToast(res.getString(R.string.err_download_fail) + app.getError(searchId) + "."); listFooter.setOnClickListener(new moreCachesListener()); @@ -361,7 +364,7 @@ public class cgeocaches extends AbstractListActivity { } else { if (cacheList != null && searchId != null) { final ArrayList<cgCache> cacheListTmp = app.getCaches(searchId); - if (cacheListTmp != null && cacheListTmp.isEmpty() == false) { + if (CollectionUtils.isNotEmpty(cacheListTmp)) { cacheList.clear(); cacheList.addAll(cacheListTmp); cacheListTmp.clear(); @@ -422,7 +425,7 @@ public class cgeocaches extends AbstractListActivity { cacheList.clear(); final ArrayList<cgCache> cacheListTmp = app.getCaches(searchId); - if (cacheListTmp != null && cacheListTmp.isEmpty() == false) { + if (CollectionUtils.isNotEmpty(cacheListTmp)) { cacheList.addAll(cacheListTmp); cacheListTmp.clear(); @@ -450,7 +453,7 @@ public class cgeocaches extends AbstractListActivity { cacheList.clear(); final ArrayList<cgCache> cacheListTmp = app.getCaches(searchId); - if (cacheListTmp != null && cacheListTmp.isEmpty() == false) { + if (CollectionUtils.isNotEmpty(cacheListTmp)) { cacheList.addAll(cacheListTmp); cacheListTmp.clear(); @@ -617,7 +620,7 @@ public class cgeocaches extends AbstractListActivity { thread.start(); } else if (type.equals("address")) { action = "planning"; - if (address != null && address.length() > 0) { + if (StringUtils.isNotBlank(address)) { title = address; setTitle(title); showProgress(true); @@ -1088,7 +1091,7 @@ public class cgeocaches extends AbstractListActivity { } final cgCache cache = adapter.getItem(adapterInfo.position); - if (cache.name != null && cache.name.length() > 0) { + if (StringUtils.isNotBlank(cache.name)) { menu.setHeaderTitle(cache.name); } else { menu.setHeaderTitle(cache.geocode); @@ -1364,7 +1367,7 @@ public class cgeocaches extends AbstractListActivity { } if (more == false) { - if (cacheList == null || cacheList.isEmpty()) { + if (CollectionUtils.isEmpty(cacheList)) { listFooterText.setText(res.getString(R.string.caches_no_cache)); } else { listFooterText.setText(res.getString(R.string.caches_more_caches_no)); @@ -1391,7 +1394,7 @@ public class cgeocaches extends AbstractListActivity { setTitle(title); } - if (cacheList != null && cacheList.isEmpty() == false) { + if (CollectionUtils.isNotEmpty(cacheList)) { final Integer count = app.getTotal(searchId); if (count != null && count > 0) { setTitle(title); @@ -1884,7 +1887,7 @@ public class cgeocaches extends AbstractListActivity { username = usernameIn; cachetype = cachetypeIn; - if (username == null || username.length() == 0) { + if (StringUtils.isBlank(username)) { showToast(res.getString(R.string.warn_no_username)); finish(); @@ -1917,7 +1920,7 @@ public class cgeocaches extends AbstractListActivity { username = usernameIn; cachetype = cachetypeIn; - if (username == null || username.length() == 0) { + if (StringUtils.isBlank(username)) { showToast(res.getString(R.string.warn_no_username)); finish(); @@ -2462,7 +2465,7 @@ public class cgeocaches extends AbstractListActivity { value = value.trim(); } - if (value != null && value.length() > 0) { + if (StringUtils.isNotBlank(value)) { int newId = app.createList(value); if (newId >= 10) { @@ -2521,7 +2524,7 @@ public class cgeocaches extends AbstractListActivity { } public void goMap(View view) { - if (searchId == null || searchId == 0 || cacheList == null || cacheList.isEmpty()) { + if (searchId == null || searchId == 0 || CollectionUtils.isEmpty(cacheList)) { showToast(res.getString(R.string.warn_no_cache_coord)); return; @@ -2585,4 +2588,4 @@ public class cgeocaches extends AbstractListActivity { context.startActivity(cachesIntent); } -}
\ No newline at end of file +} diff --git a/src/cgeo/geocaching/cgeocoords.java b/src/cgeo/geocaching/cgeocoords.java index ca6e610..ce62bd8 100644 --- a/src/cgeo/geocaching/cgeocoords.java +++ b/src/cgeo/geocaching/cgeocoords.java @@ -3,6 +3,8 @@ package cgeo.geocaching; import java.util.ArrayList; import java.util.HashMap; +import org.apache.commons.lang3.StringUtils; + import android.app.Dialog; import android.os.Bundle; import android.text.Editable; @@ -274,7 +276,7 @@ public class cgeocoords extends Dialog { public void onClick(View v) { Button e = (Button) v; CharSequence text = e.getText(); - if (text == null || text.length() == 0) { + if (StringUtils.isBlank(text)) { return; } switch (text.charAt(0)) { diff --git a/src/cgeo/geocaching/cgeodetail.java b/src/cgeo/geocaching/cgeodetail.java index 3000ec9..7a7cee0 100644 --- a/src/cgeo/geocaching/cgeodetail.java +++ b/src/cgeo/geocaching/cgeodetail.java @@ -9,6 +9,8 @@ import java.util.HashMap; import java.util.Locale; import java.util.Map.Entry; +import org.apache.commons.lang3.StringUtils; + import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.ContentValues; @@ -54,6 +56,7 @@ import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.apps.cache.GeneralAppsFactory; import cgeo.geocaching.apps.cache.navi.NavigationAppFactory; import cgeo.geocaching.compatibility.Compatibility; +import cgeo.geocaching.utils.CollectionUtils; /** * Activity to display all details of a cache like owner, difficulty, description etc. @@ -335,10 +338,10 @@ public class cgeodetail extends AbstractActivity { geocode = uri.getQueryParameter("wp"); guid = uri.getQueryParameter("guid"); - if (geocode != null && geocode.length() > 0) { + if (StringUtils.isNotBlank(geocode)) { geocode = geocode.toUpperCase(); guid = null; - } else if (guid != null && guid.length() > 0) { + } else if (StringUtils.isNotBlank(guid)) { geocode = null; guid = guid.toLowerCase(); } else { @@ -367,9 +370,9 @@ public class cgeodetail extends AbstractActivity { app.setAction(geocode); try { - if (name != null && name.length() > 0) { + if (StringUtils.isNotBlank(name)) { waitDialog = ProgressDialog.show(this, name, res.getString(R.string.cache_dialog_loading_details), true); - } else if (geocode != null && geocode.length() > 0) { + } else if (StringUtils.isNotBlank(geocode)) { waitDialog = ProgressDialog.show(this, geocode.toUpperCase(), res.getString(R.string.cache_dialog_loading_details), true); } else { waitDialog = ProgressDialog.show(this, res.getString(R.string.cache), res.getString(R.string.cache_dialog_loading_details), true); @@ -442,7 +445,7 @@ public class cgeodetail extends AbstractActivity { if (viewId == R.id.author) { // Author of a log entry contextMenuUser = ((TextView)view).getText().toString(); } else if (viewId == R.id.value) { // The owner of the cache - if (cache.ownerReal != null && cache.ownerReal.length() > 0) { + if (StringUtils.isNotBlank(cache.ownerReal)) { contextMenuUser = cache.ownerReal; } else { contextMenuUser = cache.owner; @@ -498,7 +501,7 @@ public class cgeodetail extends AbstractActivity { } addVisitMenu(menu, cache); - if (cache != null && cache.spoilers != null && cache.spoilers.size() > 0) { + if (cache != null && CollectionUtils.isNotEmpty(cache.spoilers)) { menu.add(1, 5, 0, res.getString(R.string.cache_menu_spoilers)).setIcon(android.R.drawable.ic_menu_gallery); // spoiler images } @@ -575,7 +578,7 @@ public class cgeodetail extends AbstractActivity { } } - if (geocode != null && geocode.length() > 0) { + if (StringUtils.isNotBlank(geocode)) { app.setAction(geocode); } } @@ -594,7 +597,7 @@ public class cgeodetail extends AbstractActivity { if (cache == null) { if (waitDialog != null && waitDialog.isShowing()) waitDialog.dismiss(); - if (geocode != null && geocode.length() > 0) { + if (StringUtils.isNotBlank(geocode)) { showToast(res.getString(R.string.err_detail_cache_find) + " " + geocode + "."); } else { geocode = null; @@ -607,13 +610,11 @@ public class cgeodetail extends AbstractActivity { try { - if (null == geocode && cache.geocode.length() > 0) - { + if (StringUtils.isBlank(geocode)) { geocode = cache.geocode; } - if (null == guid && cache.guid.length() > 0) - { + if (StringUtils.isBlank(guid)) { guid = cache.guid; } @@ -651,7 +652,7 @@ public class cgeodetail extends AbstractActivity { itemName.setText(res.getString(R.string.cache_type)); String size = ""; - if (cache.size != null && cache.size.length() > 0) { + if (StringUtils.isNotBlank(cache.size)) { // don't show "not chosen" for events, that should be the normal case if (!(cache.isEventCache() && cache.size.equals("not chosen"))) { size = " (" + cache.size + ")"; @@ -766,15 +767,15 @@ public class cgeodetail extends AbstractActivity { } // cache author - if ((cache.owner != null && cache.owner.length() > 0) || (cache.ownerReal != null && cache.ownerReal.length() > 0)) { + if (StringUtils.isNotBlank(cache.owner) || StringUtils.isNotBlank(cache.ownerReal)) { itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null); itemName = (TextView) itemLayout.findViewById(R.id.name); itemValue = (TextView) itemLayout.findViewById(R.id.value); itemName.setText(res.getString(R.string.cache_owner)); - if (cache.owner != null && cache.owner.length() > 0) { + if (StringUtils.isNotBlank(cache.owner)) { itemValue.setText(Html.fromHtml(cache.owner), TextView.BufferType.SPANNABLE); - } else if (cache.ownerReal != null && cache.ownerReal.length() > 0) { + } else if (StringUtils.isNotBlank(cache.ownerReal)) { itemValue.setText(Html.fromHtml(cache.ownerReal), TextView.BufferType.SPANNABLE); } itemValue.setOnClickListener(new userActions()); @@ -797,7 +798,7 @@ public class cgeodetail extends AbstractActivity { } // cache location - if (cache.location != null && cache.location.length() > 0) { + if (StringUtils.isNotBlank(cache.location)) { itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null); itemName = (TextView) itemLayout.findViewById(R.id.name); itemValue = (TextView) itemLayout.findViewById(R.id.value); @@ -819,7 +820,7 @@ public class cgeodetail extends AbstractActivity { } // cache attributes - if (cache.attributes != null && cache.attributes.size() > 0) { + if (CollectionUtils.isNotEmpty(cache.attributes)) { final LinearLayout attribBox = (LinearLayout) findViewById( R.id.attributes_innerbox); @@ -865,7 +866,7 @@ public class cgeodetail extends AbstractActivity { } // cache inventory - if (cache.inventory != null && cache.inventory.size() > 0) { + if (CollectionUtils.isNotEmpty(cache.inventory)) { final LinearLayout inventBox = (LinearLayout) findViewById(R.id.inventory_box); final TextView inventView = (TextView) findViewById(R.id.inventory); @@ -927,7 +928,7 @@ public class cgeodetail extends AbstractActivity { offlineRefresh.setClickable(true); // cache personal note - if (cache.personalNote != null && cache.personalNote.length() > 0) { + if (StringUtils.isNotBlank(cache.personalNote)) { ((LinearLayout) findViewById(R.id.personalnote_box)).setVisibility(View.VISIBLE); TextView personalNoteText = (TextView) findViewById(R.id.personalnote); @@ -937,7 +938,7 @@ public class cgeodetail extends AbstractActivity { } // cache short desc - if (cache.shortdesc != null && cache.shortdesc.length() > 0) { + if (StringUtils.isNotBlank(cache.shortdesc)) { ((LinearLayout) findViewById(R.id.desc_box)).setVisibility(View.VISIBLE); TextView descView = (TextView) findViewById(R.id.shortdesc); @@ -950,7 +951,7 @@ public class cgeodetail extends AbstractActivity { if (longDescDisplayed) { parseLongDescription(); - if (longDesc != null && longDesc.length() > 0) { + if (StringUtils.isNotBlank(longDesc)) { ((LinearLayout) findViewById(R.id.desc_box)).setVisibility(View.VISIBLE); TextView descView = (TextView) findViewById(R.id.description); @@ -963,7 +964,7 @@ public class cgeodetail extends AbstractActivity { showDesc.setOnTouchListener(null); showDesc.setOnClickListener(null); } - } else if (longDescDisplayed == false && cache.description != null && cache.description.length() > 0) { + } else if (longDescDisplayed == false && StringUtils.isNotBlank(cache.description)) { ((LinearLayout) findViewById(R.id.desc_box)).setVisibility(View.VISIBLE); Button showDesc = (Button) findViewById(R.id.show_description); @@ -986,7 +987,7 @@ public class cgeodetail extends AbstractActivity { LinearLayout waypoints = (LinearLayout) findViewById(R.id.waypoints); waypoints.removeAllViews(); - if (cache.waypoints != null && cache.waypoints.size() > 0) { + if (CollectionUtils.isNotEmpty(cache.waypoints)) { LinearLayout waypointView; // sort waypoints: PP, Sx, FI, OWN @@ -1000,7 +1001,7 @@ public class cgeodetail extends AbstractActivity { } private int order(cgWaypoint waypoint) { - if (waypoint.prefix == null || waypoint.prefix.length() == 0) { + if (StringUtils.isEmpty(waypoint.prefix)) { return 0; } // check only the first character. sometimes there are inconsistencies like FI or FN for the FINAL @@ -1034,7 +1035,7 @@ public class cgeodetail extends AbstractActivity { } TextView nameView = (TextView) waypointView.findViewById(R.id.name); - if (wpt.name.trim().length() == 0) { + if (StringUtils.isBlank(wpt.name)) { nameView.setText(cgBase.formatCoords(wpt.latitude, wpt.longitude, true)); } else { // avoid HTML parsing @@ -1066,7 +1067,7 @@ public class cgeodetail extends AbstractActivity { addWaypoint.setOnClickListener(new addWaypoint()); // cache hint - if (cache.hint != null && cache.hint.length() > 0) { + if (StringUtils.isNotBlank(cache.hint)) { ((LinearLayout) findViewById(R.id.hint_box)).setVisibility(View.VISIBLE); TextView hintView = ((TextView) findViewById(R.id.hint)); hintView.setText(cgBase.rot13(cache.hint.trim())); @@ -1303,9 +1304,9 @@ public class cgeodetail extends AbstractActivity { @Override public void run() { HashMap<String, String> params = new HashMap<String, String>(); - if (geocode != null && geocode.length() > 0) { + if (StringUtils.isNotBlank(geocode)) { params.put("geocode", geocode); - } else if (guid != null && guid.length() > 0) { + } else if (StringUtils.isNotBlank(guid)) { params.put("guid", guid); } else { return; @@ -1386,7 +1387,7 @@ public class cgeodetail extends AbstractActivity { // cache coords = new cgCoord(); coords.type = "cache"; - if (name != null && name.length() > 0) { + if (StringUtils.isNotBlank(name)) { coords.name = name; } else { coords.name = geocode.toUpperCase(); @@ -1492,11 +1493,11 @@ public class cgeodetail extends AbstractActivity { description.append("http://coord.info/"); description.append(cache.geocode.toUpperCase()); description.append("\n\n"); - if (cache.shortdesc != null && cache.shortdesc.length() > 0) { + if (StringUtils.isNotBlank(cache.shortdesc)) { description.append(Html.fromHtml(cache.shortdesc).toString()); } - if (cache.personalNote != null && cache.personalNote.length() > 0) { + if (StringUtils.isNotBlank(cache.personalNote)) { description.append("\n\n"+Html.fromHtml(cache.personalNote).toString()); } @@ -1508,10 +1509,10 @@ public class cgeodetail extends AbstractActivity { event.put("title", Html.fromHtml(cache.name).toString()); event.put("description", description.toString()); String location = ""; - if (cache.latitudeString != null && cache.latitudeString.length() > 0 && cache.longitudeString != null && cache.longitudeString.length() > 0) { + if (StringUtils.isNotBlank(cache.latitudeString) && StringUtils.isNotBlank(cache.longitudeString)) { location += cache.latitudeString + " " + cache.longitudeString; } - if (cache.location != null && cache.location.length() > 0) { + if (StringUtils.isNotBlank(cache.location)) { boolean addParenteses = false; if (location.length() > 0) { addParenteses = true; @@ -1569,7 +1570,7 @@ public class cgeodetail extends AbstractActivity { if (cache != null && cache.geocode != null) { String subject = cache.geocode.toUpperCase(); - if (cache.name != null && cache.name.length() > 0){ + if (StringUtils.isNotBlank(cache.name)){ subject = subject + " - " + cache.name; } intent.putExtra(Intent.EXTRA_SUBJECT, "Geocache " + subject); @@ -2073,7 +2074,7 @@ public class cgeodetail extends AbstractActivity { base.context.getPackageName()); if (id > 0) { String translated = res.getString(id); - if (translated != null && translated.length() > 0) { + if (StringUtils.isNotBlank(translated)) { attribute = translated; } } diff --git a/src/cgeo/geocaching/cgeoimages.java b/src/cgeo/geocaching/cgeoimages.java index c5975d0..b933c46 100644 --- a/src/cgeo/geocaching/cgeoimages.java +++ b/src/cgeo/geocaching/cgeoimages.java @@ -4,6 +4,8 @@ import java.io.File; import java.io.FileOutputStream; import java.util.ArrayList; +import org.apache.commons.lang3.StringUtils; + import android.app.ProgressDialog; import android.content.Intent; import android.graphics.Bitmap.CompressFormat; @@ -92,7 +94,7 @@ public class cgeoimages extends AbstractActivity { ((TextView) rowView.findViewById(R.id.title)).setText(Html.fromHtml(img.title)); - if (img.description != null && img.description.length() > 0) { + if (StringUtils.isNotBlank(img.description)) { final TextView descView = (TextView) rowView.findViewById(R.id.description); descView.setText(Html.fromHtml(img.description), TextView.BufferType.SPANNABLE); descView.setVisibility(View.VISIBLE); diff --git a/src/cgeo/geocaching/cgeoinit.java b/src/cgeo/geocaching/cgeoinit.java index e3111e2..39b8e51 100644 --- a/src/cgeo/geocaching/cgeoinit.java +++ b/src/cgeo/geocaching/cgeoinit.java @@ -2,6 +2,8 @@ package cgeo.geocaching; import java.io.File; +import org.apache.commons.lang3.StringUtils; + import android.app.ProgressDialog; import android.content.Intent; import android.content.SharedPreferences; @@ -261,7 +263,7 @@ public class cgeoinit extends AbstractActivity { }); CheckBox twitterButton = (CheckBox) findViewById(R.id.twitter_option); - if (prefs.getInt("twitter", 0) == 0 || settings.tokenPublic == null || settings.tokenPublic.length() == 0 || settings.tokenSecret == null || settings.tokenSecret.length() == 0) { + if (prefs.getInt("twitter", 0) == 0 || StringUtils.isBlank(settings.tokenPublic) || StringUtils.isBlank(settings.tokenSecret)) { twitterButton.setChecked(false); } else { twitterButton.setChecked(true); @@ -435,7 +437,7 @@ public class cgeoinit extends AbstractActivity { //Send2cgeo settings String webDeviceName = prefs.getString("webDeviceName", null); - if ((webDeviceName != null) &&(webDeviceName.length() > 0)) { + if (StringUtils.isNotBlank(webDeviceName)) { ((EditText) findViewById(R.id.webDeviceName)).setText(webDeviceName); } else { String s = android.os.Build.MODEL; @@ -579,7 +581,7 @@ public class cgeoinit extends AbstractActivity { } edit.commit(); - if (settings.twitter == 1 && (settings.tokenPublic == null || settings.tokenPublic.length() == 0 || settings.tokenSecret == null || settings.tokenSecret.length() == 0)) { + if (settings.twitter == 1 && (StringUtils.isBlank(settings.tokenPublic) || StringUtils.isBlank(settings.tokenSecret))) { Intent authIntent = new Intent(cgeoinit.this, cgeoauth.class); startActivity(authIntent); } @@ -1009,7 +1011,7 @@ public class cgeoinit extends AbstractActivity { final String username = ((EditText) findViewById(R.id.username)).getText().toString(); final String password = ((EditText) findViewById(R.id.password)).getText().toString(); - if (username == null || username.length() == 0 || password == null || password.length() == 0) { + if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) { showToast(res.getString(R.string.err_missing_auth)); return; } @@ -1042,7 +1044,7 @@ public class cgeoinit extends AbstractActivity { final String deviceCode = prefs.getString("webDeviceCode", null); - if (deviceName == null || deviceName.length() == 0) { + if (StringUtils.isBlank(deviceName)) { showToast(res.getString(R.string.err_missing_device_name)); return; } diff --git a/src/cgeo/geocaching/cgeonavigate.java b/src/cgeo/geocaching/cgeonavigate.java index 4b51367..5a6dcee 100644 --- a/src/cgeo/geocaching/cgeonavigate.java +++ b/src/cgeo/geocaching/cgeonavigate.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Locale; +import org.apache.commons.lang3.StringUtils; + import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -86,8 +88,8 @@ public class cgeonavigate extends AbstractActivity { dstLatitude = extras.getDouble("latitude"); dstLongitude = extras.getDouble("longitude"); - if (name != null && name.length() > 0) { - if (title != null && title.length() > 0) { + if (StringUtils.isNotBlank(name)) { + if (StringUtils.isNotBlank(title)) { title = title + ": " + name; } else { title = name; @@ -101,9 +103,9 @@ public class cgeonavigate extends AbstractActivity { return; } - if (title != null && title.length() > 0) { + if (StringUtils.isNotBlank(title)) { app.setAction(title); - } else if (name != null && name.length() > 0) { + } else if (StringUtils.isNotBlank(name)) { app.setAction(name); } @@ -132,9 +134,9 @@ public class cgeonavigate extends AbstractActivity { settings.load(); - if (title != null && title.length() > 0) { + if (StringUtils.isNotBlank(title)) { app.setAction(title); - } else if (name != null && name.length() > 0) { + } else if (StringUtils.isNotBlank(name)) { app.setAction(name); } @@ -295,7 +297,7 @@ public class cgeonavigate extends AbstractActivity { } private void setTitle() { - if (title != null && title.length() > 0) { + if (StringUtils.isNotBlank(title)) { setTitle(title); } else { setTitle(res.getString(R.string.navigation)); @@ -464,4 +466,4 @@ public class cgeonavigate extends AbstractActivity { } } } -}
\ No newline at end of file +} diff --git a/src/cgeo/geocaching/cgeopoint.java b/src/cgeo/geocaching/cgeopoint.java index d9cdfc6..907bc3d 100644 --- a/src/cgeo/geocaching/cgeopoint.java +++ b/src/cgeo/geocaching/cgeopoint.java @@ -6,6 +6,8 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.lang3.StringUtils; + import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -483,13 +485,13 @@ public class cgeopoint extends AbstractActivity { String latText = ((EditText) findViewById(R.id.latitude)).getText().toString(); String lonText = ((EditText) findViewById(R.id.longitude)).getText().toString(); - if ((bearingText == null || bearingText.length() == 0) && (distanceText == null || distanceText.length() == 0) - && (latText == null || latText.length() == 0) && (lonText == null || lonText.length() == 0)) { + if (StringUtils.isBlank(bearingText) && StringUtils.isBlank(distanceText) + && StringUtils.isBlank(latText) && StringUtils.isBlank(lonText)) { showToast(res.getString(R.string.err_point_no_position_given)); return null; } - if (latText != null && latText.length() > 0 && lonText != null && lonText.length() > 0) { + if (StringUtils.isNotBlank(latText) && StringUtils.isNotBlank(lonText)) { // latitude & longitude HashMap<String, Object> latParsed = cgBase.parseCoordinate(latText, "lat"); HashMap<String, Object> lonParsed = cgBase.parseCoordinate(lonText, "lon"); @@ -516,7 +518,7 @@ public class cgeopoint extends AbstractActivity { longitude = geo.longitudeNow; } - if (bearingText != null && bearingText.length() > 0 && distanceText != null && distanceText.length() > 0) { + if (StringUtils.isNotBlank(bearingText) && StringUtils.isNotBlank(distanceText)) { // bearing & distance Double bearing = null; try { diff --git a/src/cgeo/geocaching/cgeopopup.java b/src/cgeo/geocaching/cgeopopup.java index 8531338..9b1d816 100644 --- a/src/cgeo/geocaching/cgeopopup.java +++ b/src/cgeo/geocaching/cgeopopup.java @@ -2,6 +2,8 @@ package cgeo.geocaching; import java.util.Locale; +import org.apache.commons.lang3.StringUtils; + import android.app.ProgressDialog; import android.content.Intent; import android.content.res.Configuration; @@ -117,7 +119,7 @@ public class cgeopopup extends AbstractActivity { geocode = extras.getString("geocode"); } - if (geocode == null || geocode.length() == 0) { + if (StringUtils.isBlank(geocode)) { showToast(res.getString(R.string.err_detail_cache_find)); finish(); @@ -212,7 +214,7 @@ public class cgeopopup extends AbstractActivity { TextView itemValue; LinearLayout itemStars; - if (cache.name != null && cache.name.length() > 0) { + if (StringUtils.isNotBlank(cache.name)) { setTitle(cache.name); } else { setTitle(geocode.toUpperCase()); @@ -235,13 +237,13 @@ public class cgeopopup extends AbstractActivity { itemName.setText(res.getString(R.string.cache_type)); if (cgBase.cacheTypesInv.containsKey(cache.type)) { // cache icon - if (cache.size != null && cache.size.length() > 0) { + if (StringUtils.isNotBlank(cache.size)) { itemValue.setText(cgBase.cacheTypesInv.get(cache.type) + " (" + cache.size + ")"); } else { itemValue.setText(cgBase.cacheTypesInv.get(cache.type)); } } else { - if (cache.size != null && cache.size.length() > 0) { + if (StringUtils.isNotBlank(cache.size)) { itemValue.setText(cgBase.cacheTypesInv.get("mystery") + " (" + cache.size + ")"); } else { itemValue.setText(cgBase.cacheTypesInv.get("mystery")); @@ -662,4 +664,4 @@ public class cgeopopup extends AbstractActivity { super.goManual(view); finish(); } -}
\ No newline at end of file +} diff --git a/src/cgeo/geocaching/cgeosmaps.java b/src/cgeo/geocaching/cgeosmaps.java index 35d09d0..ddc9732 100644 --- a/src/cgeo/geocaching/cgeosmaps.java +++ b/src/cgeo/geocaching/cgeosmaps.java @@ -13,6 +13,7 @@ import android.view.LayoutInflater; import android.widget.ImageView; import android.widget.LinearLayout; import cgeo.geocaching.activity.AbstractActivity; +import cgeo.geocaching.utils.CollectionUtils; public class cgeosmaps extends AbstractActivity { @@ -27,7 +28,7 @@ public class cgeosmaps extends AbstractActivity { @Override public void handleMessage(Message msg) { try { - if (maps == null || maps.isEmpty()) { + if (CollectionUtils.isEmpty(maps)) { if (waitDialog != null) { waitDialog.dismiss(); } diff --git a/src/cgeo/geocaching/cgeotouch.java b/src/cgeo/geocaching/cgeotouch.java index a085255..f75ced7 100644 --- a/src/cgeo/geocaching/cgeotouch.java +++ b/src/cgeo/geocaching/cgeotouch.java @@ -4,6 +4,9 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; + import android.app.Dialog; import android.app.ProgressDialog; import android.content.res.Configuration; @@ -46,7 +49,7 @@ public class cgeotouch extends cgLogForm { private Handler loadDataHandler = new Handler() { @Override public void handleMessage(Message msg) { - if (cgBase.isEmpty(viewstates) && attempts < 2) { + if (ArrayUtils.isEmpty(viewstates) && attempts < 2) { showToast(res.getString(R.string.err_log_load_data_again)); loadData thread; @@ -54,7 +57,7 @@ public class cgeotouch extends cgLogForm { thread.start(); return; - } else if (cgBase.isEmpty(viewstates) && attempts >= 2) { + } else if (ArrayUtils.isEmpty(viewstates) && attempts >= 2) { showToast(res.getString(R.string.err_log_load_data)); showProgress(false); @@ -125,7 +128,7 @@ public class cgeotouch extends cgLogForm { trackable = app.getTrackableByGeocode("logging trackable"); - if (trackable.name != null && trackable.name.length() > 0) { + if (StringUtils.isNotBlank(trackable.name)) { setTitle(res.getString(R.string.trackable_touch) + trackable.name); } else { setTitle(res.getString(R.string.trackable_touch) + trackable.geocode.toUpperCase()); @@ -285,7 +288,7 @@ public class cgeotouch extends cgLogForm { tweetCheck.setChecked(true); Button buttonPost = (Button)findViewById(R.id.post); - if (cgBase.isEmpty(viewstates)) { + if (ArrayUtils.isEmpty(viewstates)) { buttonPost.setEnabled(false); buttonPost.setOnTouchListener(null); buttonPost.setOnClickListener(null); @@ -365,7 +368,7 @@ public class cgeotouch extends cgLogForm { attempts ++; try { - if (guid != null && guid.length() > 0) { + if (StringUtils.isNotBlank(guid)) { params.put("wid", guid); } else { loadDataHandler.sendEmptyMessage(0); @@ -428,7 +431,7 @@ public class cgeotouch extends cgLogForm { if ( status == 1 && settings.twitter == 1 && - settings.tokenPublic != null && settings.tokenPublic.length() > 0 && settings.tokenSecret != null && settings.tokenSecret.length() > 0 && + StringUtils.isNotBlank(settings.tokenPublic) && StringUtils.isNotBlank(settings.tokenSecret) && tweetCheck.isChecked() && tweetBox.getVisibility() == View.VISIBLE ) { cgBase.postTweetTrackable(app, settings, geocode); diff --git a/src/cgeo/geocaching/cgeotrackable.java b/src/cgeo/geocaching/cgeotrackable.java index d41324e..8959771 100644 --- a/src/cgeo/geocaching/cgeotrackable.java +++ b/src/cgeo/geocaching/cgeotrackable.java @@ -4,6 +4,8 @@ import java.net.URLEncoder; import java.util.Arrays; import java.util.HashMap; +import org.apache.commons.lang3.StringUtils; + import android.app.ProgressDialog; import android.content.Intent; import android.graphics.drawable.BitmapDrawable; @@ -51,7 +53,7 @@ public class cgeotrackable extends AbstractActivity { return; } - if (trackable != null && trackable.error.length() > 0) { + if (trackable != null && StringUtils.isNotBlank(trackable.error)) { showToast(res.getString(R.string.err_tb_details_download) + " " + trackable.error + "."); finish(); @@ -63,7 +65,7 @@ public class cgeotrackable extends AbstractActivity { waitDialog.dismiss(); } - if (geocode != null && geocode.length() > 0) { + if (StringUtils.isNotBlank(geocode)) { showToast(res.getString(R.string.err_tb_find) + " " + geocode + "."); } else { showToast(res.getString(R.string.err_tb_find_that)); @@ -77,7 +79,7 @@ public class cgeotrackable extends AbstractActivity { inflater = getLayoutInflater(); geocode = trackable.geocode.toUpperCase(); - if (trackable.name != null && trackable.name.length() > 0) { + if (StringUtils.isNotBlank(trackable.name)) { setTitle(Html.fromHtml(trackable.name).toString()); } else { setTitle(trackable.name.toUpperCase()); @@ -87,7 +89,7 @@ public class cgeotrackable extends AbstractActivity { LinearLayout detailsList = (LinearLayout) findViewById(R.id.details_list); // actiobar icon - if (trackable.iconUrl != null && trackable.iconUrl.length() > 0) { + if (StringUtils.isNotBlank(trackable.iconUrl)) { final tbIconHandler iconHandler = new tbIconHandler(((TextView) findViewById(R.id.actionbar_title))); final tbIconThread iconThread = new tbIconThread(trackable.iconUrl, iconHandler); iconThread.start(); @@ -99,7 +101,7 @@ public class cgeotrackable extends AbstractActivity { itemValue = (TextView) itemLayout.findViewById(R.id.value); itemName.setText(res.getString(R.string.trackable_name)); - if (trackable.name != null) { + if (StringUtils.isNotBlank(trackable.name)) { itemValue.setText(Html.fromHtml(trackable.name).toString()); } else { itemValue.setText(res.getString(R.string.trackable_unknown)); @@ -112,7 +114,7 @@ public class cgeotrackable extends AbstractActivity { itemValue = (TextView) itemLayout.findViewById(R.id.value); String tbType = null; - if (trackable.type != null && trackable.type.length() > 0) { + if (StringUtils.isNotBlank(trackable.type)) { tbType = Html.fromHtml(trackable.type).toString(); } else { tbType = res.getString(R.string.trackable_unknown); @@ -136,7 +138,7 @@ public class cgeotrackable extends AbstractActivity { itemValue = (TextView) itemLayout.findViewById(R.id.value); itemName.setText(res.getString(R.string.trackable_owner)); - if (trackable.owner != null) { + if (StringUtils.isNotBlank(trackable.owner)) { itemValue.setText(Html.fromHtml(trackable.owner), TextView.BufferType.SPANNABLE); itemLayout.setOnClickListener(new userActions()); } else { @@ -145,10 +147,9 @@ public class cgeotrackable extends AbstractActivity { detailsList.addView(itemLayout); // trackable spotted - if ( - (trackable.spottedName != null && trackable.spottedName.length() > 0) || - trackable.spottedType == cgTrackable.SPOTTED_UNKNOWN || - trackable.spottedType == cgTrackable.SPOTTED_OWNER + if (StringUtils.isNotBlank(trackable.spottedName) || + trackable.spottedType == cgTrackable.SPOTTED_UNKNOWN || + trackable.spottedType == cgTrackable.SPOTTED_OWNER ) { itemLayout = (RelativeLayout)inflater.inflate(R.layout.cache_item, null); itemName = (TextView) itemLayout.findViewById(R.id.name); @@ -189,7 +190,7 @@ public class cgeotrackable extends AbstractActivity { } // trackable origin - if (trackable.origin != null && trackable.origin.length() > 0) { + if (StringUtils.isNotBlank(trackable.origin)) { itemLayout = (RelativeLayout)inflater.inflate(R.layout.cache_item, null); itemName = (TextView) itemLayout.findViewById(R.id.name); itemValue = (TextView) itemLayout.findViewById(R.id.value); @@ -223,7 +224,7 @@ public class cgeotrackable extends AbstractActivity { // trackable goal - if (trackable.goal != null && trackable.goal.length() > 0) { + if (StringUtils.isNotBlank(trackable.goal)) { ((LinearLayout) findViewById(R.id.goal_box)).setVisibility(View.VISIBLE); TextView descView = (TextView) findViewById(R.id.goal); descView.setVisibility(View.VISIBLE); @@ -232,7 +233,7 @@ public class cgeotrackable extends AbstractActivity { } // trackable details - if (trackable.details != null && trackable.details.length() > 0) { + if (StringUtils.isNotBlank(trackable.details)) { ((LinearLayout) findViewById(R.id.details_box)).setVisibility(View.VISIBLE); TextView descView = (TextView) findViewById(R.id.details); descView.setVisibility(View.VISIBLE); @@ -241,7 +242,7 @@ public class cgeotrackable extends AbstractActivity { } // trackable image - if (trackable.image != null && trackable.image.length() > 0) { + if (StringUtils.isNotBlank(trackable.image)) { ((LinearLayout) findViewById(R.id.image_box)).setVisibility(View.VISIBLE); LinearLayout imgView = (LinearLayout) findViewById(R.id.image); @@ -331,15 +332,15 @@ public class cgeotrackable extends AbstractActivity { guid = uri.getQueryParameter("guid"); id = uri.getQueryParameter("id"); - if (geocode != null && geocode.length() > 0) { + if (StringUtils.isNotBlank(geocode)) { geocode = geocode.toUpperCase(); guid = null; id = null; - } else if (guid != null && guid.length() > 0) { + } else if (StringUtils.isNotBlank(guid)) { geocode = null; guid = guid.toLowerCase(); id = null; - } else if (id != null && id.length() > 0) { + } else if (StringUtils.isNotBlank(id)) { geocode = null; guid = null; id = id.toLowerCase(); @@ -369,9 +370,9 @@ public class cgeotrackable extends AbstractActivity { return; } - if (name != null && name.length() > 0) { + if (StringUtils.isNotBlank(name)) { waitDialog = ProgressDialog.show(this, Html.fromHtml(name).toString(), res.getString(R.string.trackable_details_loading), true); - } else if (geocode != null && geocode.length() > 0) { + } else if (StringUtils.isNotBlank(geocode)) { waitDialog = ProgressDialog.show(this, geocode.toUpperCase(), res.getString(R.string.trackable_details_loading), true); } else { waitDialog = ProgressDialog.show(this, res.getString(R.string.trackable), res.getString(R.string.trackable_details_loading), true); @@ -486,11 +487,11 @@ public class cgeotrackable extends AbstractActivity { public void loadTrackableFn(String geocode, String guid, String id) { HashMap<String, String> params = new HashMap<String, String>(); - if (geocode != null && geocode.length() > 0) { + if (StringUtils.isNotBlank(geocode)) { params.put("geocode", geocode); - } else if (guid != null && guid.length() > 0) { + } else if (StringUtils.isNotBlank(guid)) { params.put("guid", guid); - } else if (id != null && id.length() > 0) { + } else if (StringUtils.isNotBlank(id)) { params.put("id", id); } else { return; @@ -522,7 +523,7 @@ public class cgeotrackable extends AbstractActivity { } ((TextView) rowView.findViewById(R.id.author)).setText(Html.fromHtml(log.author), TextView.BufferType.SPANNABLE); - if (log.cacheName == null || log.cacheName.length() == 0) { + if (StringUtils.isBlank(log.cacheName)) { ((TextView) rowView.findViewById(R.id.location)).setVisibility(View.GONE); } else { ((TextView) rowView.findViewById(R.id.location)).setText(Html.fromHtml(log.cacheName)); diff --git a/src/cgeo/geocaching/cgeovisit.java b/src/cgeo/geocaching/cgeovisit.java index c26dba4..924ea7f 100644 --- a/src/cgeo/geocaching/cgeovisit.java +++ b/src/cgeo/geocaching/cgeovisit.java @@ -6,6 +6,9 @@ import java.util.Date; import java.util.HashMap; import java.util.Locale; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; + import android.app.Dialog; import android.app.ProgressDialog; import android.content.Intent; @@ -26,6 +29,7 @@ import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; import cgeo.geocaching.LogTemplateProvider.LogTemplate; +import cgeo.geocaching.utils.CollectionUtils; public class cgeovisit extends cgLogForm { static final String EXTRAS_FOUND = "found"; @@ -79,7 +83,7 @@ public class cgeovisit extends cgLogForm { showToast(res.getString(R.string.info_log_type_changed)); } - if (cgBase.isEmpty(viewstates) && attempts < 2) { + if (ArrayUtils.isEmpty(viewstates) && attempts < 2) { showToast(res.getString(R.string.err_log_load_data_again)); loadData thread; @@ -87,7 +91,7 @@ public class cgeovisit extends cgLogForm { thread.start(); return; - } else if (cgBase.isEmpty(viewstates) && attempts >= 2) { + } else if (ArrayUtils.isEmpty(viewstates) && attempts >= 2) { showToast(res.getString(R.string.err_log_load_data)); showProgress(false); @@ -103,7 +107,7 @@ public class cgeovisit extends cgLogForm { post.setOnClickListener(new postListener()); // add trackables - if (trackables != null && trackables.isEmpty() == false) { + if (CollectionUtils.isNotEmpty(trackables)) { if (inflater == null) { inflater = getLayoutInflater(); } @@ -234,16 +238,16 @@ public class cgeovisit extends cgLogForm { alreadyFound = extras.getBoolean(EXTRAS_FOUND); } - if ((cacheid == null || cacheid.length() == 0) && geocode != null && geocode.length() > 0) { + if ((StringUtils.isBlank(cacheid)) && StringUtils.isNotBlank(geocode)) { cacheid = app.getCacheid(geocode); } - if ((geocode == null || geocode.length() == 0) && cacheid != null && cacheid.length() > 0) { + if ((StringUtils.isBlank(geocode)) && StringUtils.isNotBlank(cacheid)) { geocode = app.getGeocode(cacheid); } cache = app.getCacheByGeocode(geocode); - if (cache.name != null && cache.name.length() > 0) { + if (StringUtils.isNotBlank(cache.name)) { setTitle(res.getString(R.string.log_new_log) + " " + cache.name); } else { setTitle(res.getString(R.string.log_new_log) + " " + cache.geocode.toUpperCase()); @@ -305,7 +309,7 @@ public class cgeovisit extends cgLogForm { boolean signatureAvailable = settings.getSignature() != null; menu.findItem(MENU_SIGNATURE).setVisible(signatureAvailable); - boolean voteAvailable = settings.isGCvoteLogin() && typeSelected == cgBase.LOG_FOUND_IT && cache.guid != null && cache.guid.length() > 0; + boolean voteAvailable = settings.isGCvoteLogin() && typeSelected == cgBase.LOG_FOUND_IT && StringUtils.isNotBlank(cache.guid); menu.findItem(SUBMENU_VOTE).setVisible(voteAvailable); return true; @@ -318,7 +322,7 @@ public class cgeovisit extends cgLogForm { if (id == MENU_SIGNATURE) { EditText log = (EditText) findViewById(R.id.log); String content = log.getText().toString(); - if (content.length() > 0) { + if (StringUtils.isNotBlank(content)) { insertIntoLog("\n"); } insertIntoLog(LogTemplateProvider.applyTemplates(settings.getSignature(), base)); @@ -355,7 +359,7 @@ public class cgeovisit extends cgLogForm { } public boolean setRating(String guid, double vote) { - if (guid == null || guid.length() == 0) { + if (StringUtils.isBlank(guid)) { return false; } if (vote < 0.0 || vote > 5.0) { @@ -498,10 +502,9 @@ public class cgeovisit extends cgLogForm { } post.setText(res.getString(R.string.log_post_no_rate)); } - } else if (settings.getSignature() != null + } else if (StringUtils.isNotBlank(settings.getSignature()) && settings.signatureAutoinsert - && settings.getSignature().length() > 0 - && 0 == ((EditText) findViewById(R.id.log)).getText().length()) { + && StringUtils.isBlank(((EditText) findViewById(R.id.log)).getText())) { insertIntoLog(LogTemplateProvider.applyTemplates(settings.getSignature(), base)); } @@ -529,7 +532,7 @@ public class cgeovisit extends cgLogForm { dateButton.setOnClickListener(new cgeovisitDateListener()); EditText logView = (EditText) findViewById(R.id.log); - if (logView.getText().length() == 0 && text != null && text.length() > 0) { + if (StringUtils.isBlank(logView.getText()) && StringUtils.isNotBlank(text) ) { logView.setText(text); } @@ -545,7 +548,7 @@ public class cgeovisit extends cgLogForm { if (post == null) { post = (Button) findViewById(R.id.post); } - if (cgBase.isEmpty(viewstates)) { + if (ArrayUtils.isEmpty(viewstates)) { post.setEnabled(false); post.setOnTouchListener(null); post.setOnClickListener(null); @@ -670,7 +673,7 @@ public class cgeovisit extends cgLogForm { dateButton.setOnClickListener(new cgeovisitDateListener()); EditText logView = (EditText) findViewById(R.id.log); - if (text != null && text.length() > 0) { + if (StringUtils.isNotBlank(text)) { logView.setText(text); } else { logView.setText(""); @@ -705,7 +708,7 @@ public class cgeovisit extends cgLogForm { attempts++; try { - if (cacheid != null && cacheid.length() > 0) { + if (StringUtils.isNotBlank(cacheid)) { params.put("ID", cacheid); } else { loadDataHandler.sendEmptyMessage(0); @@ -718,7 +721,7 @@ public class cgeovisit extends cgLogForm { trackables = cgBase.parseTrackableLog(page); final ArrayList<Integer> typesPre = cgBase.parseTypes(page); - if (typesPre.size() > 0) { + if (CollectionUtils.isNotEmpty(typesPre)) { types.clear(); types.addAll(typesPre); types.remove(Integer.valueOf(cgBase.LOG_UPDATE_COORDINATES)); @@ -799,8 +802,8 @@ public class cgeovisit extends cgLogForm { if ( status == 1 && typeSelected == cgBase.LOG_FOUND_IT && settings.twitter == 1 - && settings.tokenPublic != null && settings.tokenPublic.length() > 0 && settings.tokenSecret != null - && settings.tokenSecret.length() > 0 && tweetCheck.isChecked() && tweetBox.getVisibility() == View.VISIBLE + && StringUtils.isNotBlank(settings.tokenPublic) && StringUtils.isNotBlank(settings.tokenSecret) + && tweetCheck.isChecked() && tweetBox.getVisibility() == View.VISIBLE ) { cgBase.postTweetCache(app, settings, geocode); } diff --git a/src/cgeo/geocaching/cgeowaypoint.java b/src/cgeo/geocaching/cgeowaypoint.java index 59a6fb3..d623bb9 100644 --- a/src/cgeo/geocaching/cgeowaypoint.java +++ b/src/cgeo/geocaching/cgeowaypoint.java @@ -2,6 +2,8 @@ package cgeo.geocaching; import java.util.ArrayList; +import org.apache.commons.lang3.StringUtils; + import android.app.ProgressDialog; import android.content.Intent; import android.os.Bundle; @@ -56,7 +58,7 @@ public class cgeowaypoint extends AbstractActivity { final View headline = (View) findViewById(R.id.headline); registerNavigationMenu(headline); - if (waypoint.name != null && waypoint.name.length() > 0) { + if (StringUtils.isNotBlank(waypoint.name)) { setTitle(Html.fromHtml(waypoint.name.trim()).toString()); } else { setTitle(res.getString(R.string.waypoint_title)); @@ -81,7 +83,7 @@ public class cgeowaypoint extends AbstractActivity { } registerNavigationMenu(coords); - if (waypoint.note != null && waypoint.note.length() > 0) { + if (StringUtils.isNotBlank(waypoint.note)) { final TextView note = (TextView) findViewById(R.id.note); note.setText(Html.fromHtml(waypoint.note.trim()), TextView.BufferType.SPANNABLE); registerNavigationMenu(note); @@ -344,4 +346,4 @@ public class cgeowaypoint extends AbstractActivity { public boolean onContextItemSelected(MenuItem item) { return onOptionsItemSelected(item); } -}
\ No newline at end of file +} diff --git a/src/cgeo/geocaching/cgeowaypointadd.java b/src/cgeo/geocaching/cgeowaypointadd.java index 6e61e10..3b6c3eb 100644 --- a/src/cgeo/geocaching/cgeowaypointadd.java +++ b/src/cgeo/geocaching/cgeowaypointadd.java @@ -5,6 +5,8 @@ import java.util.HashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.lang3.StringUtils; + import android.app.ProgressDialog; import android.os.Bundle; import android.os.Handler; @@ -94,7 +96,7 @@ public class cgeowaypointadd extends AbstractActivity { id = extras.getInt("waypoint"); } - if ((geocode == null || geocode.length() == 0) && id <= 0) { + if (StringUtils.isBlank(geocode) && id <= 0) { showToast(res.getString(R.string.err_waypoint_cache_unknown)); finish(); @@ -245,13 +247,13 @@ public class cgeowaypointadd extends AbstractActivity { final String latText = ((Button) findViewById(R.id.buttonLatitude)).getText().toString(); final String lonText = ((Button) findViewById(R.id.buttonLongitude)).getText().toString(); - if ((bearingText == null || bearingText.length() == 0) && (distanceText == null || distanceText.length() == 0) - && (latText == null || latText.length() == 0) && (lonText == null || lonText.length() == 0)) { + if (StringUtils.isNotBlank(bearingText) && StringUtils.isNotBlank(distanceText) + && StringUtils.isNotBlank(latText) && StringUtils.isNotBlank(lonText)) { helpDialog(res.getString(R.string.err_point_no_position_given_title), res.getString(R.string.err_point_no_position_given)); return; } - if (latText != null && latText.length() > 0 && lonText != null && lonText.length() > 0) { + if (StringUtils.isNotBlank(latText) && StringUtils.isNotBlank(lonText)) { // latitude & longitude HashMap<String, Object> latParsed = cgBase.parseCoordinate(latText, "lat"); HashMap<String, Object> lonParsed = cgBase.parseCoordinate(lonText, "lon"); @@ -278,7 +280,7 @@ public class cgeowaypointadd extends AbstractActivity { longitude = geo.longitudeNow; } - if (bearingText != null && bearingText.length() > 0 && distanceText != null && distanceText.length() > 0) { + if (StringUtils.isNotBlank(bearingText) && StringUtils.isNotBlank(distanceText)) { // bearing & distance Double bearing = null; try { @@ -392,4 +394,4 @@ public class cgeowaypointadd extends AbstractActivity { ActivityMixin.goManual(this, "c:geo-waypoint-new"); } } -}
\ No newline at end of file +} diff --git a/src/cgeo/geocaching/connector/GCConnector.java b/src/cgeo/geocaching/connector/GCConnector.java index 5d5de6b..1d61d2f 100644 --- a/src/cgeo/geocaching/connector/GCConnector.java +++ b/src/cgeo/geocaching/connector/GCConnector.java @@ -1,12 +1,14 @@ package cgeo.geocaching.connector; +import org.apache.commons.lang3.StringUtils; + import cgeo.geocaching.cgCache; public class GCConnector extends AbstractConnector implements IConnector { @Override public boolean canHandle(String geocode) { - return geocode != null && geocode.toUpperCase().startsWith("GC"); + return StringUtils.isNotBlank(geocode) && geocode.toUpperCase().startsWith("GC"); } @Override diff --git a/src/cgeo/geocaching/connector/OCConnector.java b/src/cgeo/geocaching/connector/OCConnector.java index d23b3cd..8d1c42f 100644 --- a/src/cgeo/geocaching/connector/OCConnector.java +++ b/src/cgeo/geocaching/connector/OCConnector.java @@ -1,5 +1,7 @@ package cgeo.geocaching.connector; +import org.apache.commons.lang3.StringUtils; + import cgeo.geocaching.cgCache; /** @@ -9,7 +11,7 @@ import cgeo.geocaching.cgCache; public class OCConnector extends AbstractConnector implements IConnector { @Override public boolean canHandle(String geocode) { - return geocode != null && geocode.toUpperCase().startsWith("OC"); + return StringUtils.isNotBlank(geocode) && geocode.toUpperCase().startsWith("OC"); } @Override diff --git a/src/cgeo/geocaching/connector/OXConnector.java b/src/cgeo/geocaching/connector/OXConnector.java index 75d404e..dc78044 100644 --- a/src/cgeo/geocaching/connector/OXConnector.java +++ b/src/cgeo/geocaching/connector/OXConnector.java @@ -1,5 +1,7 @@ package cgeo.geocaching.connector; +import org.apache.commons.lang3.StringUtils; + import cgeo.geocaching.cgCache; /** @@ -10,7 +12,7 @@ public class OXConnector extends AbstractConnector implements IConnector { @Override public boolean canHandle(String geocode) { - return geocode != null && geocode.toUpperCase().startsWith("OX"); + return StringUtils.isNotBlank(geocode) && geocode.toUpperCase().startsWith("OX"); } @Override diff --git a/src/cgeo/geocaching/files/FileList.java b/src/cgeo/geocaching/files/FileList.java index eae1e4d..ceb17a7 100644 --- a/src/cgeo/geocaching/files/FileList.java +++ b/src/cgeo/geocaching/files/FileList.java @@ -3,6 +3,8 @@ package cgeo.geocaching.files; import java.io.File; import java.util.ArrayList; +import org.apache.commons.lang3.ArrayUtils; + import android.app.ProgressDialog; import android.content.DialogInterface; import android.os.Bundle; @@ -185,7 +187,7 @@ public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractLis final File[] files = directory.listFiles(); - if (files != null && files.length > 0) { + if (ArrayUtils.isNotEmpty(files)) { for (File file : files) { if (endSearching) { return; diff --git a/src/cgeo/geocaching/files/GPXParser.java b/src/cgeo/geocaching/files/GPXParser.java index e96c1d6..707bd1a 100644 --- a/src/cgeo/geocaching/files/GPXParser.java +++ b/src/cgeo/geocaching/files/GPXParser.java @@ -12,6 +12,7 @@ import java.util.Date; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.lang3.StringUtils; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -225,14 +226,14 @@ public abstract class GPXParser extends FileParser { @Override public void end() { - if (cache.geocode == null || cache.geocode.length() == 0) { + if (StringUtils.isBlank(cache.geocode)) { // try to find geocode somewhere else findGeoCode(name); findGeoCode(desc); findGeoCode(cmt); } - if (cache.geocode != null && cache.geocode.length() > 0 + if (StringUtils.isNotBlank(cache.geocode) && cache.latitude != null && cache.longitude != null && ((type == null && sym == null) || (type != null && type.indexOf("geocache") > -1) @@ -340,7 +341,7 @@ public abstract class GPXParser extends FileParser { final Matcher matcher = patternGuid.matcher(url); if (matcher.matches()) { String guid = matcher.group(1); - if (guid.length() > 0) { + if (StringUtils.isNotBlank(guid)) { cache.guid = guid; } } @@ -476,7 +477,7 @@ public abstract class GPXParser extends FileParser { @Override public void end(String country) { - if (cache.location == null || cache.location.length() == 0) { + if (StringUtils.isBlank(cache.location)) { cache.location = validate(country); } else { cache.location = cache.location + ", " + country.trim(); @@ -489,7 +490,7 @@ public abstract class GPXParser extends FileParser { @Override public void end(String state) { - if (cache.location == null || cache.location.length() == 0) { + if (StringUtils.isBlank(cache.location)) { cache.location = validate(state); } else { cache.location = state.trim() + ", " + cache.location; @@ -549,7 +550,7 @@ public abstract class GPXParser extends FileParser { @Override public void end() { - if (trackable.geocode != null && trackable.geocode.length() > 0 && trackable.name != null && trackable.name.length() > 0) { + if (StringUtils.isNotBlank(trackable.geocode) && StringUtils.isNotBlank(trackable.name)) { if (cache.inventory == null) { cache.inventory = new ArrayList<cgTrackable>(); } @@ -593,7 +594,7 @@ public abstract class GPXParser extends FileParser { @Override public void end() { - if (log.log != null && log.log.length() > 0) { + if (StringUtils.isNotBlank(log.log)) { if (cache.logs == null) { cache.logs = new ArrayList<cgLog>(); } @@ -697,14 +698,14 @@ public abstract class GPXParser extends FileParser { cache.type = knownType; } else { - if (cache.type == null || cache.type.length() == 0) { + if (StringUtils.isBlank(cache.type)) { cache.type = "mystery"; // default for not recognized types } } } private void findGeoCode(final String input) { - if (input == null || (cache.geocode != null && cache.geocode.length() != 0)) { + if (input == null || StringUtils.isNotBlank(cache.geocode)) { return; } final Matcher matcherGeocode = patternGeocode.matcher(input); diff --git a/src/cgeo/geocaching/files/LocParser.java b/src/cgeo/geocaching/files/LocParser.java index fd68fdc..e12e795 100644 --- a/src/cgeo/geocaching/files/LocParser.java +++ b/src/cgeo/geocaching/files/LocParser.java @@ -6,6 +6,8 @@ import java.util.Map.Entry; import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.lang3.StringUtils;
+
import android.os.Handler;
import android.util.Log;
import cgeo.geocaching.cgBase;
@@ -53,7 +55,7 @@ public final class LocParser extends FileParser { cache.terrain = coord.terrain;
cache.size = coord.size;
cache.geocode = coord.geocode.toUpperCase();
- if (cache.name == null || cache.name.length() == 0) {
+ if (StringUtils.isBlank(cache.name)) {
cache.name = coord.name;
}
}
@@ -61,7 +63,7 @@ public final class LocParser extends FileParser { private static HashMap<String, cgCoord> parseCoordinates(
final String fileContent) {
final HashMap<String, cgCoord> coords = new HashMap<String, cgCoord>();
- if (fileContent == null || fileContent.length() <= 0) {
+ if (StringUtils.isBlank(fileContent)) {
return coords;
}
// >> premium only
@@ -131,7 +133,7 @@ public final class LocParser extends FileParser { }
}
- if (pointCoord.geocode != null && pointCoord.geocode.length() > 0) {
+ if (StringUtils.isNotBlank(pointCoord.geocode)) {
coords.put(pointCoord.geocode, pointCoord);
}
}
@@ -151,7 +153,7 @@ public final class LocParser extends FileParser { final cgCacheWrap caches = new cgCacheWrap();
for (Entry<String, cgCoord> entry : coords.entrySet()) {
cgCoord coord = entry.getValue();
- if (coord.geocode == null || coord.geocode.length() == 0 || coord.name == null || coord.name.length() == 0) {
+ if (StringUtils.isBlank(coord.geocode) || StringUtils.isBlank(coord.name)) {
continue;
}
cgCache cache = new cgCache();
diff --git a/src/cgeo/geocaching/mapcommon/cgMapOverlay.java b/src/cgeo/geocaching/mapcommon/cgMapOverlay.java index d3f7c00..2b8406e 100644 --- a/src/cgeo/geocaching/mapcommon/cgMapOverlay.java +++ b/src/cgeo/geocaching/mapcommon/cgMapOverlay.java @@ -2,6 +2,8 @@ package cgeo.geocaching.mapcommon; import java.util.ArrayList; +import org.apache.commons.lang3.StringUtils; + import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.Context; @@ -10,9 +12,9 @@ import android.content.Intent; import android.graphics.Canvas; import android.graphics.DashPathEffect; import android.graphics.Paint; +import android.graphics.Paint.Style; import android.graphics.PaintFlagsDrawFilter; import android.graphics.Point; -import android.graphics.Paint.Style; import android.location.Location; import android.text.Html; import android.util.Log; @@ -199,7 +201,7 @@ public class cgMapOverlay extends ItemizedOverlayBase implements OverlayBase { cgCoord coordinate = item.getCoord(); - if (coordinate.type != null && coordinate.type.equalsIgnoreCase("cache") && coordinate.geocode != null && coordinate.geocode.length() > 0) { + if (coordinate.type != null && coordinate.type.equalsIgnoreCase("cache") && StringUtils.isNotBlank(coordinate.geocode)) { Intent popupIntent = new Intent(context, cgeopopup.class); popupIntent.putExtra("fromdetail", fromDetail); diff --git a/src/cgeo/geocaching/mapcommon/cgUsersOverlay.java b/src/cgeo/geocaching/mapcommon/cgUsersOverlay.java index f2ba50d..60439be 100644 --- a/src/cgeo/geocaching/mapcommon/cgUsersOverlay.java +++ b/src/cgeo/geocaching/mapcommon/cgUsersOverlay.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.lang3.StringUtils; + import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; @@ -109,7 +111,7 @@ public class cgUsersOverlay extends ItemizedOverlayBase implements OverlayBase { dialog.setTitle(user.username); dialog.setMessage(action); dialog.setCancelable(true); - if (geocode != null && geocode.length() > 0) { + if (StringUtils.isNotBlank(geocode)) { dialog.setPositiveButton(geocode + "?", new cacheDetails(geocode)); } dialog.setNeutralButton("Dismiss", new DialogInterface.OnClickListener() { diff --git a/src/cgeo/geocaching/mapcommon/cgeomap.java b/src/cgeo/geocaching/mapcommon/cgeomap.java index 22ea40b..7d7d51e 100644 --- a/src/cgeo/geocaching/mapcommon/cgeomap.java +++ b/src/cgeo/geocaching/mapcommon/cgeomap.java @@ -29,13 +29,13 @@ import cgeo.geocaching.cgCoord; import cgeo.geocaching.cgDirection; import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgSettings; +import cgeo.geocaching.cgSettings.mapSourceEnum; import cgeo.geocaching.cgUpdateDir; import cgeo.geocaching.cgUpdateLoc; import cgeo.geocaching.cgUser; import cgeo.geocaching.cgWaypoint; import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.activity.ActivityMixin; -import cgeo.geocaching.cgSettings.mapSourceEnum; import cgeo.geocaching.mapinterfaces.ActivityImpl; import cgeo.geocaching.mapinterfaces.CacheOverlayItemImpl; import cgeo.geocaching.mapinterfaces.GeoPointImpl; @@ -43,6 +43,7 @@ import cgeo.geocaching.mapinterfaces.MapControllerImpl; import cgeo.geocaching.mapinterfaces.MapFactory; import cgeo.geocaching.mapinterfaces.MapViewImpl; import cgeo.geocaching.mapinterfaces.UserOverlayItemImpl; +import cgeo.geocaching.utils.CollectionUtils; public class cgeomap extends MapBase { @@ -505,7 +506,7 @@ public class cgeomap extends MapBase { } item = menu.findItem(MENU_STORE_CACHES); // store loaded - if (live && !isLoading() && app.getNotOfflineCount(searchId) > 0 && caches != null && caches.size() > 0) { + if (live && !isLoading() && app.getNotOfflineCount(searchId) > 0 && CollectionUtils.isNotEmpty(caches)) { item.setEnabled(true); } else { item.setEnabled(false); @@ -562,7 +563,7 @@ public class cgeomap extends MapBase { ArrayList<cgCache> cachesProtected = new ArrayList<cgCache>(caches); try { - if (cachesProtected.size() > 0) { + if (CollectionUtils.isNotEmpty(cachesProtected)) { final GeoPointImpl mapCenter = mapView.getMapViewCenter(); final int mapCenterLat = mapCenter.getLatitudeE6(); final int mapCenterLon = mapCenter.getLongitudeE6(); diff --git a/src/cgeo/geocaching/sorting/GeocodeComparator.java b/src/cgeo/geocaching/sorting/GeocodeComparator.java index dd16f08..957545b 100644 --- a/src/cgeo/geocaching/sorting/GeocodeComparator.java +++ b/src/cgeo/geocaching/sorting/GeocodeComparator.java @@ -1,5 +1,7 @@ package cgeo.geocaching.sorting; +import org.apache.commons.lang3.StringUtils; + import cgeo.geocaching.cgCache; /** @@ -10,8 +12,8 @@ public class GeocodeComparator extends AbstractCacheComparator { @Override protected boolean canCompare(cgCache cache1, cgCache cache2) { - return cache1.geocode != null && cache1.geocode.length() > 0 - && cache2.geocode != null && cache2.geocode.length() > 0; + return StringUtils.isNotBlank(cache1.geocode) + && StringUtils.isNotBlank(cache2.geocode); } @Override diff --git a/src/cgeo/geocaching/sorting/NameComparator.java b/src/cgeo/geocaching/sorting/NameComparator.java index f1c5ae3..9f72258 100644 --- a/src/cgeo/geocaching/sorting/NameComparator.java +++ b/src/cgeo/geocaching/sorting/NameComparator.java @@ -1,5 +1,7 @@ package cgeo.geocaching.sorting; +import org.apache.commons.lang3.StringUtils; + import cgeo.geocaching.cgCache; /** @@ -10,7 +12,7 @@ public class NameComparator extends AbstractCacheComparator { @Override protected boolean canCompare(cgCache cache1, cgCache cache2) { - return cache1.name != null && cache2.name != null; + return StringUtils.isNotBlank(cache1.name) && StringUtils.isNotBlank(cache2.name); } @Override diff --git a/src/cgeo/geocaching/sorting/SizeComparator.java b/src/cgeo/geocaching/sorting/SizeComparator.java index dd9d448..cff5c49 100644 --- a/src/cgeo/geocaching/sorting/SizeComparator.java +++ b/src/cgeo/geocaching/sorting/SizeComparator.java @@ -1,5 +1,7 @@ package cgeo.geocaching.sorting; +import org.apache.commons.lang3.StringUtils; + import cgeo.geocaching.cgCache; /** @@ -10,7 +12,7 @@ public class SizeComparator extends AbstractCacheComparator { @Override protected boolean canCompare(cgCache cache1, cgCache cache2) { - return cache1.size != null && cache1.size.length() > 0 && cache2.size != null && cache2.size.length() > 0; + return StringUtils.isNotBlank(cache1.size) && StringUtils.isNotBlank(cache2.size); } @Override diff --git a/src/cgeo/geocaching/utils/CollectionUtils.java b/src/cgeo/geocaching/utils/CollectionUtils.java new file mode 100644 index 0000000..89b4b51 --- /dev/null +++ b/src/cgeo/geocaching/utils/CollectionUtils.java @@ -0,0 +1,25 @@ +package cgeo.geocaching.utils;
+
+import java.util.List;
+import java.util.Map;
+
+public class CollectionUtils {
+
+ public static <T> boolean isEmpty(List<T> list) {
+ return (list != null && list.size() == 0);
+ }
+ public static <T,T2> boolean isEmpty(Map<T,T2> map) {
+ return (map != null && map.size() == 0);
+ }
+
+
+ public static <T> boolean isNotEmpty(List<T> list) {
+ return (list != null && list.size() != 0);
+ }
+
+ public static <T,T2> boolean isNotEmpty(Map<T,T2> map) {
+ return (map != null && map.size() != 0);
+ }
+
+
+}
|
