aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2012-07-01 17:54:52 +0200
committerBananeweizen <bananeweizen@gmx.de>2012-07-01 17:54:52 +0200
commite86317306d5b013d8d2b0efc4ea35fe11b6758ae (patch)
tree60769a9c6bc4261d72f05d8f15c6548027f57a4d /main
parent34c178f55678d7c8042a460ecd632d52c300cc94 (diff)
downloadcgeo-e86317306d5b013d8d2b0efc4ea35fe11b6758ae.zip
cgeo-e86317306d5b013d8d2b0efc4ea35fe11b6758ae.tar.gz
cgeo-e86317306d5b013d8d2b0efc4ea35fe11b6758ae.tar.bz2
refactoring: some findbugs cleanup
Diffstat (limited to 'main')
-rw-r--r--main/src/cgeo/geocaching/maps/MapProviderFactory.java45
1 files changed, 14 insertions, 31 deletions
diff --git a/main/src/cgeo/geocaching/maps/MapProviderFactory.java b/main/src/cgeo/geocaching/maps/MapProviderFactory.java
index 3fb6ed0..7c0c8e5 100644
--- a/main/src/cgeo/geocaching/maps/MapProviderFactory.java
+++ b/main/src/cgeo/geocaching/maps/MapProviderFactory.java
@@ -15,12 +15,10 @@ public class MapProviderFactory {
private final static int GOOGLEMAP_BASEID = 30;
private final static int MFMAP_BASEID = 40;
- private static MapProviderFactory instance = null;
+ private final static MapProvider[] mapProviders;
+ private final static SortedMap<Integer, MapSource> mapSources;
- private final MapProvider[] mapProviders;
- private SortedMap<Integer, MapSource> mapSources;
-
- private MapProviderFactory() {
+ static {
// add GoogleMapProvider only if google api is available in order to support x86 android emulator
if (isGoogleMapsInstalled()) {
mapProviders = new MapProvider[] { new GoogleMapProvider(GOOGLEMAP_BASEID), new MapsforgeMapProvider(MFMAP_BASEID) };
@@ -45,29 +43,16 @@ public class MapProviderFactory {
return googleMaps;
}
- private static synchronized void initInstance() {
- if (null == instance) {
- instance = new MapProviderFactory();
- }
- }
-
- private static MapProviderFactory getInstance() {
- if (null == instance) {
- initInstance();
- }
- return instance;
- }
-
public static SortedMap<Integer, MapSource> getMapSources() {
- return getInstance().mapSources;
+ return mapSources;
}
public static boolean isValidSourceId(int sourceId) {
- return getInstance().mapSources.containsKey(sourceId);
+ return mapSources.containsKey(sourceId);
}
public static boolean isSameActivity(int sourceId1, int sourceId2) {
- for (MapProvider mp : getInstance().mapProviders) {
+ for (MapProvider mp : mapProviders) {
if (mp.isMySource(sourceId1) && mp.isMySource(sourceId2)) {
return mp.isSameActivity(sourceId1, sourceId2);
}
@@ -76,17 +61,17 @@ public class MapProviderFactory {
}
public static MapProvider getMapProvider(int sourceId) {
- for (MapProvider mp : getInstance().mapProviders) {
+ for (MapProvider mp : mapProviders) {
if (mp.isMySource(sourceId)) {
return mp;
}
}
- return getInstance().mapProviders[0];
+ return mapProviders[0];
}
public static int getSourceOrdinalFromId(int sourceId) {
int sourceOrdinal = 0;
- for (int key : getInstance().mapSources.keySet()) {
+ for (int key : mapSources.keySet()) {
if (sourceId == key) {
return sourceOrdinal;
}
@@ -97,20 +82,18 @@ public class MapProviderFactory {
public static int getSourceIdFromOrdinal(int sourceOrdinal) {
int count = 0;
- for (int key : getInstance().mapSources.keySet()) {
+ for (int key : mapSources.keySet()) {
if (sourceOrdinal == count) {
return key;
}
count++;
}
- return getInstance().mapSources.firstKey();
+ return mapSources.firstKey();
}
public static void addMapviewMenuItems(Menu parentMenu, int groupId, int currentSource) {
- SortedMap<Integer, MapSource> mapSources = getInstance().mapSources;
-
- for (int key : mapSources.keySet()) {
- parentMenu.add(groupId, key, 0, mapSources.get(key).getName()).setCheckable(true).setChecked(key == currentSource);
+ for (Integer key : mapSources.keySet()) {
+ parentMenu.add(groupId, key, 0, mapSources.get(key).getName()).setCheckable(true).setChecked(key.intValue() == currentSource);
}
}
@@ -119,6 +102,6 @@ public class MapProviderFactory {
}
public static MapSource getMapSource(int sourceId) {
- return getInstance().mapSources.get(sourceId);
+ return mapSources.get(Integer.valueOf(sourceId));
}
}