84 lines
2.1 KiB
Java
84 lines
2.1 KiB
Java
package envoy.client.data;
|
|
|
|
import static java.util.function.Function.identity;
|
|
|
|
import java.io.File;
|
|
|
|
import envoy.data.Config;
|
|
|
|
/**
|
|
* Implements a configuration specific to the Envoy Client with default values
|
|
* and convenience methods.
|
|
* <p>
|
|
* Project: <strong>envoy-client</strong><br>
|
|
* File: <strong>ClientConfig.java</strong><br>
|
|
* Created: <strong>01.03.2020</strong><br>
|
|
*
|
|
* @author Kai S. K. Engelbart
|
|
* @since Envoy Client v0.1-beta
|
|
*/
|
|
public final class ClientConfig extends Config {
|
|
|
|
private static ClientConfig config;
|
|
|
|
/**
|
|
* @return the singleton instance of the client config
|
|
* @since Envoy Client v0.1-beta
|
|
*/
|
|
public static ClientConfig getInstance() {
|
|
if (config == null) config = new ClientConfig();
|
|
return config;
|
|
}
|
|
|
|
private ClientConfig() {
|
|
super(".envoy");
|
|
put("server", "s", identity());
|
|
put("port", "p", Integer::parseInt);
|
|
put("localDB", "db", File::new);
|
|
put("user", "u", identity());
|
|
put("password", "pw", identity());
|
|
}
|
|
|
|
/**
|
|
* @return the host name of the Envoy server
|
|
* @since Envoy Client v0.1-alpha
|
|
*/
|
|
public String getServer() { return (String) items.get("server").get(); }
|
|
|
|
/**
|
|
* @return the port at which the Envoy server is located on the host
|
|
* @since Envoy Client v0.1-alpha
|
|
*/
|
|
public Integer getPort() { return (Integer) items.get("port").get(); }
|
|
|
|
/**
|
|
* @return the local database specific to the client user
|
|
* @since Envoy Client v0.1-alpha
|
|
*/
|
|
public File getLocalDB() { return (File) items.get("localDB").get(); }
|
|
|
|
/**
|
|
* @return the user name
|
|
* @since Envoy Client v0.3-alpha
|
|
*/
|
|
public String getUser() {
|
|
final String user = (String) items.get("user").get();
|
|
return user.equals("") ? null : user;
|
|
}
|
|
|
|
/**
|
|
* @return the password
|
|
* @since Envoy Client v0.3-alpha
|
|
*/
|
|
public String getPassword() {
|
|
final String password = (String) items.get("password").get();
|
|
return password.equals("") ? null : password;
|
|
}
|
|
|
|
/**
|
|
* @return {@code true} if user name and password are set
|
|
* @since Envoy Client v0.3-alpha
|
|
*/
|
|
public boolean hasLoginCredentials() { return getUser() != null && getPassword() != null; }
|
|
}
|