kopia lustrzana https://github.com/JOSM/MapWithAI
Remove unnecessary code and modify tests
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
608df6c7f1
commit
71eb63c135
|
@ -14,7 +14,6 @@ import java.util.TreeMap;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonException;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonValue;
|
||||
|
@ -131,10 +130,10 @@ public class DataAvailability {
|
|||
*/
|
||||
private static void parseCountries(Map<String, Map<String, Boolean>> countriesMap, JsonValue countries,
|
||||
JsonValue information) {
|
||||
if (JsonValue.ValueType.ARRAY.equals(countries.getValueType())) {
|
||||
parseCountriesArray(countriesMap, countries.asJsonArray(), information);
|
||||
} else if (JsonValue.ValueType.OBJECT.equals(countries.getValueType())) {
|
||||
if (JsonValue.ValueType.OBJECT.equals(countries.getValueType())) {
|
||||
parseCountriesObject(countriesMap, countries.asJsonObject(), information);
|
||||
} else {
|
||||
Logging.error("MapWithAI: Check format of countries map from MapWithAI");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,33 +168,6 @@ public class DataAvailability {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a JsonArray for countries
|
||||
*
|
||||
* @param countriesMap The countries map (will be modified)
|
||||
* @param countryArray The country array (JsonArray)
|
||||
* @param information The information for the source
|
||||
*/
|
||||
private static void parseCountriesArray(Map<String, Map<String, Boolean>> countriesMap, JsonArray countryArray,
|
||||
JsonValue information) {
|
||||
List<String> array = countryArray.parallelStream()
|
||||
.filter(c -> JsonValue.ValueType.STRING.equals(c.getValueType())).map(JsonValue::toString)
|
||||
.map(DataAvailability::stripQuotes).collect(Collectors.toList());
|
||||
if (JsonValue.ValueType.OBJECT.equals(information.getValueType())
|
||||
&& information.asJsonObject().containsKey(PROVIDES)) {
|
||||
List<String> provides = information.asJsonObject().getJsonArray(PROVIDES).parallelStream()
|
||||
.filter(p -> JsonValue.ValueType.STRING.equals(p.getValueType())).map(JsonValue::toString)
|
||||
.map(DataAvailability::stripQuotes).collect(Collectors.toList());
|
||||
for (String countryValue : array) {
|
||||
for (String provide : provides) {
|
||||
Map<String, Boolean> providesMap = countriesMap.getOrDefault(countryValue, new TreeMap<>());
|
||||
countriesMap.putIfAbsent(countryValue, providesMap);
|
||||
providesMap.put(provide, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip double quotes (") from a string
|
||||
*
|
||||
|
|
|
@ -78,27 +78,6 @@ public final class MapWithAIPreferenceHelper {
|
|||
returnMap.add(layerMap);
|
||||
}
|
||||
}
|
||||
if (returnMap.isEmpty()) {
|
||||
final List<String> defaultAPIs = Collections.singletonList(DEFAULT_MAPWITHAI_API);
|
||||
final List<String> defaultList = Config.getPref().getList(API_CONFIG).isEmpty() ? defaultAPIs
|
||||
: Config.getPref().getList(API_CONFIG);
|
||||
returnMap.addAll(defaultList.stream().map(string -> {
|
||||
final TreeMap<String, String> map = new TreeMap<>();
|
||||
map.put(URL_STRING, string);
|
||||
return map;
|
||||
}).collect(Collectors.toList()));
|
||||
}
|
||||
returnMap.parallelStream().forEach(map -> {
|
||||
final String url = map.get(URL_STRING);
|
||||
if (DEFAULT_MAPWITHAI_API.equals(url)) {
|
||||
map.putIfAbsent(SOURCE_STRING, MapWithAIPlugin.NAME);
|
||||
map.putIfAbsent(ENABLED_STRING, "true");
|
||||
map.putIfAbsent(PARAMETERS_STRING, DEFAULT_MAPWITHAI_API_PARAMETERS);
|
||||
} else {
|
||||
map.putIfAbsent(SOURCE_STRING, url);
|
||||
map.putIfAbsent(ENABLED_STRING, Boolean.FALSE.toString());
|
||||
}
|
||||
});
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
|
|
|
@ -200,14 +200,6 @@ public class MapWithAIDataUtilsTest {
|
|||
MapWithAIPreferenceHelper.setMapWithAIUrl("Fake2", fakeUrl, true, true);
|
||||
assertEquals(1, MapWithAIPreferenceHelper.getMapWithAIUrl().parallelStream()
|
||||
.filter(map -> fakeUrl.equals(map.get("url"))).count(), "There should only be one fakeUrl");
|
||||
MapWithAIPreferenceHelper.setMapWithAIURLs(urls.parallelStream()
|
||||
.filter(map -> !fakeUrl.equalsIgnoreCase(map.getOrDefault("url", ""))).collect(Collectors.toList()));
|
||||
assertEquals(1, MapWithAIPreferenceHelper.getMapWithAIUrl().size(),
|
||||
"The MapWithAI URLs should have been reset (essentially)");
|
||||
assertTrue(MapWithAIPreferenceHelper.getMapWithAIUrl().parallelStream()
|
||||
.anyMatch(map -> getDefaultMapWithAIAPIForTest(MapWithAIPreferenceHelper.DEFAULT_MAPWITHAI_API)
|
||||
.equals(map.get("url"))),
|
||||
"The MapWithAI URLs should have been reset");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Ładowanie…
Reference in New Issue