forked from PegaSysEng/pantheon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/move subclass in pantheon command (PegaSysEng#1272)
* clean PantheonCommand class - organize imports - move `RpcApisConverter` and `RpcApisConversionException` to separate files * spotlessApply * register converters * Revert "register converters" This reverts commit aec4735.
- Loading branch information
1 parent
33ccff1
commit 4cf8e91
Showing
3 changed files
with
62 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/RpcApisConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.cli.converter; | ||
|
||
import tech.pegasys.pantheon.cli.converter.exception.RpcApisConversionException; | ||
import tech.pegasys.pantheon.consensus.clique.jsonrpc.CliqueRpcApis; | ||
import tech.pegasys.pantheon.consensus.ibft.jsonrpc.IbftRpcApis; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Function; | ||
import java.util.stream.Stream; | ||
|
||
import picocli.CommandLine; | ||
|
||
public class RpcApisConverter implements CommandLine.ITypeConverter<RpcApi> { | ||
|
||
@Override | ||
public RpcApi convert(final String name) throws RpcApisConversionException { | ||
return Stream.<Function<String, Optional<RpcApi>>>of( | ||
RpcApis::valueOf, CliqueRpcApis::valueOf, IbftRpcApis::valueOf) | ||
.map(f -> f.apply(name.trim().toUpperCase())) | ||
.filter(Optional::isPresent) | ||
.map(Optional::get) | ||
.findFirst() | ||
.orElseThrow(() -> new RpcApisConversionException(name)); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...c/main/java/tech/pegasys/pantheon/cli/converter/exception/RpcApisConversionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.cli.converter.exception; | ||
|
||
import static java.lang.String.format; | ||
|
||
public final class RpcApisConversionException extends Exception { | ||
|
||
public RpcApisConversionException(final String name) { | ||
super(format("Invalid value: %s", name)); | ||
} | ||
} |