aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/connector/ConnectorFactory.java
diff options
context:
space:
mode:
authorMichael Keppler <bananeweizen@gmx.de>2013-12-25 21:33:20 +0100
committerMichael Keppler <bananeweizen@gmx.de>2013-12-25 21:33:20 +0100
commit62f7a80ad800a8c650e8c3547248fa5453080004 (patch)
treed5d8ab3dddee764797beb317459cd289aa402443 /main/src/cgeo/geocaching/connector/ConnectorFactory.java
parent8767705910606ef4a82a0dbd62be3a09ba5615ac (diff)
downloadcgeo-62f7a80ad800a8c650e8c3547248fa5453080004.zip
cgeo-62f7a80ad800a8c650e8c3547248fa5453080004.tar.gz
cgeo-62f7a80ad800a8c650e8c3547248fa5453080004.tar.bz2
findbugs: prohibit access to internal collections
Diffstat (limited to 'main/src/cgeo/geocaching/connector/ConnectorFactory.java')
-rw-r--r--main/src/cgeo/geocaching/connector/ConnectorFactory.java31
1 files changed, 16 insertions, 15 deletions
diff --git a/main/src/cgeo/geocaching/connector/ConnectorFactory.java b/main/src/cgeo/geocaching/connector/ConnectorFactory.java
index fba48c7..3df98e0 100644
--- a/main/src/cgeo/geocaching/connector/ConnectorFactory.java
+++ b/main/src/cgeo/geocaching/connector/ConnectorFactory.java
@@ -25,13 +25,15 @@ import cgeo.geocaching.geopoint.Viewport;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNull;
-import java.lang.reflect.Array;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
import java.util.List;
public final class ConnectorFactory {
private static final UnknownConnector UNKNOWN_CONNECTOR = new UnknownConnector();
- private static final IConnector[] CONNECTORS = new IConnector[] {
+ private static final Collection<IConnector> CONNECTORS = Collections.unmodifiableCollection(Arrays.asList(new IConnector[] {
GCConnector.getInstance(),
ECConnector.getInstance(),
new OCApiLiveConnector("opencaching.de", "www.opencaching.de", "OC", "CC BY-NC-ND, alle Logeinträge © jeweiliger Autor",
@@ -53,42 +55,41 @@ public final class ConnectorFactory {
new GeopeitusConnector(),
new WaymarkingConnector(),
UNKNOWN_CONNECTOR // the unknown connector MUST be the last one
- };
+ }));
@NonNull public static final UnknownTrackableConnector UNKNOWN_TRACKABLE_CONNECTOR = new UnknownTrackableConnector();
- private static final TrackableConnector[] TRACKABLE_CONNECTORS = new TrackableConnector[] {
+ private static final Collection<TrackableConnector> TRACKABLE_CONNECTORS = Collections.unmodifiableCollection(Arrays.asList(new TrackableConnector[] {
new GeokretyConnector(), // GK must be first, as it overlaps with the secret codes of travel bugs
TravelBugConnector.getInstance(),
UNKNOWN_TRACKABLE_CONNECTOR // must be last
- };
+ }));
- private static final ISearchByViewPort[] searchByViewPortConns = getMatchingConnectors(ISearchByViewPort.class);
+ private static final Collection<ISearchByViewPort> searchByViewPortConns = getMatchingConnectors(ISearchByViewPort.class);
- private static final ISearchByCenter[] searchByCenterConns = getMatchingConnectors(ISearchByCenter.class);
+ private static final Collection<ISearchByCenter> searchByCenterConns = getMatchingConnectors(ISearchByCenter.class);
- private static final ISearchByKeyword[] searchByKeywordConns = getMatchingConnectors(ISearchByKeyword.class);
+ private static final Collection<ISearchByKeyword> searchByKeywordConns = getMatchingConnectors(ISearchByKeyword.class);
@SuppressWarnings("unchecked")
- private static <T extends IConnector> T[] getMatchingConnectors(final Class<T> clazz) {
+ private static <T extends IConnector> Collection<T> getMatchingConnectors(final Class<T> clazz) {
final List<T> matching = new ArrayList<T>();
for (final IConnector connector : CONNECTORS) {
if (clazz.isInstance(connector)) {
matching.add((T) connector);
}
}
- T[] result = (T[]) Array.newInstance(clazz, matching.size());
- return matching.toArray(result);
+ return Collections.unmodifiableCollection(matching);
}
- public static IConnector[] getConnectors() {
+ public static Collection<IConnector> getConnectors() {
return CONNECTORS;
}
- public static ISearchByCenter[] getSearchByCenterConnectors() {
+ public static Collection<ISearchByCenter> getSearchByCenterConnectors() {
return searchByCenterConns;
}
- public static ISearchByKeyword[] getSearchByKeywordConnectors() {
+ public static Collection<ISearchByKeyword> getSearchByKeywordConnectors() {
return searchByKeywordConns;
}
@@ -175,7 +176,7 @@ public final class ConnectorFactory {
return null;
}
- public static TrackableConnector[] getTrackableConnectors() {
+ public static Collection<TrackableConnector> getTrackableConnectors() {
return TRACKABLE_CONNECTORS;
}