Make MapWithAILayerInfo.instance private

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2020-06-24 13:50:39 -06:00
rodzic 1fa9bc076a
commit 35768d1997
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
9 zmienionych plików z 42 dodań i 34 usunięć

Wyświetl plik

@ -247,7 +247,7 @@ public class DataAvailability {
* @return List of terms of use urls
*/
public static final List<String> getTermsOfUse() {
return Stream.concat(MapWithAILayerInfo.instance.getLayers().stream().map(MapWithAIInfo::getTermsOfUseURL),
return Stream.concat(MapWithAILayerInfo.getInstance().getLayers().stream().map(MapWithAIInfo::getTermsOfUseURL),
DATA_SOURCES.stream().map(clazz -> {
try {
return clazz.getConstructor().newInstance().getTermsOfUseUrl();
@ -266,16 +266,18 @@ public class DataAvailability {
* @return List of privacy policy urls
*/
public static final List<String> getPrivacyPolicy() {
return Stream.concat(MapWithAILayerInfo.instance.getLayers().stream().map(MapWithAIInfo::getPrivacyPolicyURL),
DATA_SOURCES.stream().map(clazz -> {
try {
return clazz.getConstructor().newInstance().getPrivacyPolicyUrl();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
Logging.debug(e);
}
return EMPTY_STRING;
})).filter(Objects::nonNull).filter(str -> !Utils.removeWhiteSpaces(str).isEmpty()).distinct()
return Stream
.concat(MapWithAILayerInfo.getInstance().getLayers().stream().map(MapWithAIInfo::getPrivacyPolicyURL),
DATA_SOURCES.stream().map(clazz -> {
try {
return clazz.getConstructor().newInstance().getPrivacyPolicyUrl();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
Logging.debug(e);
}
return EMPTY_STRING;
}))
.filter(Objects::nonNull).filter(str -> !Utils.removeWhiteSpaces(str).isEmpty()).distinct()
.collect(Collectors.toList());
}

Wyświetl plik

@ -511,7 +511,7 @@ public class GetDataRunnable extends RecursiveTask<DataSet> {
final DataSet dataSet = new DataSet();
dataSet.setUploadPolicy(UploadPolicy.DISCOURAGED);
new ArrayList<>(MapWithAILayerInfo.instance.getLayers()).parallelStream().forEach(map -> {
new ArrayList<>(MapWithAILayerInfo.getInstance().getLayers()).parallelStream().forEach(map -> {
try {
Bounds bound = new Bounds(bbox.getBottomRight());
bound.extend(bbox.getTopLeft());

Wyświetl plik

@ -194,7 +194,7 @@ public final class MapWithAIDataUtils {
final List<Bounds> realBounds = realBBoxes.stream()
.flatMap(tBBox -> MapWithAIDataUtils.reduceBBoxSize(tBBox, maximumDimensions).stream())
.map(MapWithAIDataUtils::bboxToBounds).collect(Collectors.toList());
if (!MapWithAILayerInfo.instance.getLayers().isEmpty()) {
if (!MapWithAILayerInfo.getInstance().getLayers().isEmpty()) {
if ((realBBoxes.size() < TOO_MANY_BBOXES) || confirmBigDownload(realBBoxes)) {
final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor();
monitor.beginTask(tr("Downloading {0} Data", MapWithAIPlugin.NAME), realBounds.size());
@ -228,8 +228,8 @@ public final class MapWithAIDataUtils {
noUrls.setHelpTopic(ht("Plugin/MapWithAI#Preferences"));
GuiHelper.runInEDT(noUrls::show);
if (MapWithAIPreferenceHelper.getMapWithAIUrl().isEmpty()
&& MapWithAILayerInfo.instance.getDefaultLayers().isEmpty()) {
MapWithAILayerInfo.instance.loadDefaults(true, MainApplication.worker, false,
&& MapWithAILayerInfo.getInstance().getDefaultLayers().isEmpty()) {
MapWithAILayerInfo.getInstance().loadDefaults(true, MainApplication.worker, false,
() -> Logging.info("MapWithAI Sources: Initialized sources"));
}
}

Wyświetl plik

@ -41,7 +41,7 @@ public final class MapWithAIPreferenceHelper {
public static List<MapWithAIInfo> getMapWithAIUrl() {
return MapWithAIDataUtils.getLayer(false) == null
|| MapWithAIDataUtils.getLayer(false).getMapWithAIUrl() == null
? MapWithAILayerInfo.instance.getLayers()
? MapWithAILayerInfo.getInstance().getLayers()
: Collections.singletonList(MapWithAIDataUtils.getLayer(false).getMapWithAIUrl());
}
@ -92,8 +92,8 @@ public final class MapWithAIPreferenceHelper {
*/
public static void setMapWithAIUrl(MapWithAIInfo info, boolean enabled, boolean permanent) {
if (permanent && enabled) {
MapWithAILayerInfo.instance.add(info);
MapWithAILayerInfo.instance.save();
MapWithAILayerInfo.getInstance().add(info);
MapWithAILayerInfo.getInstance().save();
} else if (enabled && MapWithAIDataUtils.getLayer(false) != null) {
MapWithAIDataUtils.getLayer(false).setMapWithAIUrl(info);
}

Wyświetl plik

@ -57,9 +57,14 @@ public class MapWithAILayerInfo {
"https://gitlab.com/gokaart/JOSM_MapWithAI/-/raw/pages/public/json/sources.json" };
/** Unique instance -- MUST be after DEFAULT_LAYER_SITES */
public static final MapWithAILayerInfo instance = new MapWithAILayerInfo();
private static MapWithAILayerInfo instance;
public static MapWithAILayerInfo getInstance() {
synchronized (DEFAULT_LAYER_SITES) {
if (instance == null) {
instance = new MapWithAILayerInfo();
}
}
return instance;
}

Wyświetl plik

@ -32,7 +32,7 @@ public class DownloadMapWithAITaskTest {
DownloadMapWithAITask task = new DownloadMapWithAITask();
Future<?> future = task.download(
new BoundingBoxMapWithAIDownloader(MapWithAIDataUtilsTest.getTestBounds(),
MapWithAILayerInfo.instance.getLayers().get(0), false),
MapWithAILayerInfo.getInstance().getLayers().get(0), false),
new DownloadParams(), MapWithAIDataUtilsTest.getTestBounds(), NullProgressMonitor.INSTANCE);
future.get();
assertNotNull(task.getDownloadedData(), "Data should be downloaded");

Wyświetl plik

@ -69,13 +69,14 @@ public class MapWithAIAvailabilityTest {
@Test
public void testNoURLs() {
new ArrayList<>(MapWithAILayerInfo.instance.getLayers()).forEach(i -> MapWithAILayerInfo.instance.remove(i));
new ArrayList<>(MapWithAILayerInfo.getInstance().getLayers())
.forEach(i -> MapWithAILayerInfo.getInstance().remove(i));
DataAvailability.getInstance();
testgetDataLatLon();
MapWithAILayerInfo.instance.getLayers().forEach(i -> MapWithAILayerInfo.instance.remove(i));
MapWithAILayerInfo.getInstance().getLayers().forEach(i -> MapWithAILayerInfo.getInstance().remove(i));
DataAvailability.getInstance();
testHasDataLatLon();
MapWithAILayerInfo.instance.getLayers().forEach(i -> MapWithAILayerInfo.instance.remove(i));
MapWithAILayerInfo.getInstance().getLayers().forEach(i -> MapWithAILayerInfo.getInstance().remove(i));
DataAvailability.getInstance();
testHasDataBBox();
}

Wyświetl plik

@ -67,8 +67,8 @@ public class MapWithAIRemoteControlTest {
*/
@Test
public void testNominalRequest() throws Exception {
newHandler("https://localhost?url=" + Utils.encodeUrl(MapWithAILayerInfo.instance.getLayers().get(0).getUrl()))
.handle();
newHandler("https://localhost?url="
+ Utils.encodeUrl(MapWithAILayerInfo.getInstance().getLayers().get(0).getUrl())).handle();
Awaitility.await().atMost(Durations.ONE_SECOND)
.until(() -> !MainApplication.getLayerManager().getLayersOfType(MapWithAILayer.class).isEmpty());

Wyświetl plik

@ -70,9 +70,6 @@ public class MapWithAITestRules extends JOSMTestRules {
super.before();
Logging.getLogger().setFilter(record -> record.getLevel().intValue() >= Level.WARNING.intValue()
|| record.getSourceClassName().startsWith("org.openstreetmap.josm.plugins.mapwithai"));
if (sources) {
MapWithAILayerInfo.instance.load(false);
}
if (wiremock) {
wireMock = new WireMockServer(options().usingFilesUnderDirectory("test/resources/wiremock"));
wireMock.start();
@ -89,6 +86,9 @@ public class MapWithAITestRules extends JOSMTestRules {
Logging.error(e);
}
}
if (sources) {
MapWithAILayerInfo.getInstance().load(false);
}
if (workerExceptions) {
currentExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
@ -119,18 +119,18 @@ public class MapWithAITestRules extends JOSMTestRules {
private static void setupMapWithAILayerInfo(WireMockServer wireMockServer) {
synchronized (MapWithAITestRules.class) {
resetMapWithAILayerInfo();
MapWithAILayerInfo.instance.getLayers().stream().forEach(
MapWithAILayerInfo.getInstance().getLayers().stream().forEach(
i -> i.setUrl(GetDataRunnableTest.getDefaultMapWithAIAPIForTest(wireMockServer, i.getUrl())));
MapWithAILayerInfo.instance.save();
MapWithAILayerInfo.getInstance().save();
}
}
private static void resetMapWithAILayerInfo() {
synchronized (MapWithAILayerInfo.class) {
MapWithAILayerInfo.instance.clear();
MapWithAILayerInfo.instance.getDefaultLayers().stream().filter(MapWithAIInfo::isDefaultEntry)
.forEach(MapWithAILayerInfo.instance::add);
MapWithAILayerInfo.instance.save();
MapWithAILayerInfo.getInstance().clear();
MapWithAILayerInfo.getInstance().getDefaultLayers().stream().filter(MapWithAIInfo::isDefaultEntry)
.forEach(MapWithAILayerInfo.getInstance()::add);
MapWithAILayerInfo.getInstance().save();
}
}