All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.cli.completers.ListCompleter Maven / Gradle / Ivy

package org.infinispan.cli.completers;

import java.io.IOException;
import java.util.Collection;

import org.aesh.command.completer.CompleterInvocation;
import org.aesh.command.completer.OptionCompleter;
import org.infinispan.cli.Context;

/**
 * @author Tristan Tarrant <[email protected]>
 * @since 10.0
 **/
public abstract class ListCompleter implements OptionCompleter {

   abstract Collection getAvailableItems(Context context) throws IOException;

   protected Collection getAvailableItems(ContextAwareCompleterInvocation invocation) throws IOException {
      return getAvailableItems(invocation.context);
   }

   @Override
   public void complete(ContextAwareCompleterInvocation invocation) {
      try {
         Collection all = getAvailableItems(invocation);
         completeFromList(invocation, all);
      } catch (IOException e) {
         e.printStackTrace();
      }
   }

   public void completeFromList(CompleterInvocation invocation, Collection all) {
      String v = invocation.getGivenCompleteValue();
      if (v == null || v.length() == 0) {
         invocation.addAllCompleterValues(all);
      } else {
         for (String item : all) {
            if (item.startsWith(v)) {
               invocation.addCompleterValue(item);
            }
         }
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy