This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/client/src/main/java/envoy/client/data/ClientConfig.java

88 lines
2.3 KiB
Java
Raw Normal View History

package envoy.client.data;
2019-10-30 06:26:50 +01:00
2020-07-09 09:13:26 +02:00
import static java.util.function.Function.identity;
2019-10-30 06:26:50 +01:00
import java.io.File;
import envoy.data.Config;
2019-10-30 06:26:50 +01:00
/**
* Implements a configuration specific to the Envoy Client with default values
* and convenience methods.
* <p>
2019-10-30 06:26:50 +01:00
* Project: <strong>envoy-client</strong><br>
* File: <strong>ClientConfig.java</strong><br>
* Created: <strong>01.03.2020</strong><br>
*
2019-10-30 06:26:50 +01:00
* @author Kai S. K. Engelbart
* @since Envoy Client v0.1-beta
2019-10-30 06:26:50 +01:00
*/
public class ClientConfig extends Config {
2019-10-30 06:26:50 +01:00
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(), true);
put("port", "p", Integer::parseInt, true);
put("localDB", "db", File::new, true);
put("ignoreLocalDB", "nodb", Boolean::parseBoolean);
put("user", "u", identity());
put("password", "pw", identity());
}
2019-10-30 06:26:50 +01:00
/**
2019-10-30 17:01:55 +01:00
* @return the host name of the Envoy server
* @since Envoy Client v0.1-alpha
2019-10-30 06:26:50 +01:00
*/
public String getServer() { return (String) items.get("server").get(); }
2019-10-30 06:26:50 +01:00
/**
2019-10-30 17:01:55 +01:00
* @return the port at which the Envoy server is located on the host
* @since Envoy Client v0.1-alpha
2019-10-30 06:26:50 +01:00
*/
public Integer getPort() { return (Integer) items.get("port").get(); }
2019-10-30 06:26:50 +01:00
2019-10-30 07:45:33 +01:00
/**
2019-10-30 17:01:55 +01:00
* @return the local database specific to the client user
* @since Envoy Client v0.1-alpha
2019-12-21 12:36:26 +01:00
*/
public File getLocalDB() { return (File) items.get("localDB").get(); }
/**
* @return {@code true} if the local database is to be ignored
* @since Envoy Client v0.3-alpha
*/
public Boolean isIgnoreLocalDB() {
final var ignoreLocalDB = items.get("ignoreLocalDB").get();
return ignoreLocalDB != null && (Boolean) ignoreLocalDB;
}
/**
* @return the user name
* @since Envoy Client v0.3-alpha
*/
public String getUser() { return (String) items.get("user").get(); }
/**
* @return the password
* @since Envoy Client v0.3-alpha
*/
2020-07-09 09:13:26 +02:00
public String getPassword() { return (String) items.get("password").get(); }
/**
* @return {@code true} if user name and password are set
* @since Envoy Client v0.3-alpha
*/
public boolean hasLoginCredentials() { return getUser() != null && getPassword() != null; }
}