Merge pull request #3432 from lusarz/refactor-bisq-environment-3

Refactor BisqEnvironment - create getListProperty
This commit is contained in:
Florian Reimair 2019-11-01 11:17:33 +01:00 committed by GitHub
commit c1e7a0bb6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -272,14 +272,9 @@ public class BisqEnvironment extends StandardEnvironment {
try {
propertySources.addLast(getAppDirProperties());
final String bannedPriceRelayNodesAsString = getProperty(FilterManager.BANNED_PRICE_RELAY_NODES, "");
bannedPriceRelayNodes = !bannedPriceRelayNodesAsString.isEmpty() ? Arrays.asList(StringUtils.deleteWhitespace(bannedPriceRelayNodesAsString).split(",")) : null;
final String bannedSeedNodesAsString = getProperty(FilterManager.BANNED_SEED_NODES, "");
bannedSeedNodes = !bannedSeedNodesAsString.isEmpty() ? Arrays.asList(StringUtils.deleteWhitespace(bannedSeedNodesAsString).split(",")) : new ArrayList<>();
final String bannedBtcNodesAsString = getProperty(FilterManager.BANNED_BTC_NODES, "");
bannedBtcNodes = !bannedBtcNodesAsString.isEmpty() ? Arrays.asList(StringUtils.deleteWhitespace(bannedBtcNodesAsString).split(",")) : null;
bannedPriceRelayNodes = getListProperty(FilterManager.BANNED_PRICE_RELAY_NODES, null);
bannedSeedNodes = getListProperty(FilterManager.BANNED_SEED_NODES, new ArrayList<>());
bannedBtcNodes = getListProperty(FilterManager.BANNED_BTC_NODES, null);
baseCurrencyNetwork = BaseCurrencyNetwork.valueOf(getProperty(BtcOptionKeys.BASE_CURRENCY_NETWORK,
getDefaultBaseCurrencyNetwork().name()).toUpperCase());
@ -371,6 +366,11 @@ public class BisqEnvironment extends StandardEnvironment {
return properties.containsProperty(propertyKey) ? (String) properties.getProperty(propertyKey) : defaultValue;
}
private List<String> getListProperty (String key, List defaultValue) {
final String value = getProperty(key, "");
return value.isEmpty() ? defaultValue : Arrays.asList(StringUtils.deleteWhitespace(value).split(","));
}
private PropertySource<?> defaultProperties() {
return new PropertiesPropertySource(BISQ_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {
{