mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 09:20:04 +01:00
BitcoinNetwork: private static stream()
method
Create a private method to stream the `values()` array, as it is used in multiple places.
This commit is contained in:
parent
ffcd879208
commit
298a75808e
1 changed files with 12 additions and 5 deletions
|
@ -197,17 +197,24 @@ public enum BitcoinNetwork implements Network {
|
|||
* @return An {@code Optional} containing the matching enum or empty
|
||||
*/
|
||||
public static Optional<BitcoinNetwork> 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<BitcoinNetwork> stream() {
|
||||
return Arrays.stream(values());
|
||||
}
|
||||
|
||||
// Create a Map that maps name Strings to networks for all instances
|
||||
private static Map<String, BitcoinNetwork> 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
|
||||
|
|
Loading…
Add table
Reference in a new issue