[bisq-network/bisq] Secondary sort order for offer book (rewrite) (#4259)

James Cox notifications at github.com
Mon May 25 00:47:16 UTC 2020


@jmacxx requested changes on this pull request.



> @@ -276,22 +276,24 @@ private boolean isAnyPricePresent() {
     }
 
     private void updateChartData() {
+
+        // Offer price can be null (if price feed unavailable), thus a null-tolerant comparator is used.
+        Comparator<Offer> offerPriceComparator = Comparator.comparing(Offer::getPrice, Comparator.nullsLast(Comparator.naturalOrder()));
+        // Offer amounts are used for the secondary sort. They are sorted from high to low.
+        Comparator<Offer> offerAmountComparator = Comparator.comparing(Offer::getAmount).reversed();
+

        boolean isCrypto = CurrencyUtil.isCryptoCurrency(getCurrencyCode());

> @@ -276,22 +276,24 @@ private boolean isAnyPricePresent() {
     }
 
     private void updateChartData() {
+
+        // Offer price can be null (if price feed unavailable), thus a null-tolerant comparator is used.
+        Comparator<Offer> offerPriceComparator = Comparator.comparing(Offer::getPrice, Comparator.nullsLast(Comparator.naturalOrder()));
+        // Offer amounts are used for the secondary sort. They are sorted from high to low.
+        Comparator<Offer> offerAmountComparator = Comparator.comparing(Offer::getAmount).reversed();
+
+        var buyOfferSortComparator =
+            offerPriceComparator.reversed() // Buy offers, as opposed to sell offers, are primarily sorted from high price to low.

            (isCrypto ? offerPriceComparator : offerPriceComparator.reversed()) // Buy offers, as opposed to sell offers, are primarily sorted from high price to low.

> @@ -276,22 +276,24 @@ private boolean isAnyPricePresent() {
     }
 
     private void updateChartData() {
+
+        // Offer price can be null (if price feed unavailable), thus a null-tolerant comparator is used.
+        Comparator<Offer> offerPriceComparator = Comparator.comparing(Offer::getPrice, Comparator.nullsLast(Comparator.naturalOrder()));
+        // Offer amounts are used for the secondary sort. They are sorted from high to low.
+        Comparator<Offer> offerAmountComparator = Comparator.comparing(Offer::getAmount).reversed();
+
+        var buyOfferSortComparator =
+            offerPriceComparator.reversed() // Buy offers, as opposed to sell offers, are primarily sorted from high price to low.
+            .thenComparing(offerAmountComparator);
+        var sellOfferSortComparator =
+            offerPriceComparator

            (isCrypto ? offerPriceComparator.reversed() : offerPriceComparator)

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/bisq-network/bisq/pull/4259#pullrequestreview-417409172
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bisq.network/pipermail/bisq-github/attachments/20200524/fc83093c/attachment.html>


More information about the bisq-github mailing list