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/src/main/java/envoy/client/Config.java

110 lines
2.8 KiB
Java
Raw Normal View History

2019-10-30 06:26:50 +01:00
package envoy.client;
import java.io.File;
import java.util.Properties;
/**
* Project: <strong>envoy-client</strong><br>
* File: <strong>Config.java</strong><br>
* Created: <strong>12 Oct 2019</strong><br>
*
* @author Kai S. K. Engelbart
* @since Envoy v0.1-alpha
*/
public class Config {
private String server;
private int port;
private File localDB;
/**
* Defaults to the {@code client.properties} file for information.
*
* @param properties a {@link Properties} object containing information about
* the server and port, as well as the path to the local
* database
* @since Envoy v0.1-alpha
*/
public void load(Properties properties) {
if (properties.containsKey("server")) server = properties.getProperty("server");
if (properties.containsKey("port")) port = Integer.parseInt(properties.getProperty("port"));
localDB = new File(properties.getProperty("localDB", ".\\localDB"));
}
/**
* Sets the server, port and localDB path via command line properties --server /
* -s, --port / -p and --localDB / -db.
*
* @param args the command line arguments to parse
* @since Envoy v0.1-alpha
*/
public void load(String[] args) {
for (int i = 0; i < args.length; i++)
switch (args[i]) {
case "--server":
case "-s":
server = args[++i];
break;
case "--port":
case "-p":
port = Integer.parseInt(args[++i]);
break;
case "--localDB":
case "-db":
localDB = new File(args[++i]);
2019-10-30 07:45:33 +01:00
break;
2019-10-30 06:26:50 +01:00
}
}
/**
* @return {@code true} if server, port andd localDB directory are known.
* @since Envoy v0.1-alpha
*/
public boolean isInitialized() { return server != null && !server.isEmpty() && port > 0 && port < 65566 && localDB != null; }
/**
* @return the URL of our website
* @since Envoy v0.1-alpha
*/
public String getServer() { return server; }
/**
* Changes the default URL.
* Exclusively meant for developing reasons. (localhost)
*
* @param server the URL where wish to host Envoy
* @since Envoy v0.1-alpha
*/
public void setServer(String server) { this.server = server; }
/**
* @return the port at which Envoy is located in the Server
* @since Envoy v0.1-alpha
*/
public int getPort() { return port; }
/**
* Changes the default port.
* Exclusively meant for developing reasons. (localhost)
*
* @param port the port where we wish to connect to {@code Envoy}.
* @since Envoy v0.1-alpha
*/
public void setPort(int port) { this.port = port; }
2019-10-30 07:45:33 +01:00
/**
*@return the current local database that is held for that user
*@since Envoy v0.1-alpha
**/
2019-10-30 06:26:50 +01:00
public File getLocalDB() { return localDB; }
2019-10-30 07:45:33 +01:00
/**
*Changes the default local database.
*Exclusively meant for developing reasons.
*
*@param the local database object to set
*@since Envoy v0.1-alpha
**/
2019-10-30 06:26:50 +01:00
public void setLocalDB(File localDB) { this.localDB = localDB; }
2019-10-30 07:45:33 +01:00
}