From 67c76c3b28158e38dbf6a5a3eb49f4a03b01b7b1 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 27 Oct 2020 11:11:15 +0200 Subject: [PATCH] avoid casting to int when comparing longs --- .../java/com/sparrowwallet/drongo/wallet/BnBUtxoSelector.java | 2 +- .../com/sparrowwallet/drongo/wallet/KnapsackUtxoSelector.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/BnBUtxoSelector.java b/src/main/java/com/sparrowwallet/drongo/wallet/BnBUtxoSelector.java index 5132993..c3cacca 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/BnBUtxoSelector.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/BnBUtxoSelector.java @@ -34,7 +34,7 @@ public class BnBUtxoSelector implements UtxoSelector { return Collections.emptyList(); } - utxoPool.sort((a, b) -> (int)(b.getEffectiveValue() - a.getEffectiveValue())); + utxoPool.sort((a, b) -> Long.compare(b.getEffectiveValue(), a.getEffectiveValue())); long currentWasteValue = 0; ArrayDeque bestSelection = null; diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/KnapsackUtxoSelector.java b/src/main/java/com/sparrowwallet/drongo/wallet/KnapsackUtxoSelector.java index 2b02819..93c615f 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/KnapsackUtxoSelector.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/KnapsackUtxoSelector.java @@ -50,7 +50,7 @@ public class KnapsackUtxoSelector implements UtxoSelector { //We now have a list of UTXOs that are all smaller than the target + MIN_CHANGE, but together sum to greater than actualTargetValue // Solve subset sum by stochastic approximation - applicableGroups.sort((a, b) -> (int)(b.getEffectiveValue() - a.getEffectiveValue())); + applicableGroups.sort((a, b) -> Long.compare(b.getEffectiveValue(), a.getEffectiveValue())); boolean[] bestSelection = new boolean[applicableGroups.size()]; long bestValue = findApproximateBestSubset(applicableGroups, totalLower, actualTargetValue, bestSelection);