Wallet: use List interface where possible

Some local/private/protected declarations were using
`LinkedList` or `ArrayList` when they should be using
the generic `List`.
This commit is contained in:
Sean Gilligan 2023-05-06 11:31:49 -07:00 committed by Andreas Schildbach
parent 7cb61b0399
commit 3a28163d50

View file

@ -2529,7 +2529,7 @@ public class Wallet extends BaseTaggableObject
* as there is no guarantee on the order of the returned txns besides what was already stated. * as there is no guarantee on the order of the returned txns besides what was already stated.
*/ */
List<Transaction> sortTxnsByDependency(Set<Transaction> inputSet) { List<Transaction> sortTxnsByDependency(Set<Transaction> inputSet) {
ArrayList<Transaction> result = new ArrayList<>(inputSet); List<Transaction> result = new ArrayList<>(inputSet);
for (int i = 0; i < result.size()-1; i++) { for (int i = 0; i < result.size()-1; i++) {
boolean txAtISpendsOtherTxInTheList; boolean txAtISpendsOtherTxInTheList;
do { do {
@ -3374,7 +3374,7 @@ public class Wallet extends BaseTaggableObject
if (numTransactions > size || numTransactions == 0) { if (numTransactions > size || numTransactions == 0) {
numTransactions = size; numTransactions = size;
} }
ArrayList<Transaction> all = new ArrayList<>(getTransactions(includeDead)); List<Transaction> all = new ArrayList<>(getTransactions(includeDead));
// Order by update time. // Order by update time.
Collections.sort(all, Transaction.SORT_TX_BY_UPDATE_TIME); Collections.sort(all, Transaction.SORT_TX_BY_UPDATE_TIME);
if (numTransactions == all.size()) { if (numTransactions == all.size()) {
@ -3478,7 +3478,7 @@ public class Wallet extends BaseTaggableObject
lock.lock(); lock.lock();
keyChainGroupLock.lock(); keyChainGroupLock.lock();
try { try {
LinkedList<TransactionOutput> candidates = new LinkedList<>(); List<TransactionOutput> candidates = new LinkedList<>();
for (Transaction tx : Iterables.concat(unspent.values(), pending.values())) { for (Transaction tx : Iterables.concat(unspent.values(), pending.values())) {
if (excludeImmatureCoinbases && !isTransactionMature(tx)) continue; if (excludeImmatureCoinbases && !isTransactionMature(tx)) continue;
for (TransactionOutput output : tx.getOutputs()) { for (TransactionOutput output : tx.getOutputs()) {
@ -4785,10 +4785,10 @@ public class Wallet extends BaseTaggableObject
* Returns the spendable candidates from the {@link UTXOProvider} based on keys that the wallet contains. * Returns the spendable candidates from the {@link UTXOProvider} based on keys that the wallet contains.
* @return The list of candidates. * @return The list of candidates.
*/ */
protected LinkedList<TransactionOutput> calculateAllSpendCandidatesFromUTXOProvider(boolean excludeImmatureCoinbases) { protected List<TransactionOutput> calculateAllSpendCandidatesFromUTXOProvider(boolean excludeImmatureCoinbases) {
checkState(lock.isHeldByCurrentThread()); checkState(lock.isHeldByCurrentThread());
UTXOProvider utxoProvider = Objects.requireNonNull(vUTXOProvider, "No UTXO provider has been set"); UTXOProvider utxoProvider = Objects.requireNonNull(vUTXOProvider, "No UTXO provider has been set");
LinkedList<TransactionOutput> candidates = new LinkedList<>(); List<TransactionOutput> candidates = new LinkedList<>();
try { try {
int chainHeight = utxoProvider.getChainHeadHeight(); int chainHeight = utxoProvider.getChainHeadHeight();
for (UTXO output : getStoredOutputsFromUTXOProvider()) { for (UTXO output : getStoredOutputsFromUTXOProvider()) {
@ -4802,6 +4802,7 @@ public class Wallet extends BaseTaggableObject
} catch (UTXOProviderException e) { } catch (UTXOProviderException e) {
throw new RuntimeException("UTXO provider error", e); throw new RuntimeException("UTXO provider error", e);
} }
// We need to handle the pending transactions that we know about. // We need to handle the pending transactions that we know about.
for (Transaction tx : pending.values()) { for (Transaction tx : pending.values()) {
// Remove the spent outputs. // Remove the spent outputs.
@ -5007,7 +5008,7 @@ public class Wallet extends BaseTaggableObject
Collections.reverse(newBlocks); // Need bottom-to-top but we get top-to-bottom. Collections.reverse(newBlocks); // Need bottom-to-top but we get top-to-bottom.
// For each block in the old chain, disconnect the transactions in reverse order. // For each block in the old chain, disconnect the transactions in reverse order.
LinkedList<Transaction> oldChainTxns = new LinkedList<>(); List<Transaction> oldChainTxns = new LinkedList<>();
for (Sha256Hash blockHash : oldBlockHashes) { for (Sha256Hash blockHash : oldBlockHashes) {
for (TxOffsetPair pair : mapBlockTx.get(blockHash)) { for (TxOffsetPair pair : mapBlockTx.get(blockHash)) {
Transaction tx = pair.tx; Transaction tx = pair.tx;
@ -5122,7 +5123,7 @@ public class Wallet extends BaseTaggableObject
//region Bloom filtering //region Bloom filtering
private final ArrayList<TransactionOutPoint> bloomOutPoints = new ArrayList<>(); private final List<TransactionOutPoint> bloomOutPoints = new ArrayList<>();
// Used to track whether we must automatically begin/end a filter calculation and calc outpoints/take the locks. // Used to track whether we must automatically begin/end a filter calculation and calc outpoints/take the locks.
private final AtomicInteger bloomFilterGuard = new AtomicInteger(0); private final AtomicInteger bloomFilterGuard = new AtomicInteger(0);
@ -5686,7 +5687,7 @@ public class Wallet extends BaseTaggableObject
lock.unlock(); lock.unlock();
} }
checkState(!lock.isHeldByCurrentThread()); checkState(!lock.isHeldByCurrentThread());
ArrayList<CompletableFuture<Transaction>> futures = new ArrayList<>(txns.size()); List<CompletableFuture<Transaction>> futures = new ArrayList<>(txns.size());
TransactionBroadcaster broadcaster = vTransactionBroadcaster; TransactionBroadcaster broadcaster = vTransactionBroadcaster;
for (Transaction tx : txns) { for (Transaction tx : txns) {
try { try {