diff --git a/core/src/main/java/io/bitsquare/arbitration/Arbitrator.java b/core/src/main/java/io/bitsquare/arbitration/Arbitrator.java index f950099af6..6940feaf1b 100644 --- a/core/src/main/java/io/bitsquare/arbitration/Arbitrator.java +++ b/core/src/main/java/io/bitsquare/arbitration/Arbitrator.java @@ -68,13 +68,13 @@ public class Arbitrator implements Serializable { transient private Storage storage; // Persisted fields - private String id; - private byte[] pubKey; - private PublicKey p2pSigPubKey; - private String name; - private Reputation reputation; + private final String id; + private final byte[] pubKey; + private final PublicKey p2pSigPubKey; + private final String name; + private final Reputation reputation; - // editable + // Mutable private ID_TYPE idType; private List languageCodes; private Coin fee; @@ -137,6 +137,8 @@ public class Arbitrator implements Serializable { Arbitrator other = (Arbitrator) obj; return id != null && id.equals(other.getId()); } + + /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/core/src/main/java/io/bitsquare/fiat/FiatAccount.java b/core/src/main/java/io/bitsquare/fiat/FiatAccount.java index 3ee477e074..b62f8452f0 100644 --- a/core/src/main/java/io/bitsquare/fiat/FiatAccount.java +++ b/core/src/main/java/io/bitsquare/fiat/FiatAccount.java @@ -21,79 +21,69 @@ import io.bitsquare.locale.Country; import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Objects; import javax.annotation.concurrent.Immutable; @Immutable public class FiatAccount implements Serializable { - // That object is saved to disc. We need to take care of changes to not break deserialization. + // That object is sent over the wire, so we need to take care of version compatibility. private static final long serialVersionUID = 1L; - private final FiatAccountType fiatAccountType; - private final String accountPrimaryID; // like IBAN - private final String accountSecondaryID; // like BIC - private final String accountHolderName; - private final Country country; // where bank is registered - private final String nameOfBank; + public enum Type { + IRC("", ""), + SEPA("IBAN", "BIC"), + WIRE("primary ID", "secondary ID"), + INTERNATIONAL("primary ID", "secondary ID"), + OK_PAY("primary ID", "secondary ID"), + NET_TELLER("primary ID", "secondary ID"), + PERFECT_MONEY("primary ID", "secondary ID"); + + public final String primaryId; + public final String secondaryId; + + Type(String primaryId, String secondaryId) { + this.primaryId = primaryId; + this.secondaryId = secondaryId; + } + + public static ArrayList getAllBankAccountTypes() { + return new ArrayList<>(Arrays.asList(Type.values())); + } + } + + public final String id; + public final String nameOfBank; + public final Type type; + public final Country country; // where bank is registered + public final String accountPrimaryID; // like IBAN + public final String accountSecondaryID; // like BIC + public final String accountHolderName; + // The main currency if account support multiple currencies. // The user can create multiple bank accounts with same bank account but other currency if his bank account // support that. - private final String currencyCode; + public final String currencyCode; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor /////////////////////////////////////////////////////////////////////////////////////////// - public FiatAccount(FiatAccountType fiatAccountType, String currencyCode, Country country, String nameOfBank, + public FiatAccount(Type type, String currencyCode, Country country, String nameOfBank, String accountHolderName, String accountPrimaryID, String accountSecondaryID) { - this.fiatAccountType = fiatAccountType; + this.type = type; this.currencyCode = currencyCode; this.country = country; this.nameOfBank = nameOfBank; this.accountHolderName = accountHolderName; this.accountPrimaryID = accountPrimaryID; this.accountSecondaryID = accountSecondaryID; - } - - /////////////////////////////////////////////////////////////////////////////////////////// - // Getters/Setters - /////////////////////////////////////////////////////////////////////////////////////////// - - public String getAccountPrimaryID() { - return accountPrimaryID; - } - - public String getAccountSecondaryID() { - return accountSecondaryID; - } - - public String getAccountHolderName() { - return accountHolderName; - } - - public FiatAccountType getFiatAccountType() { - return fiatAccountType; - } - - public String getCurrencyCode() { - return currencyCode; - } - - public Country getCountry() { - return country; - } - - // we use the accountTitle as unique id - public String getId() { - return nameOfBank; - } - - public String getNameOfBank() { - return nameOfBank; + id = nameOfBank; } @@ -103,7 +93,7 @@ public class FiatAccount implements Serializable { @Override public int hashCode() { - return Objects.hashCode(nameOfBank); + return Objects.hashCode(id); } @Override @@ -112,19 +102,20 @@ public class FiatAccount implements Serializable { if (obj == this) return true; final FiatAccount other = (FiatAccount) obj; - return nameOfBank.equals(other.getId()); + return id.equals(other.id); } @Override public String toString() { - return "BankAccount{" + - "bankAccountType=" + fiatAccountType + + return "FiatAccount{" + + "id='" + id + '\'' + + ", nameOfBank='" + nameOfBank + '\'' + + ", type=" + type + + ", country=" + country + ", accountPrimaryID='" + accountPrimaryID + '\'' + ", accountSecondaryID='" + accountSecondaryID + '\'' + ", accountHolderName='" + accountHolderName + '\'' + - ", country=" + country + - ", currency=" + currencyCode + - ", accountTitle='" + nameOfBank + '\'' + + ", currencyCode='" + currencyCode + '\'' + '}'; } } diff --git a/core/src/main/java/io/bitsquare/fiat/FiatAccountType.java b/core/src/main/java/io/bitsquare/fiat/FiatAccountType.java deleted file mode 100644 index fffa7052a2..0000000000 --- a/core/src/main/java/io/bitsquare/fiat/FiatAccountType.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of Bitsquare. - * - * Bitsquare is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bitsquare is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bitsquare. If not, see . - */ - -package io.bitsquare.fiat; - -import java.util.ArrayList; -import java.util.Arrays; - -public enum FiatAccountType { - IRC("", ""), - SEPA("IBAN", "BIC"), - WIRE("primary ID", "secondary ID"), - INTERNATIONAL("primary ID", "secondary ID"), - OK_PAY("primary ID", "secondary ID"), - NET_TELLER("primary ID", "secondary ID"), - PERFECT_MONEY("primary ID", "secondary ID"); - - private final String primaryId; - private final String secondaryId; - - FiatAccountType(String primaryId, String secondaryId) { - this.primaryId = primaryId; - this.secondaryId = secondaryId; - } - - public static ArrayList getAllBankAccountTypes() { - return new ArrayList<>(Arrays.asList(FiatAccountType.values())); - } - - public String getPrimaryId() { - return primaryId; - } - - public String getSecondaryId() { - return secondaryId; - } -} diff --git a/core/src/main/java/io/bitsquare/gui/main/MainViewModel.java b/core/src/main/java/io/bitsquare/gui/main/MainViewModel.java index cbeb226aaa..34b469578e 100644 --- a/core/src/main/java/io/bitsquare/gui/main/MainViewModel.java +++ b/core/src/main/java/io/bitsquare/gui/main/MainViewModel.java @@ -23,7 +23,6 @@ import io.bitsquare.btc.BitcoinNetwork; import io.bitsquare.btc.WalletService; import io.bitsquare.common.viewfx.model.ViewModel; import io.bitsquare.fiat.FiatAccount; -import io.bitsquare.fiat.FiatAccountType; import io.bitsquare.gui.util.BSFormatter; import io.bitsquare.locale.CountryUtil; import io.bitsquare.p2p.BaseP2PService; @@ -193,7 +192,7 @@ class MainViewModel implements ViewModel { // For alpha version if (!user.isRegistered()) { - FiatAccount fiatAccount = new FiatAccount(FiatAccountType.IRC, + FiatAccount fiatAccount = new FiatAccount(FiatAccount.Type.IRC, "EUR", CountryUtil.getDefaultCountry(), "Demo (Name of bank)", @@ -286,7 +285,7 @@ class MainViewModel implements ViewModel { return new StringConverter() { @Override public String toString(FiatAccount fiatAccount) { - return fiatAccount.getNameOfBank(); + return fiatAccount.nameOfBank; } @Override diff --git a/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountDataModel.java b/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountDataModel.java index e89a6b2398..f463946675 100644 --- a/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountDataModel.java +++ b/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountDataModel.java @@ -20,7 +20,6 @@ package io.bitsquare.gui.main.account.content.fiat; import io.bitsquare.common.viewfx.model.Activatable; import io.bitsquare.common.viewfx.model.DataModel; import io.bitsquare.fiat.FiatAccount; -import io.bitsquare.fiat.FiatAccountType; import io.bitsquare.locale.Country; import io.bitsquare.locale.CountryUtil; import io.bitsquare.locale.CurrencyUtil; @@ -52,10 +51,10 @@ class FiatAccountDataModel implements Activatable, DataModel { final StringProperty secondaryIDPrompt = new SimpleStringProperty(); final StringProperty currencyCode = new SimpleStringProperty(); final BooleanProperty countryNotInAcceptedCountriesList = new SimpleBooleanProperty(); - final ObjectProperty type = new SimpleObjectProperty<>(); + final ObjectProperty type = new SimpleObjectProperty<>(); final ObjectProperty country = new SimpleObjectProperty<>(); - final ObservableList allTypes = FXCollections.observableArrayList(FiatAccountType + final ObservableList allTypes = FXCollections.observableArrayList(FiatAccount.Type .getAllBankAccountTypes()); final ObservableList allFiatAccounts = FXCollections.observableArrayList(); final ObservableList allCurrencyCodes = FXCollections.observableArrayList(CurrencyUtil @@ -112,16 +111,16 @@ class FiatAccountDataModel implements Activatable, DataModel { user.setCurrentFiatAccountProperty(fiatAccount); if (fiatAccount != null) { - title.set(fiatAccount.getNameOfBank()); - holderName.set(fiatAccount.getAccountHolderName()); - primaryID.set(fiatAccount.getAccountPrimaryID()); - secondaryID.set(fiatAccount.getAccountSecondaryID()); - primaryIDPrompt.set(fiatAccount.getFiatAccountType().getPrimaryId()); - secondaryIDPrompt.set(fiatAccount.getFiatAccountType().getSecondaryId()); + title.set(fiatAccount.nameOfBank); + holderName.set(fiatAccount.accountHolderName); + primaryID.set(fiatAccount.accountPrimaryID); + secondaryID.set(fiatAccount.accountSecondaryID); + primaryIDPrompt.set(fiatAccount.type.primaryId); + secondaryIDPrompt.set(fiatAccount.type.secondaryId); - type.set(fiatAccount.getFiatAccountType()); - country.set(fiatAccount.getCountry()); - currencyCode.set(fiatAccount.getCurrencyCode()); + type.set(fiatAccount.type); + country.set(fiatAccount.country); + currencyCode.set(fiatAccount.currencyCode); } else { reset(); @@ -134,12 +133,12 @@ class FiatAccountDataModel implements Activatable, DataModel { } - void setType(FiatAccountType type) { + void setType(FiatAccount.Type type) { this.type.set(type); if (type != null) { - primaryIDPrompt.set(type.getPrimaryId()); - secondaryIDPrompt.set(type.getSecondaryId()); + primaryIDPrompt.set(type.primaryId); + secondaryIDPrompt.set(type.secondaryId); } else { primaryIDPrompt.set(null); diff --git a/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountView.java b/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountView.java index 33a35dcaf4..d44ca250fc 100644 --- a/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountView.java +++ b/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountView.java @@ -21,7 +21,6 @@ import io.bitsquare.common.viewfx.view.ActivatableViewAndModel; import io.bitsquare.common.viewfx.view.FxmlView; import io.bitsquare.common.viewfx.view.Wizard; import io.bitsquare.fiat.FiatAccount; -import io.bitsquare.fiat.FiatAccountType; import io.bitsquare.gui.OverlayManager; import io.bitsquare.gui.components.InputTextField; import io.bitsquare.gui.components.Popups; @@ -58,7 +57,7 @@ public class FiatAccountView extends ActivatableViewAndModel selectionComboBox; - @FXML ComboBox typesComboBox; + @FXML ComboBox typesComboBox; @FXML ComboBox currencyComboBox; private Wizard wizard; @@ -187,9 +186,9 @@ public class FiatAccountView extends ActivatableViewAndModel { if (newValue != null) { - int regionIndex = regionComboBox.getItems().indexOf(newValue.getRegion()); + int regionIndex = regionComboBox.getItems().indexOf(newValue.region); if (regionIndex >= 0 && regionIndex < regionComboBox.getItems().size()) - regionComboBox.getSelectionModel().select(regionComboBox.getItems().indexOf(newValue.getRegion())); + regionComboBox.getSelectionModel().select(regionComboBox.getItems().indexOf(newValue.region)); int countryIndex = countryComboBox.getItems().indexOf(newValue); if (countryIndex >= 0 && countryIndex < countryComboBox.getItems().size()) diff --git a/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountViewModel.java b/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountViewModel.java index ce4fae63b3..47fd16c91a 100644 --- a/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountViewModel.java +++ b/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountViewModel.java @@ -20,7 +20,6 @@ package io.bitsquare.gui.main.account.content.fiat; import io.bitsquare.common.viewfx.model.ActivatableWithDataModel; import io.bitsquare.common.viewfx.model.ViewModel; import io.bitsquare.fiat.FiatAccount; -import io.bitsquare.fiat.FiatAccountType; import io.bitsquare.gui.util.validation.BankAccountNumberValidator; import io.bitsquare.gui.util.validation.InputValidator; import io.bitsquare.locale.BSResources; @@ -54,7 +53,7 @@ class FiatAccountViewModel extends ActivatableWithDataModel type = new SimpleObjectProperty<>(); + final ObjectProperty type = new SimpleObjectProperty<>(); final ObjectProperty country = new SimpleObjectProperty<>(); @@ -112,15 +111,15 @@ class FiatAccountViewModel extends ActivatableWithDataModel getTypesConverter() { - return new StringConverter() { + StringConverter getTypesConverter() { + return new StringConverter() { @Override - public String toString(FiatAccountType TypeInfo) { + public String toString(FiatAccount.Type TypeInfo) { return BSResources.get(TypeInfo.toString()); } @Override - public FiatAccountType fromString(String s) { + public FiatAccount.Type fromString(String s) { return null; } }; @@ -130,7 +129,7 @@ class FiatAccountViewModel extends ActivatableWithDataModel() { @Override public String toString(FiatAccount fiatAccount) { - return fiatAccount.getNameOfBank(); + return fiatAccount.nameOfBank; } @Override @@ -160,7 +159,7 @@ class FiatAccountViewModel extends ActivatableWithDataModel() { @Override public String toString(io.bitsquare.locale.Region region) { - return region.getName(); + return region.name; } @Override @@ -174,7 +173,7 @@ class FiatAccountViewModel extends ActivatableWithDataModel() { @Override public String toString(Country country) { - return country.getName(); + return country.name; } @Override @@ -185,7 +184,7 @@ class FiatAccountViewModel extends ActivatableWithDataModel getAllTypes() { + ObservableList getAllTypes() { return dataModel.allTypes; } @@ -214,7 +213,7 @@ class FiatAccountViewModel extends ActivatableWithDataModel type = new SimpleObjectProperty<>(); + final ObjectProperty type = new SimpleObjectProperty<>(); - final ObservableList allTypes = - FXCollections.observableArrayList(FiatAccountType.getAllBankAccountTypes()); + final ObservableList allTypes = + FXCollections.observableArrayList(FiatAccount.Type.getAllBankAccountTypes()); final ObservableList allCurrencyCodes = FXCollections.observableArrayList(CurrencyUtil.getAllCurrencyCodes()); final ObservableList allFiatAccounts = FXCollections.observableArrayList(); @@ -76,7 +75,7 @@ class IrcAccountDataModel implements Activatable, DataModel { reset(); } - void setType(FiatAccountType type) { + void setType(FiatAccount.Type type) { this.type.set(type); } diff --git a/core/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountView.java b/core/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountView.java index 7afca13a1a..f48bc17832 100644 --- a/core/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountView.java +++ b/core/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountView.java @@ -20,7 +20,7 @@ package io.bitsquare.gui.main.account.content.irc; import io.bitsquare.common.viewfx.view.ActivatableViewAndModel; import io.bitsquare.common.viewfx.view.FxmlView; import io.bitsquare.common.viewfx.view.Wizard; -import io.bitsquare.fiat.FiatAccountType; +import io.bitsquare.fiat.FiatAccount; import io.bitsquare.gui.components.InputTextField; import io.bitsquare.gui.components.Popups; import io.bitsquare.gui.main.help.Help; @@ -45,7 +45,7 @@ public class IrcAccountView extends ActivatableViewAndModel typesComboBox; + @FXML ComboBox typesComboBox; @FXML ComboBox currencyComboBox; private Wizard wizard; @@ -62,13 +62,13 @@ public class IrcAccountView extends ActivatableViewAndModel, ListCell>() { + typesComboBox.setCellFactory(new Callback, ListCell>() { @Override - public ListCell call(ListView p) { - return new ListCell() { + public ListCell call(ListView p) { + return new ListCell() { @Override - protected void updateItem(FiatAccountType item, boolean empty) { + protected void updateItem(FiatAccount.Type item, boolean empty) { super.updateItem(item, empty); setText(model.getBankAccountType(item)); @@ -76,7 +76,7 @@ public class IrcAccountView extends ActivatableViewAndModel final StringProperty ircNickName = new SimpleStringProperty(); final StringProperty currencyCode = new SimpleStringProperty(); final BooleanProperty saveButtonDisable = new SimpleBooleanProperty(true); - final ObjectProperty type = new SimpleObjectProperty<>(); + final ObjectProperty type = new SimpleObjectProperty<>(); @Inject public IrcAccountViewModel(IrcAccountDataModel dataModel, BankAccountNumberValidator nickNameValidator) { @@ -67,21 +67,21 @@ class IrcAccountViewModel extends ActivatableWithDataModel return result; } - StringConverter getTypesConverter() { - return new StringConverter() { + StringConverter getTypesConverter() { + return new StringConverter() { @Override - public String toString(FiatAccountType TypeInfo) { + public String toString(FiatAccount.Type TypeInfo) { return BSResources.get(TypeInfo.toString()); } @Override - public FiatAccountType fromString(String s) { + public FiatAccount.Type fromString(String s) { return null; } }; } - String getBankAccountType(FiatAccountType fiatAccountType) { + String getBankAccountType(FiatAccount.Type fiatAccountType) { return fiatAccountType != null ? BSResources.get(fiatAccountType.toString()) : ""; } @@ -100,7 +100,7 @@ class IrcAccountViewModel extends ActivatableWithDataModel } - ObservableList getAllTypes() { + ObservableList getAllTypes() { return dataModel.allTypes; } @@ -113,7 +113,7 @@ class IrcAccountViewModel extends ActivatableWithDataModel } - void setType(FiatAccountType type) { + void setType(FiatAccount.Type type) { dataModel.setType(type); validateInput(); } diff --git a/core/src/main/java/io/bitsquare/gui/main/account/content/restrictions/RestrictionsView.java b/core/src/main/java/io/bitsquare/gui/main/account/content/restrictions/RestrictionsView.java index c10cb3e6da..292250e4ad 100644 --- a/core/src/main/java/io/bitsquare/gui/main/account/content/restrictions/RestrictionsView.java +++ b/core/src/main/java/io/bitsquare/gui/main/account/content/restrictions/RestrictionsView.java @@ -105,7 +105,7 @@ public class RestrictionsView extends ActivatableViewAndModel() { @Override public String toString(io.bitsquare.locale.Region region) { - return region.getName(); + return region.name; } @Override @@ -248,11 +248,11 @@ public class RestrictionsView extends ActivatableViewAndModel removeCountry(item)); + public void updateItem(final Country country, boolean empty) { + super.updateItem(country, empty); + if (country != null && !empty) { + label.setText(country.name); + removeButton.setOnAction(actionEvent -> removeCountry(country)); setGraphic(pane); } else { @@ -266,7 +266,7 @@ public class RestrictionsView extends ActivatableViewAndModel() { @Override public String toString(Country country) { - return country.getName(); + return country.name; } @Override diff --git a/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesViewModel.java b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesViewModel.java index a21dc9eca9..6673772abf 100644 --- a/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesViewModel.java +++ b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesViewModel.java @@ -171,7 +171,7 @@ class PendingTradesViewModel extends ActivatableWithDataModel e.setBankAccountCountry(fiatAccount.getCountry())); + fiatCode.set(fiatAccount.currencyCode); + bankAccountCountry.set(fiatAccount.country); + sortedItems.stream().forEach(e -> e.setBankAccountCountry(fiatAccount.country)); } else { fiatCode.set(CurrencyUtil.getDefaultCurrencyAsCode()); diff --git a/core/src/main/java/io/bitsquare/gui/main/trade/offerbook/OfferBookView.java b/core/src/main/java/io/bitsquare/gui/main/trade/offerbook/OfferBookView.java index e1336b1506..0753fc1507 100644 --- a/core/src/main/java/io/bitsquare/gui/main/trade/offerbook/OfferBookView.java +++ b/core/src/main/java/io/bitsquare/gui/main/trade/offerbook/OfferBookView.java @@ -586,7 +586,7 @@ public class OfferBookView extends ActivatableViewAndModel im acceptedArbitratorIds = formatter.arbitratorIdsToNames(offer.getArbitratorIds()); bankAccountType = BSResources.get(offer.getFiatAccountType().toString()); bankAccountCurrency = BSResources.get(CurrencyUtil.getDisplayName(offer.getCurrencyCode())); - bankAccountCounty = BSResources.get(offer.getBankAccountCountry().getName()); + bankAccountCounty = BSResources.get(offer.getBankAccountCountry().name); offer.stateProperty().addListener((ov, oldValue, newValue) -> applyOfferState(newValue)); applyOfferState(offer.stateProperty().get()); diff --git a/core/src/main/java/io/bitsquare/gui/util/BSFormatter.java b/core/src/main/java/io/bitsquare/gui/util/BSFormatter.java index 2bc5f6de6b..f2d86e4401 100644 --- a/core/src/main/java/io/bitsquare/gui/util/BSFormatter.java +++ b/core/src/main/java/io/bitsquare/gui/util/BSFormatter.java @@ -82,11 +82,11 @@ public class BSFormatter { if (user.currentFiatAccountPropertyProperty().get() == null) setFiatCurrencyCode(CurrencyUtil.getDefaultCurrencyAsCode()); else if (user.currentFiatAccountPropertyProperty().get() != null) - setFiatCurrencyCode(user.currentFiatAccountPropertyProperty().get().getCurrencyCode()); + setFiatCurrencyCode(user.currentFiatAccountPropertyProperty().get().currencyCode); user.currentFiatAccountPropertyProperty().addListener((ov, oldValue, newValue) -> { if (newValue != null) - setFiatCurrencyCode(newValue.getCurrencyCode()); + setFiatCurrencyCode(newValue.currencyCode); }); } @@ -313,7 +313,7 @@ public class BSFormatter { } public String countryLocalesToString(List countries) { - return countries.stream().map(Country::getName).collect(Collectors.joining(", ")); + return countries.stream().map(e-> e.name).collect(Collectors.joining(", ")); } public String arbitratorsToNames(List arbitrators) { diff --git a/core/src/main/java/io/bitsquare/gui/util/ImageUtil.java b/core/src/main/java/io/bitsquare/gui/util/ImageUtil.java index 390331ce39..6fd7496b2b 100644 --- a/core/src/main/java/io/bitsquare/gui/util/ImageUtil.java +++ b/core/src/main/java/io/bitsquare/gui/util/ImageUtil.java @@ -50,10 +50,10 @@ public class ImageUtil { public static ImageView getCountryIconImageView(Country country) { try { - return ImageUtil.getImageViewByUrl("/images/countries/" + country.getCode().toLowerCase() + ".png"); + return ImageUtil.getImageViewByUrl("/images/countries/" + country.code.toLowerCase() + ".png"); } catch (Exception e) { - log.error("Country icon not found URL = /images/countries/" + country.getCode().toLowerCase() + - ".png / country name = " + country.getName()); + log.error("Country icon not found URL = /images/countries/" + country.code.toLowerCase() + + ".png / country name = " + country.name); return null; } } diff --git a/core/src/main/java/io/bitsquare/gui/util/validation/FiatValidator.java b/core/src/main/java/io/bitsquare/gui/util/validation/FiatValidator.java index 022404a9c4..3cdb67564b 100644 --- a/core/src/main/java/io/bitsquare/gui/util/validation/FiatValidator.java +++ b/core/src/main/java/io/bitsquare/gui/util/validation/FiatValidator.java @@ -42,11 +42,11 @@ public final class FiatValidator extends NumberValidator { if (user.currentFiatAccountPropertyProperty().get() == null) setFiatCurrencyCode(CurrencyUtil.getDefaultCurrencyAsCode()); else if (user.currentFiatAccountPropertyProperty().get() != null) - setFiatCurrencyCode(user.currentFiatAccountPropertyProperty().get().getCurrencyCode()); + setFiatCurrencyCode(user.currentFiatAccountPropertyProperty().get().currencyCode); user.currentFiatAccountPropertyProperty().addListener((ov, oldValue, newValue) -> { if (newValue != null) - setFiatCurrencyCode(newValue.getCurrencyCode()); + setFiatCurrencyCode(newValue.currencyCode); }); } } diff --git a/core/src/main/java/io/bitsquare/gui/util/validation/OptionalFiatValidator.java b/core/src/main/java/io/bitsquare/gui/util/validation/OptionalFiatValidator.java index c1f301e19e..45001f3a2e 100644 --- a/core/src/main/java/io/bitsquare/gui/util/validation/OptionalFiatValidator.java +++ b/core/src/main/java/io/bitsquare/gui/util/validation/OptionalFiatValidator.java @@ -42,11 +42,11 @@ public final class OptionalFiatValidator extends NumberValidator { if (user.currentFiatAccountPropertyProperty().get() == null) setFiatCurrencyCode(CurrencyUtil.getDefaultCurrencyAsCode()); else if (user.currentFiatAccountPropertyProperty().get() != null) - setFiatCurrencyCode(user.currentFiatAccountPropertyProperty().get().getCurrencyCode()); + setFiatCurrencyCode(user.currentFiatAccountPropertyProperty().get().currencyCode); user.currentFiatAccountPropertyProperty().addListener((ov, oldValue, newValue) -> { if (newValue != null) - setFiatCurrencyCode(newValue.getCurrencyCode()); + setFiatCurrencyCode(newValue.currencyCode); }); } } diff --git a/core/src/main/java/io/bitsquare/locale/Country.java b/core/src/main/java/io/bitsquare/locale/Country.java index 2cfadad016..6d647819df 100644 --- a/core/src/main/java/io/bitsquare/locale/Country.java +++ b/core/src/main/java/io/bitsquare/locale/Country.java @@ -19,8 +19,6 @@ package io.bitsquare.locale; import java.io.Serializable; -import java.util.Objects; - import javax.annotation.concurrent.Immutable; @Immutable @@ -28,9 +26,9 @@ public class Country implements Serializable { // That object is sent over the wire, so we need to take care of version compatibility. private static final long serialVersionUID = 1L; - private final String code; - private final String name; - private final Region region; + public final String code; + public final String name; + public final Region region; public Country(String code, String name, Region region) { this.code = code; @@ -38,40 +36,33 @@ public class Country implements Serializable { this.region = region; } - public String getCode() { - return code; - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; - public String getName() { - return name; - } + Country country = (Country) o; + + if (code != null ? !code.equals(country.code) : country.code != null) return false; + if (name != null ? !name.equals(country.name) : country.name != null) return false; + return !(region != null ? !region.equals(country.region) : country.region != null); - public Region getRegion() { - return region; } @Override public int hashCode() { - return Objects.hashCode(code); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Country)) { - return false; - } - if (obj == this) { - return true; - } - - final Country other = (Country) obj; - return code.equals(other.getCode()); + int result = code != null ? code.hashCode() : 0; + result = 31 * result + (name != null ? name.hashCode() : 0); + result = 31 * result + (region != null ? region.hashCode() : 0); + return result; } @Override public String toString() { - return "code='" + code + '\'' + + return "Country{" + + "code='" + code + '\'' + ", name='" + name + '\'' + - ", getRegion='" + region; + ", region=" + region + + '}'; } } diff --git a/core/src/main/java/io/bitsquare/locale/CountryUtil.java b/core/src/main/java/io/bitsquare/locale/CountryUtil.java index 82350b5ff6..1c48802cca 100644 --- a/core/src/main/java/io/bitsquare/locale/CountryUtil.java +++ b/core/src/main/java/io/bitsquare/locale/CountryUtil.java @@ -76,7 +76,7 @@ public class CountryUtil { public static List getAllCountriesFor(Region selectedRegion) { return Lists.newArrayList(Collections2.filter(getAllCountries(), country -> - selectedRegion != null && country != null && selectedRegion.equals(country.getRegion()))); + selectedRegion != null && country != null && selectedRegion.equals(country.region))); } public static Country getDefaultCountry() { diff --git a/core/src/main/java/io/bitsquare/locale/Region.java b/core/src/main/java/io/bitsquare/locale/Region.java index 1470825ee2..70a2879bd8 100644 --- a/core/src/main/java/io/bitsquare/locale/Region.java +++ b/core/src/main/java/io/bitsquare/locale/Region.java @@ -19,8 +19,6 @@ package io.bitsquare.locale; import java.io.Serializable; -import java.util.Objects; - import javax.annotation.concurrent.Immutable; @Immutable @@ -28,43 +26,38 @@ public class Region implements Serializable { // That object is sent over the wire, so we need to take care of version compatibility. private static final long serialVersionUID = 1L; - private final String code; - private final String name; + public final String code; + public final String name; public Region(String code, String name) { this.code = code; this.name = name; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Region region = (Region) o; + + if (code != null ? !code.equals(region.code) : region.code != null) return false; + return !(name != null ? !name.equals(region.name) : region.name != null); + + } + + @Override public int hashCode() { - return Objects.hashCode(code); + int result = code != null ? code.hashCode() : 0; + result = 31 * result + (name != null ? name.hashCode() : 0); + return result; } - public boolean equals(Object obj) { - if (!(obj instanceof Region)) { - return false; - } - if (obj == this) { - return true; - } - - Region other = (Region) obj; - return code.equals(other.getCode()); - } - - - public String getCode() { - return code; - } - - public String getName() { - return name; - } - - @Override public String toString() { - return "regionCode='" + code + '\'' + - ", continentName='" + name; + return "Region{" + + "code='" + code + '\'' + + ", name='" + name + '\'' + + '}'; } } diff --git a/core/src/main/java/io/bitsquare/offer/Offer.java b/core/src/main/java/io/bitsquare/offer/Offer.java index 456c4af5ec..a355617e73 100644 --- a/core/src/main/java/io/bitsquare/offer/Offer.java +++ b/core/src/main/java/io/bitsquare/offer/Offer.java @@ -18,7 +18,7 @@ package io.bitsquare.offer; import io.bitsquare.btc.Restrictions; -import io.bitsquare.fiat.FiatAccountType; +import io.bitsquare.fiat.FiatAccount; import io.bitsquare.locale.Country; import org.bitcoinj.core.Coin; @@ -70,7 +70,7 @@ public class Offer implements Serializable { private final Coin amount; private final Coin minAmount; private final PublicKey p2pSigPubKey; - private final FiatAccountType fiatAccountType; + private final FiatAccount.Type fiatAccountType; private final Country bankAccountCountry; private final Coin securityDeposit; @@ -98,7 +98,7 @@ public class Offer implements Serializable { long fiatPrice, Coin amount, Coin minAmount, - FiatAccountType fiatAccountType, + FiatAccount.Type fiatAccountType, String currencyCode, Country bankAccountCountry, String bankAccountUID, @@ -217,7 +217,7 @@ public class Offer implements Serializable { return direction == Direction.BUY ? Direction.SELL : Direction.BUY; } - public FiatAccountType getFiatAccountType() { + public FiatAccount.Type getFiatAccountType() { return fiatAccountType; } diff --git a/core/src/main/java/io/bitsquare/offer/OfferBook.java b/core/src/main/java/io/bitsquare/offer/OfferBook.java index 7bdff6738e..d2c11ef6e4 100644 --- a/core/src/main/java/io/bitsquare/offer/OfferBook.java +++ b/core/src/main/java/io/bitsquare/offer/OfferBook.java @@ -137,8 +137,8 @@ public class OfferBook { private void setBankAccount(FiatAccount fiatAccount) { log.debug("setBankAccount " + fiatAccount); if (fiatAccount != null) { - country = fiatAccount.getCountry(); - fiatCode = fiatAccount.getCurrencyCode(); + country = fiatAccount.country; + fiatCode = fiatAccount.currencyCode; // TODO check why that was used (probably just for update triggering, if so refactor that) //offerBookListItems.stream().forEach(e -> e.setBankAccountCountry(country)); diff --git a/core/src/main/java/io/bitsquare/trade/Contract.java b/core/src/main/java/io/bitsquare/trade/Contract.java index 0888a06579..cf3fd25778 100644 --- a/core/src/main/java/io/bitsquare/trade/Contract.java +++ b/core/src/main/java/io/bitsquare/trade/Contract.java @@ -34,15 +34,15 @@ public class Contract implements Serializable { // That object is sent over the wire, so we need to take care of version compatibility. private static final long serialVersionUID = 1L; - private final Offer offer; - private final String takeOfferFeeTxID; - private final Coin tradeAmount; - private final String offererAccountID; - private final String takerAccountID; - private final FiatAccount offererFiatAccount; - private final FiatAccount takerFiatAccount; - private final String offererP2PSigPubKeyAsString; - private final String takerP2PSigPubKeyAsString; + public final Offer offer; + public final String takeOfferFeeTxID; + public final Coin tradeAmount; + public final String offererAccountID; + public final String takerAccountID; + public final FiatAccount offererFiatAccount; + public final FiatAccount takerFiatAccount; + public final String offererP2PSigPubKeyAsString; + public final String takerP2PSigPubKeyAsString; public Contract(Offer offer, Coin tradeAmount, @@ -64,47 +64,6 @@ public class Contract implements Serializable { this.takerP2PSigPubKeyAsString = Utilities.getHexFromPubKey(takerP2PSigPubKey); } - - /////////////////////////////////////////////////////////////////////////////////////////// - // Getters - /////////////////////////////////////////////////////////////////////////////////////////// - - public Offer getOffer() { - return offer; - } - - public String getTakeOfferFeeTxID() { - return takeOfferFeeTxID; - } - - public Coin getTradeAmount() { - return tradeAmount; - } - - public String getOffererAccountID() { - return offererAccountID; - } - - public String getTakerAccountID() { - return takerAccountID; - } - - public FiatAccount getOffererFiatAccount() { - return offererFiatAccount; - } - - public FiatAccount getTakerFiatAccount() { - return takerFiatAccount; - } - - public String getTakerMessagePublicKey() { - return takerP2PSigPubKeyAsString; - } - - public String getOffererMessagePublicKey() { - return offererP2PSigPubKeyAsString; - } - @Override public String toString() { return "Contract{" + @@ -113,10 +72,10 @@ public class Contract implements Serializable { ", tradeAmount=" + tradeAmount + ", offererAccountID='" + offererAccountID + '\'' + ", takerAccountID='" + takerAccountID + '\'' + - ", offererBankAccount=" + offererFiatAccount + - ", takerBankAccount=" + takerFiatAccount + - ", takerP2PSigPubKeyAsString=" + takerP2PSigPubKeyAsString + - ", offererP2PSigPubKeyAsString=" + offererP2PSigPubKeyAsString + + ", offererFiatAccount=" + offererFiatAccount + + ", takerFiatAccount=" + takerFiatAccount + + ", offererP2PSigPubKeyAsString='" + offererP2PSigPubKeyAsString + '\'' + + ", takerP2PSigPubKeyAsString='" + takerP2PSigPubKeyAsString + '\'' + '}'; } } diff --git a/core/src/main/java/io/bitsquare/trade/TradeManager.java b/core/src/main/java/io/bitsquare/trade/TradeManager.java index 10b213e3d6..47c9d10fe5 100644 --- a/core/src/main/java/io/bitsquare/trade/TradeManager.java +++ b/core/src/main/java/io/bitsquare/trade/TradeManager.java @@ -172,10 +172,10 @@ public class TradeManager { price.getValue(), amount, minAmount, - currentFiatAccount.getFiatAccountType(), - currentFiatAccount.getCurrencyCode(), - currentFiatAccount.getCountry(), - currentFiatAccount.getId(), + currentFiatAccount.type, + currentFiatAccount.currencyCode, + currentFiatAccount.country, + currentFiatAccount.id, accountSettings.getAcceptedArbitratorIds(), accountSettings.getSecurityDeposit(), accountSettings.getAcceptedCountries(), diff --git a/core/src/main/java/io/bitsquare/user/User.java b/core/src/main/java/io/bitsquare/user/User.java index 920700df77..3b0aba5181 100644 --- a/core/src/main/java/io/bitsquare/user/User.java +++ b/core/src/main/java/io/bitsquare/user/User.java @@ -181,7 +181,7 @@ public class User implements Serializable { public FiatAccount getFiatAccount(String fiatAccountId) { for (FiatAccount fiatAccount : fiatAccountsObservableList) { - if (fiatAccount.getId().equals(fiatAccountId)) { + if (fiatAccount.id.equals(fiatAccountId)) { return fiatAccount; } } diff --git a/core/src/test/java/io/bitsquare/gui/main/trade/createoffer/CreateOfferViewModelTest.java b/core/src/test/java/io/bitsquare/gui/main/trade/createoffer/CreateOfferViewModelTest.java index 48a98fd782..e99009a75e 100644 --- a/core/src/test/java/io/bitsquare/gui/main/trade/createoffer/CreateOfferViewModelTest.java +++ b/core/src/test/java/io/bitsquare/gui/main/trade/createoffer/CreateOfferViewModelTest.java @@ -17,7 +17,7 @@ package io.bitsquare.gui.main.trade.createoffer; -import io.bitsquare.fiat.FiatAccountType; +import io.bitsquare.fiat.FiatAccount; import io.bitsquare.gui.util.BSFormatter; import io.bitsquare.gui.util.validation.BtcValidator; import io.bitsquare.gui.util.validation.FiatValidator; @@ -97,10 +97,10 @@ public class CreateOfferViewModelTest { assertEquals(Fiat.valueOf("USD", 9999900), model.volumeAsFiat.get()); - model.bankAccountType.set(FiatAccountType.SEPA.toString()); + model.bankAccountType.set(FiatAccount.Type.SEPA.toString()); assertEquals("Sepa", presenter.bankAccountType.get()); - model.bankAccountType.set(FiatAccountType.WIRE.toString()); + model.bankAccountType.set(FiatAccount.Type.WIRE.toString()); assertEquals("Wire", presenter.bankAccountType.get());