aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo/geocaching/files
diff options
context:
space:
mode:
authorGerald Barker <geraldbarker@gmail.com>2011-09-02 23:19:51 +0100
committerGerald Barker <geraldbarker@gmail.com>2011-09-02 23:19:51 +0100
commit53936c7ee6654a525075b03e1b4c8ddbfbcd4ef5 (patch)
tree41154be6daecad1b4483223d72920e0a290024ef /src/cgeo/geocaching/files
parentafbe8c5164e1157e38e0f8c4b28942cbd9fe3d41 (diff)
downloadcgeo-53936c7ee6654a525075b03e1b4c8ddbfbcd4ef5.zip
cgeo-53936c7ee6654a525075b03e1b4c8ddbfbcd4ef5.tar.gz
cgeo-53936c7ee6654a525075b03e1b4c8ddbfbcd4ef5.tar.bz2
First commit of Apache Commons String & Date functions and required, and
refactor of code to use them.
Diffstat (limited to 'src/cgeo/geocaching/files')
-rw-r--r--src/cgeo/geocaching/files/FileList.java4
-rw-r--r--src/cgeo/geocaching/files/GPXParser.java19
-rw-r--r--src/cgeo/geocaching/files/LocParser.java10
3 files changed, 19 insertions, 14 deletions
diff --git a/src/cgeo/geocaching/files/FileList.java b/src/cgeo/geocaching/files/FileList.java
index 67e89a0..be808a3 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 2a3b167..881f186 100644
--- a/src/cgeo/geocaching/files/GPXParser.java
+++ b/src/cgeo/geocaching/files/GPXParser.java
@@ -11,6 +11,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;
@@ -112,14 +113,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)
@@ -318,7 +319,7 @@ public abstract class GPXParser extends FileParser {
@Override
public void end(String body) {
- if (cache.location == null || cache.location.length() == 0) {
+ if (StringUtils.isBlank(cache.location)) {
cache.location = validate(body.trim());
} else {
cache.location = cache.location + ", " + body.trim();
@@ -331,7 +332,7 @@ public abstract class GPXParser extends FileParser {
@Override
public void end(String body) {
- if (cache.location == null || cache.location.length() == 0) {
+ if (StringUtils.isBlank(cache.location)) {
cache.location = validate(body.trim());
} else {
cache.location = body.trim() + ", " + cache.location;
@@ -434,7 +435,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>();
}
@@ -478,7 +479,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>();
}
@@ -572,14 +573,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;
}
Matcher matcherGeocode = patternGeocode.matcher(input);
@@ -612,4 +613,4 @@ public abstract class GPXParser extends FileParser {
return search.getCurrentId();
}
-}
+} \ No newline at end of file
diff --git a/src/cgeo/geocaching/files/LocParser.java b/src/cgeo/geocaching/files/LocParser.java
index 152293c..da21ed2 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();