Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Commit

Permalink
refactor integer logic to getInteger
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Feb 24, 2020
1 parent c9cde27 commit e691f7c
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/main/java/net/consensys/orion/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,7 @@ public Optional<URL> nodeUrl() {
* @return Port to listen on for the Orion API
*/
public int nodePort() {
String port = env.get(envKey("nodeport"));
if (port != null) {
try {
return Integer.parseInt(port);
} catch (NumberFormatException e) {
log.warn(e.getMessage(), e);
}
}
return configuration.getInteger("nodeport");
return getInteger("nodeport");
}

/**
Expand Down Expand Up @@ -157,15 +149,7 @@ public Optional<URL> clientUrl() {
* @return Port to listen on for the client API
*/
public int clientPort() {
String port = env.get(envKey("clientport"));
if (port != null) {
try {
return Integer.parseInt(port);
} catch (NumberFormatException e) {
log.warn(e.getMessage(), e);
}
}
return configuration.getInteger("clientport");
return getInteger("clientport");
}

/**
Expand Down Expand Up @@ -537,6 +521,18 @@ private boolean contains(final String key) {
return env.containsKey(envKey(key)) || configuration.contains(key);
}

private Integer getInteger(final String key) {
String valueStr = env.get(envKey(key));
if (valueStr != null) {
try {
return Integer.parseInt(valueStr);
} catch (NumberFormatException e) {
log.warn(e.getMessage(), e);
}
}
return configuration.getInteger(key);
}

private String getString(final String key) {
return env.getOrDefault(envKey(key), configuration.getString(key));
}
Expand Down

0 comments on commit e691f7c

Please sign in to comment.