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/ConfigItem.java

65 lines
2.0 KiB
Java

package envoy.client;
import java.util.function.Function;
/**
* Contains a single {@link Config} value as well as the corresponding command
* line arguments and its default value.<br>
* <br>
* 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
* @param <T> the type of the config item's value
* @since Envoy v0.2-alpha
*/
public class ConfigItem<T> {
private String commandLong, commandShort;
private Function<String, T> parseFunction;
private T value;
/**
* 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
*/
public ConfigItem(String commandLong, String commandShort, Function<String, T> parseFunction, T defaultValue) {
this.commandLong = commandLong;
this.commandShort = commandShort;
this.parseFunction = parseFunction;
value = defaultValue;
}
/**
* Parses this {@ConfigItem}'s value from a string
* @param input the string to parse from
* @since Envoy v0.2-alpha
*/
public void parse(String input) { value = parseFunction.apply(input); }
/**
* @return The long command line argument to set the value of this {@link ConfigItem}
* @since Envoy v0.2-alpha
*/
public String getCommandLong() { return commandLong; }
/**
* @return The short command line argument to set the value of this {@link ConfigItem}
* @since Envoy v0.2-alpha
*/
public String getCommandShort() { return commandShort; }
/**
* @return the value of this {@link ConfigItem}
* @since Envoy v0.2-alpha
*/
public T get() { return value; }
}