From 298a75808eaa046dca5c084e7ae66a1cfec1d311 Mon Sep 17 00:00:00 2001 From: Sean Gilligan Date: Mon, 22 Apr 2024 12:39:25 -0700 Subject: [PATCH] BitcoinNetwork: private static `stream()` method Create a private method to stream the `values()` array, as it is used in multiple places. --- .../java/org/bitcoinj/base/BitcoinNetwork.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/base/BitcoinNetwork.java b/core/src/main/java/org/bitcoinj/base/BitcoinNetwork.java index e72dfa09c..a3bb24f57 100644 --- a/core/src/main/java/org/bitcoinj/base/BitcoinNetwork.java +++ b/core/src/main/java/org/bitcoinj/base/BitcoinNetwork.java @@ -197,17 +197,24 @@ public enum BitcoinNetwork implements Network { * @return An {@code Optional} containing the matching enum or empty */ public static Optional fromIdString(String idString) { - return Arrays.stream(values()) + return stream() .filter(n -> n.id.equals(idString)) .findFirst(); } + /** + * @return stream of all instances of this enum + */ + private static Stream stream() { + return Arrays.stream(values()); + } + // Create a Map that maps name Strings to networks for all instances private static Map mergedNameMap() { - return Stream.of(values()) - .collect(HashMap::new, // Supply HashMaps as mutable containers - BitcoinNetwork::accumulateNames, // Accumulate one network into hashmap - Map::putAll); // Combine two containers + return stream() + .collect(HashMap::new, // Supply HashMaps as mutable containers + BitcoinNetwork::accumulateNames, // Accumulate one network into hashmap + Map::putAll); // Combine two containers } // Add allNames for this Network as keys to a map that can be used to find it