Merge pull request #352 from gubatron/cleanup-gubatron-2016-01-14

Exploratory cleanup, Hi.
This commit is contained in:
Manfred Karrer 2016-01-15 00:13:01 +01:00
commit c7b8921c61
16 changed files with 70 additions and 155 deletions

View File

@ -26,7 +26,7 @@ public final class Alert implements PubKeyProtectedExpirablePayload {
// That object is sent over the wire, so we need to take care of version compatibility.
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
public static final long TTL = 10 * 24 * 60 * 60 * 1000; // 10 days
private static final long TTL = 10 * 24 * 60 * 60 * 1000; // 10 days
public final String message;
private String signatureAsBase64;
@ -59,12 +59,9 @@ public final class Alert implements PubKeyProtectedExpirablePayload {
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Alert)) return false;
Alert that = (Alert) o;
if (message != null ? !message.equals(that.message) : that.message != null) return false;
return !(getSignatureAsBase64() != null ? !getSignatureAsBase64().equals(that.getSignatureAsBase64()) : that.getSignatureAsBase64() != null);
}
@Override

View File

@ -40,8 +40,8 @@ public class AlertManager {
transient private static final Logger log = LoggerFactory.getLogger(AlertManager.class);
private final AlertService alertService;
private KeyRing keyRing;
private User user;
private final KeyRing keyRing;
private final User user;
private final ObjectProperty<Alert> alertMessageProperty = new SimpleObjectProperty<>();
// Pub key for developer global alert message

View File

@ -33,7 +33,7 @@ import javax.inject.Inject;
*/
public class AlertService {
private static final Logger log = LoggerFactory.getLogger(AlertService.class);
private P2PService p2PService;
private final P2PService p2PService;
///////////////////////////////////////////////////////////////////////////////////////////

View File

@ -37,7 +37,7 @@ import java.util.stream.Collectors;
public class ArbitratorService {
private static final Logger log = LoggerFactory.getLogger(ArbitratorService.class);
private P2PService p2PService;
private final P2PService p2PService;
interface ArbitratorMapResultHandler {
void handleResult(Map<String, Arbitrator> arbitratorsMap);

View File

@ -49,27 +49,24 @@ class AddressBasedCoinSelector implements CoinSelector {
@VisibleForTesting
static void sortOutputs(ArrayList<TransactionOutput> outputs) {
Collections.sort(outputs, new Comparator<TransactionOutput>() {
@Override
public int compare(TransactionOutput a, TransactionOutput b) {
int depth1 = a.getParentTransactionDepthInBlocks();
int depth2 = b.getParentTransactionDepthInBlocks();
Coin aValue = a.getValue();
Coin bValue = b.getValue();
BigInteger aCoinDepth = BigInteger.valueOf(aValue.value).multiply(BigInteger.valueOf(depth1));
BigInteger bCoinDepth = BigInteger.valueOf(bValue.value).multiply(BigInteger.valueOf(depth2));
int c1 = bCoinDepth.compareTo(aCoinDepth);
if (c1 != 0) return c1;
// The "coin*days" destroyed are equal, sort by value alone to get the lowest transaction size.
int c2 = bValue.compareTo(aValue);
if (c2 != 0) return c2;
// They are entirely equivalent (possibly pending) so sort by hash to ensure a total ordering.
checkNotNull(a.getParentTransactionHash(), "a.getParentTransactionHash() must not be null");
checkNotNull(b.getParentTransactionHash(), "b.getParentTransactionHash() must not be null");
BigInteger aHash = a.getParentTransactionHash().toBigInteger();
BigInteger bHash = b.getParentTransactionHash().toBigInteger();
return aHash.compareTo(bHash);
}
Collections.sort(outputs, (a, b) -> {
int depth1 = a.getParentTransactionDepthInBlocks();
int depth2 = b.getParentTransactionDepthInBlocks();
Coin aValue = a.getValue();
Coin bValue = b.getValue();
BigInteger aCoinDepth = BigInteger.valueOf(aValue.value).multiply(BigInteger.valueOf(depth1));
BigInteger bCoinDepth = BigInteger.valueOf(bValue.value).multiply(BigInteger.valueOf(depth2));
int c1 = bCoinDepth.compareTo(aCoinDepth);
if (c1 != 0) return c1;
// The "coin*days" destroyed are equal, sort by value alone to get the lowest transaction size.
int c2 = bValue.compareTo(aValue);
if (c2 != 0) return c2;
// They are entirely equivalent (possibly pending) so sort by hash to ensure a total ordering.
checkNotNull(a.getParentTransactionHash(), "a.getParentTransactionHash() must not be null");
checkNotNull(b.getParentTransactionHash(), "b.getParentTransactionHash() must not be null");
BigInteger aHash = a.getParentTransactionHash().toBigInteger();
BigInteger bHash = b.getParentTransactionHash().toBigInteger();
return aHash.compareTo(bHash);
});
}

View File

@ -56,7 +56,7 @@ public class AddressEntry implements Serializable {
// Only set if its a TRADE Context
@Nullable
private String offerId;
private final String offerId;
private final Context context;
private final byte[] pubKey;

View File

@ -17,48 +17,24 @@
package io.bitsquare.locale;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import io.bitsquare.user.Preferences;
import java.util.*;
import java.util.stream.Collectors;
public class CountryUtil {
public static List<Region> getAllRegions() {
final List<Region> allRegions = new ArrayList<>();
String regionCode = "NA";
Region region = new Region(regionCode, getRegionName(regionCode));
allRegions.add(region);
regionCode = "SA";
region = new Region(regionCode, getRegionName(regionCode));
allRegions.add(region);
regionCode = "AF";
region = new Region(regionCode, getRegionName(regionCode));
allRegions.add(region);
regionCode = "EU";
region = new Region(regionCode, getRegionName(regionCode));
allRegions.add(region);
regionCode = "AS";
region = new Region(regionCode, getRegionName(regionCode));
allRegions.add(region);
regionCode = "OC";
region = new Region(regionCode, getRegionName(regionCode));
allRegions.add(region);
return allRegions;
}
public static List<Country> getAllSepaEuroCountries() {
List<Country> list = new ArrayList<>();
String[] codes = {"AT", "BE", "CY", "DE", "EE", "FI", "FR", "GR", "IE",
"IT", "LV", "LT", "LU", "MC", "MT", "NL", "PT", "SK", "SI", "ES"};
populateCountryListByCodes(list, codes);
list.sort((a, b) -> a.code.compareTo(b.code));
return list;
}
private static void populateCountryListByCodes(List<Country> list, String[] codes) {
for (String code : codes) {
Locale locale = new Locale(LanguageUtil.getDefaultLanguage(), code, "");
String regionCode = getRegionCode(locale.getCountry());
@ -66,42 +42,19 @@ public class CountryUtil {
final Country country = new Country(locale.getCountry(), locale.getDisplayCountry(), region);
list.add(country);
}
list.sort((a, b) -> a.code.compareTo(b.code));
return list;
}
public static boolean containsAllSepaEuroCountries(List<String> countryCodesToCompare) {
countryCodesToCompare.sort((a, b) -> a.compareTo(b));
countryCodesToCompare.sort(String::compareTo);
List<String> countryCodesBase = getAllSepaEuroCountries().stream().map(c -> c.code).collect(Collectors.toList());
return countryCodesToCompare.toString().equals(countryCodesBase.toString());
/*
List<Country> countriesBase = getAllSepaEuroCountries();
List<Country> remainingBase = new ArrayList<>(countriesBase);
List<String> remainingToCompare = new ArrayList<>(countryCodesToCompare);
for (int i = 0; i < countriesBase.size(); i++) {
String countryCodeBase = countriesBase.get(i).code;
for (int n = 0; n < countryCodesToCompare.size(); n++) {
if (countryCodeBase.equals(countryCodesToCompare.get(n))) {
if (remainingBase.size() > 0) remainingBase.remove(i);
if (remainingToCompare.size() > 0) remainingToCompare.remove(n);
}
}
}
return remainingBase.size() == 0 && remainingBase.size() == remainingToCompare.size();*/
}
public static List<Country> getAllSepaNonEuroCountries() {
List<Country> list = new ArrayList<>();
String[] codes = {"BG", "HR", "CZ", "DK", "GB", "HU", "PL", "RO",
"SE", "IS", "NO", "LI", "CH"};
for (String code : codes) {
Locale locale = new Locale(LanguageUtil.getDefaultLanguage(), code, "");
String regionCode = getRegionCode(locale.getCountry());
final Region region = new Region(regionCode, getRegionName(regionCode));
final Country country = new Country(locale.getCountry(), locale.getDisplayCountry(), region);
list.add(country);
}
populateCountryListByCodes(list, codes);
list.sort((a, b) -> a.code.compareTo(b.code));
return list;
}
@ -113,11 +66,6 @@ public class CountryUtil {
return list;
}
public static List<Country> getAllCountriesFor(Region selectedRegion) {
return Lists.newArrayList(Collections2.filter(getAllCountries(), country ->
selectedRegion != null && country != null && selectedRegion.equals(country.region)));
}
public static Country getDefaultCountry() {
final Locale locale = Preferences.getDefaultLocale();
String regionCode = getRegionCode(locale.getCountry());
@ -125,26 +73,10 @@ public class CountryUtil {
return new Country(locale.getCountry(), locale.getDisplayCountry(), region);
}
private static List<Country> getAllCountries() {
final List<Country> allCountries = new ArrayList<>();
for (final Locale locale : getAllCountryLocales()) {
String regionCode = getRegionCode(locale.getCountry());
final Region region = new Region(regionCode, getRegionName(regionCode));
final Country country = new Country(locale.getCountry(), locale.getDisplayCountry(), region);
allCountries.add(country);
}
return allCountries;
}
public static String getNameByCode(String countryCode) {
return new Locale(LanguageUtil.getDefaultLanguage(), countryCode).getDisplayCountry();
}
public static List<String> getNamesByCodes(List<String> countryCodes) {
return countryCodes.stream().map(c -> getNameByCode(c)).collect(Collectors.toList());
}
public static String getCodesString(List<String> countryCodes) {
return countryCodes.stream().collect(Collectors.joining(", "));
}
@ -153,6 +85,10 @@ public class CountryUtil {
return getNamesByCodes(countryCodes).stream().collect(Collectors.joining(",\n"));
}
private static List<String> getNamesByCodes(List<String> countryCodes) {
return countryCodes.stream().map(CountryUtil::getNameByCode).collect(Collectors.toList());
}
private static final String[] countryCodes = new String[]{"AE", "AL", "AR", "AT", "AU", "BA", "BE", "BG", "BH",
"BO", "BR", "BY", "CA", "CH", "CL", "CN", "CO", "CR", "CS", "CU", "CY", "CZ", "DE", "DK", "DO", "DZ",
"EC", "EE", "EG", "ES", "FI", "FR", "GB", "GR", "GT", "HK", "HN", "HR", "HU", "ID", "IE", "IL", "IN",
@ -183,20 +119,6 @@ public class CountryUtil {
return regionCode;
}
// We use getAvailableLocales as we depend on display names (would be a bit painful with translations if handled
// from a static list -or we find something ready made?).
private static List<Locale> getAllCountryLocales() {
List<Locale> allLocales = Arrays.asList(Locale.getAvailableLocales());
Set<Locale> allLocalesAsSet = allLocales.stream().filter(locale -> !"".equals(locale.getCountry()))
.map(locale -> new Locale(LanguageUtil.getDefaultLanguage(), locale.getCountry(), ""))
.collect(Collectors.toSet());
allLocales = new ArrayList<>();
allLocales.addAll(allLocalesAsSet);
allLocales.sort((locale1, locale2) -> locale1.getDisplayCountry().compareTo(locale2.getDisplayCountry()));
return allLocales;
}
private static String getRegionCode(String countryCode) {
if (!countryCode.isEmpty() && countryCodeList.contains(countryCode)) {
return regionCodeList.get(countryCodeList.indexOf(countryCode));

View File

@ -27,7 +27,7 @@ import java.util.stream.Collectors;
public class CurrencyUtil {
transient private static final Logger log = LoggerFactory.getLogger(CurrencyUtil.class);
private static List<TradeCurrency> allSortedCurrencies = createAllSortedCurrenciesList();
private static final List<TradeCurrency> allSortedCurrencies = createAllSortedCurrenciesList();
public static List<TradeCurrency> getAllSortedCurrencies() {
return allSortedCurrencies;
@ -38,7 +38,7 @@ public class CurrencyUtil {
Set<TradeCurrency> set = new HashSet<>();
// Sepa: EUR at first place
set.addAll(getSortedSepaCurrencyCodes());
set.addAll(getSortedSEPACurrencyCodes());
// PerfectMoney:
set.add(new TradeCurrency("USD"));
@ -47,9 +47,9 @@ public class CurrencyUtil {
set.add(new TradeCurrency("CNY"));
// OKPay: We want to maintain the order so we don't use a Set but add items if nto already in list
getAllOKPayCurrencies().stream().forEach(e -> set.add(e));
getAllOKPayCurrencies().stream().forEach(set::add);
// Swish: it is already added by Sepa
// Swish: it is already added by SEPA
// for printing out all codes
/* String res;
@ -64,9 +64,9 @@ public class CurrencyUtil {
// check if the list derived form the payment methods is containing exactly the same as our manually sorted one
List<String> list1 = set.stream().map(e -> e.code).collect(Collectors.toList());
list1.sort((a, b) -> a.compareTo(b));
list1.sort(String::compareTo);
List<String> list2 = list.stream().map(e -> e.code).collect(Collectors.toList());
list2.sort((a, b) -> a.compareTo(b));
list2.sort(String::compareTo);
if (list1.size() != list2.size()) {
log.error("manually defined currencies are not matching currencies derived form our payment methods");
@ -81,7 +81,7 @@ public class CurrencyUtil {
}
// Blockchain
getSortedCryptoCurrencies().stream().forEach(e -> list.add(e));
getSortedCryptoCurrencies().stream().forEach(list::add);
return list;
}
@ -119,9 +119,9 @@ public class CurrencyUtil {
}
/**
* @return Sorted list of sepa currencies with EUR as first item
* @return Sorted list of SEPA currencies with EUR as first item
*/
public static Set<TradeCurrency> getSortedSepaCurrencyCodes() {
private static Set<TradeCurrency> getSortedSEPACurrencyCodes() {
return CountryUtil.getAllSepaCountries().stream()
.map(country -> getCurrencyByCountryCode(country.code))
.collect(Collectors.toSet());
@ -162,7 +162,7 @@ public class CurrencyUtil {
// Unfortunately we cannot support CryptoNote coins yet as there is no way to proof the transaction. Payment ID helps only locate the tx but the
// arbitrator cannot see if the receiving key matches the receivers address. They might add support for exposing the tx key, but that is not
// implemented yet. To use the view key (also not available in GUI wallets) would reveal the complete wallet history for incoming payments, which is
// not acceptable from pricavy point of view.
// not acceptable from privacy point of view.
// result.add(new CryptoCurrency("XMR", "Monero"));
// result.add(new CryptoCurrency("BCN", "Bytecoin"));
result.add(new CryptoCurrency("DASH", "Dash"));

View File

@ -38,7 +38,7 @@ public class SepaAccountContractData extends PaymentAccountContractData implemen
private String iban;
private String bic;
// Dont use a set here as we need a deterministic ordering, otherwise the contract hash does not match
private ArrayList<String> acceptedCountryCodes;
private final ArrayList<String> acceptedCountryCodes;
public SepaAccountContractData(String paymentMethod, String id, int maxTradePeriod) {
super(paymentMethod, id, maxTradePeriod);

View File

@ -36,11 +36,11 @@ public abstract class BuyerTrade extends Trade implements Serializable {
transient private static final Logger log = LoggerFactory.getLogger(BuyerAsOffererTrade.class);
public BuyerTrade(Offer offer, Coin tradeAmount, Address tradingPeerAddress, Storage<? extends TradableList> storage) {
BuyerTrade(Offer offer, Coin tradeAmount, Address tradingPeerAddress, Storage<? extends TradableList> storage) {
super(offer, tradeAmount, tradingPeerAddress, storage);
}
public BuyerTrade(Offer offer, Storage<? extends TradableList> storage) {
BuyerTrade(Offer offer, Storage<? extends TradableList> storage) {
super(offer, storage);
}

View File

@ -83,7 +83,7 @@ public class TradeManager {
private final Storage<TradableList<Trade>> tradableListStorage;
private final TradableList<Trade> trades;
private final BooleanProperty pendingTradesInitialized = new SimpleBooleanProperty();
private FirstPeerAuthenticatedListener firstPeerAuthenticatedListener;
private final FirstPeerAuthenticatedListener firstPeerAuthenticatedListener;
///////////////////////////////////////////////////////////////////////////////////////////

View File

@ -35,7 +35,7 @@ import java.util.stream.Collectors;
public class OfferBookService {
private static final Logger log = LoggerFactory.getLogger(OfferBookService.class);
private P2PService p2PService;
private final P2PService p2PService;
///////////////////////////////////////////////////////////////////////////////////////////

View File

@ -58,8 +58,8 @@ public class OpenOfferManager {
private static final Logger log = LoggerFactory.getLogger(OpenOfferManager.class);
private final KeyRing keyRing;
private User user;
private P2PService p2PService;
private final User user;
private final P2PService p2PService;
private final WalletService walletService;
private final TradeWalletService tradeWalletService;
private final OfferBookService offerBookService;

View File

@ -21,9 +21,9 @@ public class PopupId {
// We don't use an enum because it would break updates if we add a new item in a new version
public static String TRADE_WALLET = "tradeWallet";
public static String SEND_PAYMENT_INFO = "sendPaymentInfo";
public static String PAYMENT_SENT = "paymentSent";
public static String PAYMENT_RECEIVED = "paymentReceived";
public static final String TRADE_WALLET = "tradeWallet";
public static final String SEND_PAYMENT_INFO = "sendPaymentInfo";
public static final String PAYMENT_SENT = "paymentSent";
public static final String PAYMENT_RECEIVED = "paymentReceived";
}

View File

@ -88,14 +88,14 @@ public class Preferences implements Serializable {
private boolean useAnimations = true;
private boolean useEffects = true;
private boolean displaySecurityDepositInfo = true;
private ArrayList<TradeCurrency> tradeCurrencies;
private final ArrayList<TradeCurrency> tradeCurrencies;
private BlockChainExplorer blockChainExplorerMainNet;
private BlockChainExplorer blockChainExplorerTestNet;
private boolean showPlaceOfferConfirmation;
private boolean showTakeOfferConfirmation;
private String backupDirectory;
private boolean autoSelectArbitrators = true;
private Map<String, Boolean> showAgainMap;
private final Map<String, Boolean> showAgainMap;
private boolean tacAccepted;
private Locale preferredLocale;
private TradeCurrency preferredTradeCurrency;

View File

@ -151,17 +151,16 @@ class ArbitratorRegistrationViewModel extends ActivatableViewModel {
registrationKey.getPubKey(),
registrationSignature
);
if (arbitrator != null) {
arbitratorManager.addArbitrator(arbitrator,
() -> {
updateDisableStates();
resultHandler.handleResult();
},
(errorMessage) -> {
updateDisableStates();
errorMessageHandler.handleErrorMessage(errorMessage);
});
}
arbitratorManager.addArbitrator(arbitrator,
() -> {
updateDisableStates();
resultHandler.handleResult();
},
(errorMessage) -> {
updateDisableStates();
errorMessageHandler.handleErrorMessage(errorMessage);
});
}
}