Package org.moeaframework.util
Class OptionCompleter
java.lang.Object
org.moeaframework.util.OptionCompleter
Utility for auto-completion, finding the closest matching unique option from a set of options. For instance,
OptionCompleter completer = new OptionCompleter();
completer.add("subset");
completer.add("superset");
completer.lookup("sub"); // returns "subset"
completer.lookup("sup"); // returns "superset"
completer.lookup("s"); // returns null, since both subset and superset match
completer.lookup("k"); // returns null, no matches
-
Constructor Summary
ConstructorDescriptionConstructs a new, empty option auto-completer.OptionCompleter
(Class<T> options) Constructs a new option auto-completer initialized to recognize the enumerated values.OptionCompleter
(String... options) Constructs a new option auto-completer initialized to recognize the specified options.OptionCompleter
(Collection<String> options) Constructs a new option auto-completer initialized to recognize the specified options. -
Method Summary
-
Constructor Details
-
OptionCompleter
public OptionCompleter()Constructs a new, empty option auto-completer. -
OptionCompleter
Constructs a new option auto-completer initialized to recognize the specified options.- Parameters:
options
- the initial options
-
OptionCompleter
Constructs a new option auto-completer initialized to recognize the specified options.- Parameters:
options
- the initial options
-
OptionCompleter
Constructs a new option auto-completer initialized to recognize the enumerated values. Note that the enum constants are converted into their string representations, and likewise the returned value oflookup(String)
will be the string representation. UseEnum.valueOf(Class, String)
to convert back into the enumeration, if required.- Type Parameters:
T
- the enum type- Parameters:
options
- the enum class
-
-
Method Details
-
add
Adds an option to thisOptionCompleter
. Duplicate options are ignored.- Parameters:
option
- the option
-
getOptions
Returns the supported options.- Returns:
- the supported options
-
lookup
Returns the closest matching unique option from the set of options stored in thisOptionCompleter
. Returnsnull
if no options matched or more than one option matched.- Parameters:
partial
- the partial/complete option- Returns:
- the closest matching option, or
null
if no options matched or more than one option matched
-