From e52e4d0e721b592d87587fbda9eccbbab41cf5f5 Mon Sep 17 00:00:00 2001 From: Sean Gilligan Date: Tue, 19 Jul 2022 10:05:25 -0700 Subject: [PATCH] CoinSelection: require a List of outputs, rather than a Collection Rationale: * The comment says that it is a "list" * Immutable Lists are the collection that maps most easily/logically to and from Stream * Lists are easier to enforce reproducibility (mainly for unit tests) --- .../main/java/org/bitcoinj/wallet/CoinSelection.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/wallet/CoinSelection.java b/core/src/main/java/org/bitcoinj/wallet/CoinSelection.java index bceba0527..4ed5e3dc7 100644 --- a/core/src/main/java/org/bitcoinj/wallet/CoinSelection.java +++ b/core/src/main/java/org/bitcoinj/wallet/CoinSelection.java @@ -19,6 +19,7 @@ package org.bitcoinj.wallet; import org.bitcoinj.base.Coin; import org.bitcoinj.core.TransactionOutput; +import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -31,23 +32,23 @@ import java.util.List; */ public class CoinSelection { public final Coin valueGathered; - public final Collection gathered; + public final List gathered; - public CoinSelection(Collection gathered) { + public CoinSelection(List gathered) { this.valueGathered = sumOutputValues(gathered); this.gathered = gathered; } /** - * @deprecated use {@link #CoinSelection(Collection)} + * @deprecated use {@link #CoinSelection(List)} */ @Deprecated public CoinSelection(Coin valueGathered, Collection gathered) { // ignore valueGathered - this(gathered); + this(new ArrayList<>(gathered)); } - private static Coin sumOutputValues(Collection outputs) { + private static Coin sumOutputValues(List outputs) { return outputs.stream() .map(TransactionOutput::getValue) .reduce(Coin.ZERO, Coin::add);