2019-12-21 11:35:01 +01:00
|
|
|
package envoy.client;
|
|
|
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
|
|
/**
|
2019-12-21 12:20:23 +01:00
|
|
|
* Contains a single {@link Config} value as well as the corresponding command
|
|
|
|
* line arguments and its default value.<br>
|
|
|
|
* <br>
|
2019-12-21 11:35:01 +01:00
|
|
|
* Project: <strong>envoy-clientChess</strong><br>
|
|
|
|
* File: <strong>ConfigItem.javaEvent.java</strong><br>
|
|
|
|
* Created: <strong>21.12.2019</strong><br>
|
|
|
|
*
|
|
|
|
* @author Kai S. K. Engelbart
|
2019-12-21 12:20:23 +01:00
|
|
|
* @param <T> the type of the config item's value
|
|
|
|
* @since Envoy v0.2-alpha
|
2019-12-21 11:35:01 +01:00
|
|
|
*/
|
|
|
|
public class ConfigItem<T> {
|
|
|
|
|
|
|
|
private String commandLong, commandShort;
|
|
|
|
private Function<String, T> parseFunction;
|
|
|
|
private T value;
|
|
|
|
|
2019-12-21 12:20:23 +01:00
|
|
|
/**
|
|
|
|
* Initializes a {@link ConfigItem}
|
|
|
|
*
|
|
|
|
* @param commandLong the long command line argument to set this value
|
|
|
|
* @param commandShort the short command line argument to set this value
|
|
|
|
* @param parseFunction the {@code Function<String, T>} that parses the value
|
|
|
|
* from a string
|
|
|
|
* @param defaultValue the optional default value to set before parsing
|
|
|
|
* @since Envoy v0.2-alpha
|
|
|
|
*/
|
2019-12-21 11:35:01 +01:00
|
|
|
public ConfigItem(String commandLong, String commandShort, Function<String, T> parseFunction, T defaultValue) {
|
|
|
|
this.commandLong = commandLong;
|
|
|
|
this.commandShort = commandShort;
|
|
|
|
this.parseFunction = parseFunction;
|
|
|
|
value = defaultValue;
|
|
|
|
}
|
|
|
|
|
2019-12-21 12:20:23 +01:00
|
|
|
/**
|
|
|
|
* Parses this {@ConfigItem}'s value from a string
|
|
|
|
* @param input the string to parse from
|
|
|
|
* @since Envoy v0.2-alpha
|
|
|
|
*/
|
2019-12-21 11:35:01 +01:00
|
|
|
public void parse(String input) { value = parseFunction.apply(input); }
|
|
|
|
|
2019-12-21 12:20:23 +01:00
|
|
|
/**
|
|
|
|
* @return The long command line argument to set the value of this {@link ConfigItem}
|
|
|
|
* @since Envoy v0.2-alpha
|
|
|
|
*/
|
2019-12-21 11:35:01 +01:00
|
|
|
public String getCommandLong() { return commandLong; }
|
|
|
|
|
2019-12-21 12:20:23 +01:00
|
|
|
/**
|
|
|
|
* @return The short command line argument to set the value of this {@link ConfigItem}
|
|
|
|
* @since Envoy v0.2-alpha
|
|
|
|
*/
|
2019-12-21 11:35:01 +01:00
|
|
|
public String getCommandShort() { return commandShort; }
|
|
|
|
|
2019-12-21 12:20:23 +01:00
|
|
|
/**
|
|
|
|
* @return the value of this {@link ConfigItem}
|
|
|
|
* @since Envoy v0.2-alpha
|
|
|
|
*/
|
2019-12-21 11:35:01 +01:00
|
|
|
public T get() { return value; }
|
|
|
|
}
|