From c899466ec426ffa75e3ac585494651681b85bc89 Mon Sep 17 00:00:00 2001 From: gubatron Date: Thu, 14 Jan 2016 17:07:49 -0500 Subject: [PATCH] [refactor] use lambda. --- .../btc/AddressBasedCoinSelector.java | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/io/bitsquare/btc/AddressBasedCoinSelector.java b/core/src/main/java/io/bitsquare/btc/AddressBasedCoinSelector.java index f3c6481f3a..65f675a027 100644 --- a/core/src/main/java/io/bitsquare/btc/AddressBasedCoinSelector.java +++ b/core/src/main/java/io/bitsquare/btc/AddressBasedCoinSelector.java @@ -49,27 +49,24 @@ class AddressBasedCoinSelector implements CoinSelector { @VisibleForTesting static void sortOutputs(ArrayList outputs) { - Collections.sort(outputs, new Comparator() { - @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); }); }