Use #ofType in commandline parsing for type safety

- Remove Node#getPortAsString; it is now no longer necessary
This commit is contained in:
Chris Beams 2014-11-13 10:25:50 +01:00
parent 0e167bed6c
commit 8d70e23ba5
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
5 changed files with 6 additions and 10 deletions

View File

@ -32,8 +32,8 @@ public class BootstrapNodeMain extends BitsquareExecutable {
protected void customizeOptionParsing(OptionParser parser) {
parser.accepts(Node.NAME_KEY, "Name of this node").withRequiredArg().isRequired();
parser.accepts(Node.PORT_KEY, "Port to listen on").withRequiredArg()
.defaultsTo(String.valueOf(Node.DEFAULT_PORT));
parser.accepts(Node.PORT_KEY, "Port to listen on").withRequiredArg().ofType(int.class)
.defaultsTo(Node.DEFAULT_PORT);
}
protected void doExecute(OptionSet options) {

View File

@ -44,11 +44,12 @@ public class BitsquareAppMain extends BitsquareExecutable {
parser.accepts(APP_DATA_DIR_KEY, "Application data directory").withRequiredArg()
.defaultsTo(DEFAULT_APP_DATA_DIR);
parser.accepts(NAME_KEY, "Name of this node").withRequiredArg();
parser.accepts(PORT_KEY, "Port to listen on").withRequiredArg().defaultsTo(String.valueOf(Node.DEFAULT_PORT));
parser.accepts(BITCOIN_NETWORK_KEY).withRequiredArg().defaultsTo(BitcoinModule.DEFAULT_BITCOIN_NETWORK);
parser.accepts(PORT_KEY, "Port to listen on").withRequiredArg().ofType(int.class).defaultsTo(Node.DEFAULT_PORT);
parser.accepts(BOOTSTRAP_NODE_NAME_KEY).withRequiredArg().defaultsTo(BootstrapNodes.DEFAULT.getName());
parser.accepts(BOOTSTRAP_NODE_IP_KEY).withRequiredArg().defaultsTo(BootstrapNodes.DEFAULT.getIp());
parser.accepts(BOOTSTRAP_NODE_PORT_KEY).withRequiredArg().defaultsTo(BootstrapNodes.DEFAULT.getPortAsString());
parser.accepts(BOOTSTRAP_NODE_PORT_KEY).withRequiredArg().ofType(int.class)
.defaultsTo(BootstrapNodes.DEFAULT.getPort());
parser.accepts(NETWORK_INTERFACE_KEY, "Network interface").withRequiredArg();
}

View File

@ -53,7 +53,7 @@ public class TomP2PMessageModule extends MessageModule {
Node.at(
env.getProperty(BOOTSTRAP_NODE_NAME_KEY, BootstrapNodes.DEFAULT.getName()),
env.getProperty(BOOTSTRAP_NODE_IP_KEY, BootstrapNodes.DEFAULT.getIp()),
env.getProperty(BOOTSTRAP_NODE_PORT_KEY, BootstrapNodes.DEFAULT.getPortAsString())
env.getProperty(BOOTSTRAP_NODE_PORT_KEY, int.class, BootstrapNodes.DEFAULT.getPort())
)
);
bindConstant().annotatedWith(Names.named(NETWORK_INTERFACE_KEY)).to(

View File

@ -64,10 +64,6 @@ public final class Node {
return port;
}
public String getPortAsString() {
return String.valueOf(port);
}
/**
* Return a copy of this node with the port updated to the given value.
*/

View File

@ -46,7 +46,6 @@ public class NodeTests {
assertThat(node1a.hashCode(), not(equalTo(node2.hashCode())));
assertThat(node1a.getPort(), equalTo(Node.DEFAULT_PORT));
assertThat(node1a.getPortAsString(), equalTo(String.valueOf(Node.DEFAULT_PORT)));
Node node3a = Node.at("bitsquare3.example.com", "203.0.113.3", 1234);
Node node3b = Node.at("bitsquare3.example.com", "203.0.113.3", "1234");