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,14 +197,21 @@ public enum BitcoinNetwork implements Network {
|
||||||
* @return An {@code Optional} containing the matching enum or empty
|
* @return An {@code Optional} containing the matching enum or empty
|
||||||
*/
|
*/
|
||||||
public static Optional<BitcoinNetwork> fromIdString(String idString) {
|
public static Optional<BitcoinNetwork> fromIdString(String idString) {
|
||||||
return Arrays.stream(values())
|
return stream()
|
||||||
.filter(n -> n.id.equals(idString))
|
.filter(n -> n.id.equals(idString))
|
||||||
.findFirst();
|
.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
|
// Create a Map that maps name Strings to networks for all instances
|
||||||
private static Map<String, BitcoinNetwork> mergedNameMap() {
|
private static Map<String, BitcoinNetwork> mergedNameMap() {
|
||||||
return Stream.of(values())
|
return stream()
|
||||||
.collect(HashMap::new, // Supply HashMaps as mutable containers
|
.collect(HashMap::new, // Supply HashMaps as mutable containers
|
||||||
BitcoinNetwork::accumulateNames, // Accumulate one network into hashmap
|
BitcoinNetwork::accumulateNames, // Accumulate one network into hashmap
|
||||||
Map::putAll); // Combine two containers
|
Map::putAll); // Combine two containers
|
||||||
|
|
Loading…
Add table
Reference in a new issue