You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public static final String SERVICE_PORT_KEY = ".network.port";
public static final int SERVICE_PORT_DEFAULT = 8090;
public static final String PURPOSE_KEY = ".purpose"; // No default
private final int servicePort;
private final String purpose;
public MyApp {
YAML conf = getMajorConfiguration().getSubMap(".myapp");
servicePort = conf.getInt(SERVICE_PORT_KEY, SERVICE_PORT_DEFAULT);
purpose = conf.getString(PURPOSE_KEY); // throws exception if the param is not defined
}
Having the keys and the defaults defined as static final at the top of the file is great when reading the code, but maybe they could be collapsed to 1 line each and maybe it could be externalized when there is a problem with the configuration? Something like
public static final KeyPool KP = new KeyPool();
public static final Key SERVICE_PORT = KP.add(".network.port", 8090),
public static final Key PURPOSE = KP.addString("purpose")
public MyApp {
// If the value for PURPOSE is not defined, an exception is thrown
KP.setConf(getMajorConfiguration().getSubMap(".myapp"));
// After setconf on KP, the values can be accessed with
// SERVICE_PORT.get()
// PURPOSE.get();
}
The text was updated successfully, but these errors were encountered:
A common pattern is to have something like
Having the keys and the defaults defined as
static final
at the top of the file is great when reading the code, but maybe they could be collapsed to 1 line each and maybe it could be externalized when there is a problem with the configuration? Something likeThe text was updated successfully, but these errors were encountered: