mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-14 17:35:27 -04:00
[refactor] use lambda.
This commit is contained in:
parent
088334014c
commit
c899466ec4
1 changed files with 18 additions and 21 deletions
|
@ -49,27 +49,24 @@ class AddressBasedCoinSelector implements CoinSelector {
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static void sortOutputs(ArrayList<TransactionOutput> outputs) {
|
static void sortOutputs(ArrayList<TransactionOutput> outputs) {
|
||||||
Collections.sort(outputs, new Comparator<TransactionOutput>() {
|
Collections.sort(outputs, (a, b) -> {
|
||||||
@Override
|
int depth1 = a.getParentTransactionDepthInBlocks();
|
||||||
public int compare(TransactionOutput a, TransactionOutput b) {
|
int depth2 = b.getParentTransactionDepthInBlocks();
|
||||||
int depth1 = a.getParentTransactionDepthInBlocks();
|
Coin aValue = a.getValue();
|
||||||
int depth2 = b.getParentTransactionDepthInBlocks();
|
Coin bValue = b.getValue();
|
||||||
Coin aValue = a.getValue();
|
BigInteger aCoinDepth = BigInteger.valueOf(aValue.value).multiply(BigInteger.valueOf(depth1));
|
||||||
Coin bValue = b.getValue();
|
BigInteger bCoinDepth = BigInteger.valueOf(bValue.value).multiply(BigInteger.valueOf(depth2));
|
||||||
BigInteger aCoinDepth = BigInteger.valueOf(aValue.value).multiply(BigInteger.valueOf(depth1));
|
int c1 = bCoinDepth.compareTo(aCoinDepth);
|
||||||
BigInteger bCoinDepth = BigInteger.valueOf(bValue.value).multiply(BigInteger.valueOf(depth2));
|
if (c1 != 0) return c1;
|
||||||
int c1 = bCoinDepth.compareTo(aCoinDepth);
|
// The "coin*days" destroyed are equal, sort by value alone to get the lowest transaction size.
|
||||||
if (c1 != 0) return c1;
|
int c2 = bValue.compareTo(aValue);
|
||||||
// The "coin*days" destroyed are equal, sort by value alone to get the lowest transaction size.
|
if (c2 != 0) return c2;
|
||||||
int c2 = bValue.compareTo(aValue);
|
// They are entirely equivalent (possibly pending) so sort by hash to ensure a total ordering.
|
||||||
if (c2 != 0) return c2;
|
checkNotNull(a.getParentTransactionHash(), "a.getParentTransactionHash() must not be null");
|
||||||
// They are entirely equivalent (possibly pending) so sort by hash to ensure a total ordering.
|
checkNotNull(b.getParentTransactionHash(), "b.getParentTransactionHash() must not be null");
|
||||||
checkNotNull(a.getParentTransactionHash(), "a.getParentTransactionHash() must not be null");
|
BigInteger aHash = a.getParentTransactionHash().toBigInteger();
|
||||||
checkNotNull(b.getParentTransactionHash(), "b.getParentTransactionHash() must not be null");
|
BigInteger bHash = b.getParentTransactionHash().toBigInteger();
|
||||||
BigInteger aHash = a.getParentTransactionHash().toBigInteger();
|
return aHash.compareTo(bHash);
|
||||||
BigInteger bHash = b.getParentTransactionHash().toBigInteger();
|
|
||||||
return aHash.compareTo(bHash);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue