From c7290ee091d19f103f10d757023f8263af9772a8 Mon Sep 17 00:00:00 2001 From: Deus Max Date: Wed, 2 Dec 2020 18:09:03 +0200 Subject: [PATCH] Replace use of Collections to FXCollections in desktop. Replace use of java library java.util.Collections with javafx.collections.FXCollections instead. Bisq issue#4388. --- .../skin/StaticProgressIndicatorSkin.java | 18 +++---- .../market/offerbook/OfferBookChartView.java | 5 +- .../market/trades/TradesChartsViewModel.java | 14 ++--- .../main/overlays/windows/FilterWindow.java | 5 +- .../settings/preferences/PreferencesView.java | 5 +- .../bisq/desktop/util/AxisInlierUtils.java | 4 +- .../DisplayedTransactionsTest.java | 4 +- .../offerbook/OfferBookViewModelTest.java | 53 +++++++++---------- 8 files changed, 54 insertions(+), 54 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/components/indicator/skin/StaticProgressIndicatorSkin.java b/desktop/src/main/java/bisq/desktop/components/indicator/skin/StaticProgressIndicatorSkin.java index d7cd410ca6c..343bb0a567f 100644 --- a/desktop/src/main/java/bisq/desktop/components/indicator/skin/StaticProgressIndicatorSkin.java +++ b/desktop/src/main/java/bisq/desktop/components/indicator/skin/StaticProgressIndicatorSkin.java @@ -75,8 +75,10 @@ import javafx.beans.property.IntegerProperty; import javafx.beans.property.ObjectProperty; +import javafx.collections.ObservableList; +import javafx.collections.FXCollections; + import java.util.ArrayList; -import java.util.Collections; import java.util.List; // TODO Copied form OpenJFX, check license issues and way how we integrated it @@ -261,7 +263,7 @@ public StaticProgressIndicatorSkin(TxConfidenceIndicator control) { * CssMetaData of its super classes. */ @SuppressWarnings("SameReturnValue") - public static List> getClassCssMetaData() { + public static ObservableList> getClassCssMetaData() { return StyleableProperties.STYLEABLES; } @@ -316,7 +318,7 @@ public Paint getProgressColor() { * {@inheritDoc} */ @Override - public List> getCssMetaData() { + public ObservableList> getCssMetaData() { return getClassCssMetaData(); } @@ -691,7 +693,7 @@ protected void layoutChildren() { */ @SuppressWarnings({"deprecation", "unchecked", "ConstantConditions"}) private static class StyleableProperties { - static final List> STYLEABLES; + static final ObservableList> STYLEABLES; private static final CssMetaData PROGRESS_COLOR = new CssMetaData<>( @@ -746,7 +748,6 @@ public boolean isSettable(TxConfidenceIndicator node) { return skin.spinEnabled == null || !skin.spinEnabled.isBound(); } - @Override public StyleableProperty getStyleableProperty(TxConfidenceIndicator node) { final StaticProgressIndicatorSkin skin = (StaticProgressIndicatorSkin) node.getSkin(); @@ -755,13 +756,12 @@ public StyleableProperty getStyleableProperty(TxConfidenceIndicator nod }; static { - final List> styleables = - new ArrayList<>(SkinBase.getClassCssMetaData()); + final ObservableList> styleables = + FXCollections.observableArrayList(SkinBase.getClassCssMetaData()); styleables.add(PROGRESS_COLOR); styleables.add(INDETERMINATE_SEGMENT_COUNT); styleables.add(SPIN_ENABLED); - STYLEABLES = Collections.unmodifiableList(styleables); + STYLEABLES = FXCollections.unmodifiableObservableList(styleables); } } - } diff --git a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java index e79b701f324..29a87c9ac24 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java +++ b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java @@ -93,7 +93,6 @@ import javafx.util.Callback; import javafx.util.StringConverter; -import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.function.Function; @@ -668,12 +667,12 @@ public void updateItem(final OfferListItem newItem, boolean empty) { private void reverseTableColumns() { ObservableList> columns = FXCollections.observableArrayList(buyOfferTableView.getColumns()); buyOfferTableView.getColumns().clear(); - Collections.reverse(columns); + FXCollections.reverse(columns); buyOfferTableView.getColumns().addAll(columns); columns = FXCollections.observableArrayList(sellOfferTableView.getColumns()); sellOfferTableView.getColumns().clear(); - Collections.reverse(columns); + FXCollections.reverse(columns); sellOfferTableView.getColumns().addAll(columns); } diff --git a/desktop/src/main/java/bisq/desktop/main/market/trades/TradesChartsViewModel.java b/desktop/src/main/java/bisq/desktop/main/market/trades/TradesChartsViewModel.java index 831f5551a64..0e67d26b025 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/trades/TradesChartsViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/market/trades/TradesChartsViewModel.java @@ -65,7 +65,6 @@ import java.time.temporal.ChronoUnit; import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.HashMap; @@ -292,7 +291,7 @@ CandleData getCandleData(long tick, Set set) { long accumulatedVolume = 0; long accumulatedAmount = 0; long numTrades = set.size(); - List tradePrices = new ArrayList<>(set.size()); + ObservableList tradePrices = FXCollections.observableArrayList(); for (TradeStatistics3 item : set) { long tradePriceAsLong = item.getTradePrice().getValue(); @@ -304,13 +303,14 @@ CandleData getCandleData(long tick, Set set) { accumulatedAmount += item.getTradeAmount().getValue(); tradePrices.add(item.getTradePrice().getValue()); } - Collections.sort(tradePrices); + FXCollections.sort(tradePrices); List list = new ArrayList<>(set); - list.sort(Comparator.comparingLong(TradeStatistics3::getDateAsLong)); - if (list.size() > 0) { - open = list.get(0).getTradePrice().getValue(); - close = list.get(list.size() - 1).getTradePrice().getValue(); + ObservableList obsList = FXCollections.observableArrayList(list); + obsList.sort(Comparator.comparingLong(TradeStatistics3::getDateAsLong)); + if (obsList.size() > 0) { + open = obsList.get(0).getTradePrice().getValue(); + close = obsList.get(obsList.size() - 1).getTradePrice().getValue(); } long averagePrice; diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/windows/FilterWindow.java b/desktop/src/main/java/bisq/desktop/main/overlays/windows/FilterWindow.java index 167c4e6bd9f..a82f00d02b7 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/windows/FilterWindow.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/windows/FilterWindow.java @@ -37,6 +37,8 @@ import org.apache.commons.lang3.StringUtils; +import javafx.collections.FXCollections; + import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; @@ -50,7 +52,6 @@ import javafx.geometry.Insets; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -294,7 +295,7 @@ private void setupFieldFromPaymentAccountFiltersList(InputTextField field, List< private List readAsList(InputTextField field) { if (field.getText().isEmpty()) { - return Collections.emptyList(); + return FXCollections.emptyObservableList(); } else { return Arrays.asList(StringUtils.deleteWhitespace(field.getText()).split(",")); } diff --git a/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java b/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java index ed2ac501d05..8d000b3139b 100644 --- a/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java +++ b/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java @@ -99,7 +99,6 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; @@ -416,9 +415,9 @@ public TradeCurrency fromString(String string) { }); preferredTradeCurrencyComboBox.setButtonCell(GUIUtil.getTradeCurrencyButtonCell("", "", - Collections.emptyMap())); + FXCollections.emptyObservableMap())); preferredTradeCurrencyComboBox.setCellFactory(GUIUtil.getTradeCurrencyCellFactory("", "", - Collections.emptyMap())); + FXCollections.emptyObservableMap())); Tuple3, VBox> fiatTuple = addTopLabelListView(root, displayCurrenciesGridRowIndex, Res.get("setting.preferences.displayFiat")); diff --git a/desktop/src/main/java/bisq/desktop/util/AxisInlierUtils.java b/desktop/src/main/java/bisq/desktop/util/AxisInlierUtils.java index d80d79a009b..66e1c6f2dc5 100644 --- a/desktop/src/main/java/bisq/desktop/util/AxisInlierUtils.java +++ b/desktop/src/main/java/bisq/desktop/util/AxisInlierUtils.java @@ -25,8 +25,8 @@ import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; +import javafx.collections.FXCollections; -import java.util.Collections; import java.util.DoubleSummaryStatistics; import java.util.List; import java.util.stream.Collectors; @@ -171,7 +171,7 @@ private static List trim(double percentToTrim, List numbers) { return numbers; } if (totalPercentTrim == 100) { - return Collections.emptyList(); + return FXCollections.emptyObservableList(); } if (numbers.isEmpty()) { diff --git a/desktop/src/test/java/bisq/desktop/main/funds/transactions/DisplayedTransactionsTest.java b/desktop/src/test/java/bisq/desktop/main/funds/transactions/DisplayedTransactionsTest.java index 1bc407f5c38..09c84516b73 100644 --- a/desktop/src/test/java/bisq/desktop/main/funds/transactions/DisplayedTransactionsTest.java +++ b/desktop/src/test/java/bisq/desktop/main/funds/transactions/DisplayedTransactionsTest.java @@ -23,6 +23,8 @@ import com.google.common.collect.Sets; +import javafx.collections.FXCollections; + import java.util.Collections; import java.util.Set; @@ -61,7 +63,7 @@ public void testUpdateWhenRepositoryIsEmpty() { .thenReturn(Collections.singleton(mock(Transaction.class))); TradableRepository tradableRepository = mock(TradableRepository.class); - when(tradableRepository.getAll()).thenReturn(Collections.emptySet()); + when(tradableRepository.getAll()).thenReturn(FXCollections.emptyObservableSet()); TransactionListItemFactory transactionListItemFactory = mock(TransactionListItemFactory.class); diff --git a/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java b/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java index 9cd74e457fb..3c75ba5f18f 100644 --- a/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java +++ b/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java @@ -57,7 +57,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -94,7 +93,7 @@ public void setUp() { @Ignore("PaymentAccountPayload needs to be set (has been changed with PB changes)") public void testIsAnyPaymentAccountValidForOffer() { Collection paymentAccounts; - paymentAccounts = new ArrayList<>(Collections.singletonList(getSepaAccount("EUR", "DE", "1212324", + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getSepaAccount("EUR", "DE", "1212324", new ArrayList<>(Arrays.asList("AT", "DE"))))); assertTrue(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getSEPAPaymentMethod("EUR", "AT", new ArrayList<>(Arrays.asList("AT", "DE")), "PSK"), paymentAccounts)); @@ -108,33 +107,33 @@ public void testIsAnyPaymentAccountValidForOffer() { // simple cases: same payment methods // offer: alipay paymentAccount: alipay - same country, same currency - paymentAccounts = new ArrayList<>(Collections.singletonList(getAliPayAccount("CNY"))); + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getAliPayAccount("CNY"))); assertTrue(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getAliPayPaymentMethod("EUR"), paymentAccounts)); // offer: ether paymentAccount: ether - same country, same currency - paymentAccounts = new ArrayList<>(Collections.singletonList(getCryptoAccount("ETH"))); + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getCryptoAccount("ETH"))); assertTrue(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getBlockChainsPaymentMethod("ETH"), paymentAccounts)); // offer: sepa paymentAccount: sepa - same country, same currency - paymentAccounts = new ArrayList<>(Collections.singletonList(getSepaAccount("EUR", "AT", "1212324", + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getSepaAccount("EUR", "AT", "1212324", new ArrayList<>(Arrays.asList("AT", "DE"))))); assertTrue(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getSEPAPaymentMethod("EUR", "AT", new ArrayList<>(Arrays.asList("AT", "DE")), "PSK"), paymentAccounts)); // offer: nationalBank paymentAccount: nationalBank - same country, same currency - paymentAccounts = new ArrayList<>(Collections.singletonList(getNationalBankAccount("EUR", "AT", "PSK"))); + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getNationalBankAccount("EUR", "AT", "PSK"))); assertTrue(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts)); // offer: SameBank paymentAccount: SameBank - same country, same currency - paymentAccounts = new ArrayList<>(Collections.singletonList(getSameBankAccount("EUR", "AT", "PSK"))); + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getSameBankAccount("EUR", "AT", "PSK"))); assertTrue(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getSameBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts)); // offer: sepa paymentAccount: sepa - diff. country, same currency - paymentAccounts = new ArrayList<>(Collections.singletonList(getSepaAccount("EUR", "DE", "1212324", new ArrayList<>(Arrays.asList("AT", "DE"))))); + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getSepaAccount("EUR", "DE", "1212324", new ArrayList<>(Arrays.asList("AT", "DE"))))); assertTrue(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getSEPAPaymentMethod("EUR", "AT", new ArrayList<>(Arrays.asList("AT", "DE")), "PSK"), paymentAccounts)); @@ -142,78 +141,78 @@ public void testIsAnyPaymentAccountValidForOffer() { ////// // offer: sepa paymentAccount: sepa - same country, same currency - paymentAccounts = new ArrayList<>(Collections.singletonList(getSepaAccount("EUR", "AT", "1212324", new ArrayList<>(Arrays.asList("AT", "DE"))))); + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getSepaAccount("EUR", "AT", "1212324", new ArrayList<>(Arrays.asList("AT", "DE"))))); assertTrue(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getSEPAPaymentMethod("EUR", "AT", new ArrayList<>(Arrays.asList("AT", "DE")), "PSK"), paymentAccounts)); // offer: sepa paymentAccount: nationalBank - same country, same currency // wrong method - paymentAccounts = new ArrayList<>(Collections.singletonList(getNationalBankAccount("EUR", "AT", "PSK"))); + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getNationalBankAccount("EUR", "AT", "PSK"))); assertFalse(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getSEPAPaymentMethod("EUR", "AT", new ArrayList<>(Arrays.asList("AT", "DE")), "PSK"), paymentAccounts)); // wrong currency - paymentAccounts = new ArrayList<>(Collections.singletonList(getNationalBankAccount("USD", "US", "XXX"))); + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getNationalBankAccount("USD", "US", "XXX"))); assertFalse(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts)); // wrong country - paymentAccounts = new ArrayList<>(Collections.singletonList(getNationalBankAccount("EUR", "FR", "PSK"))); + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getNationalBankAccount("EUR", "FR", "PSK"))); assertFalse(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts)); // sepa wrong country - paymentAccounts = new ArrayList<>(Collections.singletonList(getNationalBankAccount("EUR", "CH", "PSK"))); + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getNationalBankAccount("EUR", "CH", "PSK"))); assertFalse(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getSEPAPaymentMethod("EUR", "AT", new ArrayList<>(Arrays.asList("AT", "DE")), "PSK"), paymentAccounts)); // sepa wrong currency - paymentAccounts = new ArrayList<>(Collections.singletonList(getNationalBankAccount("CHF", "DE", "PSK"))); + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getNationalBankAccount("CHF", "DE", "PSK"))); assertFalse(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getSEPAPaymentMethod("EUR", "AT", new ArrayList<>(Arrays.asList("AT", "DE")), "PSK"), paymentAccounts)); // same bank - paymentAccounts = new ArrayList<>(Collections.singletonList(getSameBankAccount("EUR", "AT", "PSK"))); + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getSameBankAccount("EUR", "AT", "PSK"))); assertTrue(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts)); // not same bank - paymentAccounts = new ArrayList<>(Collections.singletonList(getSameBankAccount("EUR", "AT", "Raika"))); + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getSameBankAccount("EUR", "AT", "Raika"))); assertFalse(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts)); // same bank, wrong country - paymentAccounts = new ArrayList<>(Collections.singletonList(getSameBankAccount("EUR", "DE", "PSK"))); + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getSameBankAccount("EUR", "DE", "PSK"))); assertFalse(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts)); // same bank, wrong currency - paymentAccounts = new ArrayList<>(Collections.singletonList(getSameBankAccount("USD", "AT", "PSK"))); + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getSameBankAccount("USD", "AT", "PSK"))); assertFalse(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts)); // spec. bank - paymentAccounts = new ArrayList<>(Collections.singletonList(getSpecificBanksAccount("EUR", "AT", "PSK", + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getSpecificBanksAccount("EUR", "AT", "PSK", new ArrayList<>(Arrays.asList("PSK", "Raika"))))); assertTrue(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts)); // spec. bank, missing bank - paymentAccounts = new ArrayList<>(Collections.singletonList(getSpecificBanksAccount("EUR", "AT", "PSK", - new ArrayList<>(Collections.singletonList("Raika"))))); + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getSpecificBanksAccount("EUR", "AT", "PSK", + new ArrayList<>(FXCollections.singletonObservableList("Raika"))))); assertFalse(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts)); // spec. bank, wrong country - paymentAccounts = new ArrayList<>(Collections.singletonList(getSpecificBanksAccount("EUR", "FR", "PSK", + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getSpecificBanksAccount("EUR", "FR", "PSK", new ArrayList<>(Arrays.asList("PSK", "Raika"))))); assertFalse(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts)); // spec. bank, wrong currency - paymentAccounts = new ArrayList<>(Collections.singletonList(getSpecificBanksAccount("USD", "AT", "PSK", + paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getSpecificBanksAccount("USD", "AT", "PSK", new ArrayList<>(Arrays.asList("PSK", "Raika"))))); assertFalse(PaymentAccountUtil.isAnyTakerPaymentAccountValidForOffer( getNationalBankPaymentMethod("EUR", "AT", "PSK"), paymentAccounts)); @@ -526,7 +525,7 @@ private Offer getNationalBankPaymentMethod(String currencyCode, String countryCo return getPaymentMethod(currencyCode, PaymentMethod.NATIONAL_BANK_ID, countryCode, - new ArrayList<>(Collections.singletonList(countryCode)), + new ArrayList<>(FXCollections.singletonObservableList(countryCode)), bankId, null); } @@ -535,9 +534,9 @@ private Offer getSameBankPaymentMethod(String currencyCode, String countryCode, return getPaymentMethod(currencyCode, PaymentMethod.SAME_BANK_ID, countryCode, - new ArrayList<>(Collections.singletonList(countryCode)), + new ArrayList<>(FXCollections.singletonObservableList(countryCode)), bankId, - new ArrayList<>(Collections.singletonList(bankId))); + new ArrayList<>(FXCollections.singletonObservableList(bankId))); } private Offer getSpecificBanksPaymentMethod(String currencyCode, @@ -547,7 +546,7 @@ private Offer getSpecificBanksPaymentMethod(String currencyCode, return getPaymentMethod(currencyCode, PaymentMethod.SPECIFIC_BANKS_ID, countryCode, - new ArrayList<>(Collections.singletonList(countryCode)), + new ArrayList<>(FXCollections.singletonObservableList(countryCode)), bankId, bankIds); }