Class OptionCompleter

java.lang.Object
org.moeaframework.util.OptionCompleter

public class OptionCompleter extends Object
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 Details

    • OptionCompleter

      public OptionCompleter()
      Constructs a new, empty option auto-completer.
    • OptionCompleter

      public OptionCompleter(String... options)
      Constructs a new option auto-completer initialized to recognize the specified options.
      Parameters:
      options - the initial options
    • OptionCompleter

      public OptionCompleter(Collection<String> options)
      Constructs a new option auto-completer initialized to recognize the specified options.
      Parameters:
      options - the initial options
  • Method Details

    • add

      public void add(String option)
      Adds an option to this OptionCompleter. Duplicate options are ignored.
      Parameters:
      option - the option
    • lookup

      public String lookup(String partial)
      Returns the closest matching unique option from the set of options stored in this OptionCompleter. Returns null 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