From cb94f1f020596be019cc4c000a93a318600d7f37 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sat, 29 Dec 2012 19:16:31 +0100 Subject: refactoring: findbugs --- main/src/cgeo/geocaching/StaticMapsProvider.java | 28 +++++++++++----------- main/src/cgeo/geocaching/TrackableActivity.java | 2 +- main/src/cgeo/geocaching/VisitCacheActivity.java | 18 +++++++------- main/src/cgeo/geocaching/files/FileList.java | 12 +++------- .../cgeo/geocaching/connector/gc/GCParserTest.java | 2 +- .../cgeo/geocaching/test/RegExPerformanceTest.java | 6 ++++- 6 files changed, 33 insertions(+), 35 deletions(-) diff --git a/main/src/cgeo/geocaching/StaticMapsProvider.java b/main/src/cgeo/geocaching/StaticMapsProvider.java index 49dfb0f..132619a 100644 --- a/main/src/cgeo/geocaching/StaticMapsProvider.java +++ b/main/src/cgeo/geocaching/StaticMapsProvider.java @@ -62,21 +62,21 @@ public class StaticMapsProvider { } final HttpResponse httpResponse = Network.getRequest(GOOGLE_STATICMAP_URL, params); - if (httpResponse != null) { - if (httpResponse.getStatusLine().getStatusCode() == 200) { - final File file = getMapFile(geocode, prefix, true); - if (LocalStorage.saveEntityToFile(httpResponse, file)) { - // Delete image if it has no contents - final long fileSize = file.length(); - if (fileSize < MIN_MAP_IMAGE_BYTES) { - file.delete(); - } - } - } else { - Log.d("StaticMapsProvider.downloadMap: httpResponseCode = " + httpResponse.getStatusLine().getStatusCode()); - } - } else { + if (httpResponse == null) { Log.e("StaticMapsProvider.downloadMap: httpResponse is null"); + return; + } + if (httpResponse.getStatusLine().getStatusCode() != 200) { + Log.d("StaticMapsProvider.downloadMap: httpResponseCode = " + httpResponse.getStatusLine().getStatusCode()); + return; + } + final File file = getMapFile(geocode, prefix, true); + if (LocalStorage.saveEntityToFile(httpResponse, file)) { + // Delete image if it has no contents + final long fileSize = file.length(); + if (fileSize < MIN_MAP_IMAGE_BYTES) { + file.delete(); + } } } diff --git a/main/src/cgeo/geocaching/TrackableActivity.java b/main/src/cgeo/geocaching/TrackableActivity.java index 8b300be..d5b4f9f 100644 --- a/main/src/cgeo/geocaching/TrackableActivity.java +++ b/main/src/cgeo/geocaching/TrackableActivity.java @@ -50,7 +50,7 @@ public class TrackableActivity extends AbstractViewPagerActivity trackables; private final int attempts; @@ -735,13 +735,13 @@ public class VisitCacheActivity extends AbstractLoggingActivity implements DateD private final LogType typeSelected; private final double rating; - public ActivityState() { - this.viewstates = VisitCacheActivity.this.viewstates; - this.trackables = VisitCacheActivity.this.trackables; - this.attempts = VisitCacheActivity.this.attempts; - this.possibleLogTypes = VisitCacheActivity.this.possibleLogTypes; - this.typeSelected = VisitCacheActivity.this.typeSelected; - this.rating = VisitCacheActivity.this.rating; + public ActivityState(VisitCacheActivity activity) { + this.viewstates = activity.viewstates; + this.trackables = activity.trackables; + this.attempts = activity.attempts; + this.possibleLogTypes = activity.possibleLogTypes; + this.typeSelected = activity.typeSelected; + this.rating = activity.rating; } public void restore(final VisitCacheActivity activity) { @@ -756,7 +756,7 @@ public class VisitCacheActivity extends AbstractLoggingActivity implements DateD @Override public Object onRetainNonConfigurationInstance() { - return new ActivityState(); + return new ActivityState(this); } @Override diff --git a/main/src/cgeo/geocaching/files/FileList.java b/main/src/cgeo/geocaching/files/FileList.java index 19d3305..990d2ae 100644 --- a/main/src/cgeo/geocaching/files/FileList.java +++ b/main/src/cgeo/geocaching/files/FileList.java @@ -8,6 +8,7 @@ import cgeo.geocaching.utils.Log; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.mapsforge.core.IOUtils; import android.app.ProgressDialog; import android.content.DialogInterface; @@ -242,15 +243,8 @@ public abstract class FileList> extends AbstractLis Log.e("Could not get additional mount points for user content. " + "Proceeding with external storage only (" + extStorage + ")"); } finally { - try { - if (fr != null) { - fr.close(); - } - if (br != null) { - br.close(); - } - } catch (IOException e) { - } + IOUtils.closeQuietly(fr); + IOUtils.closeQuietly(br); } } return storages; diff --git a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java index dd71302..0f1f4cf 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java @@ -72,7 +72,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase { } private static cgCache createCache(int index) { - final MockedCache mockedCache = RegExPerformanceTest.MOCKED_CACHES[index]; + final MockedCache mockedCache = RegExPerformanceTest.MOCKED_CACHES.get(index); // to get the same results we have to use the date format used when the mocked data was created String oldCustomDate = Settings.getGcCustomDate(); diff --git a/tests/src/cgeo/geocaching/test/RegExPerformanceTest.java b/tests/src/cgeo/geocaching/test/RegExPerformanceTest.java index 5e46445..bd30532 100644 --- a/tests/src/cgeo/geocaching/test/RegExPerformanceTest.java +++ b/tests/src/cgeo/geocaching/test/RegExPerformanceTest.java @@ -8,6 +8,7 @@ import cgeo.geocaching.test.mock.MockedCache; import cgeo.geocaching.utils.BaseUtils; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.regex.Pattern; @@ -69,7 +70,10 @@ public class RegExPerformanceTest extends TestCase { public final static Pattern PATTERN_DESCRIPTION = Pattern.compile("(.*?)[^<]*[^<]*

[^<]*

[^<]*

[^<]*\\W*Additional Hints"); - public final static MockedCache[] MOCKED_CACHES = { new GC2CJPF(), new GC1ZXX2(), new GC2JVEH(), new GC3XX5J() }; + public final static List MOCKED_CACHES; + static { + MOCKED_CACHES = Arrays.asList(new GC2CJPF(), new GC1ZXX2(), new GC2JVEH(), new GC3XX5J()); + } public static void testRegEx() { List output = doTheTests(10); -- cgit v1.1