/* (non-Javadoc)
@see org.jboss.as.cli.CommandLineCompleter#complete(org.jboss.as.cli.CommandContext, java.lang.String, int, java.util.List)
434200
@Override
    public int complete(CommandContext ctx, String buffer, int cursor, List<String> candidates) {

        final Collection<String> all = getAllCandidates(ctx);
        if (all.isEmpty()) {
            return -1;
        }

        candidates.addAll(all);
        if(buffer.isEmpty()) {
            return 0;
        }
        final String[] specified = buffer.split(",+");
        candidates.removeAll(Arrays.asList(specified));
        if(buffer.charAt(buffer.length() - 1) == ',') {
            return buffer.length();
        }
        final String chunk = specified[specified.length - 1];
        final Iterator<String> iterator = candidates.iterator();
        while(iterator.hasNext()) {
            if(!iterator.next().startsWith(chunk)) {
                iterator.remove();
            }
        }
        return buffer.length() - chunk.length();
    }
651573
private void complete(Subscriber<? super T> subscriber) {
        if (!subscriber.isUnsubscribed()) {
            debug("onCompleted");
            subscriber.onCompleted();
        } else
            debug("unsubscribed");
    }
609402
private void checkForCompletion() {
        final String methodName = "checkForCompletion(): ";
        // mark the list complete if that was the last awaited key
        if (actualIndices.isEmpty()) {
            if (tc.isDebugEnabled())
                Tr.debug(tc, methodName + "setting state=COMPLETE");
            state = failedKeys == null
                            ? COMPLETE
                            : COMPLETE_WITH_FAILURES; // state change must be last action
        }
    }
611747
protected int complete(CommandContext ctx, ParsedCommandLine parsedCmd, OperationCandidatesProvider candidatesProvider, final String buffer, int cursor, List<String> candidates) {

        if(parsedCmd.isRequestComplete()) {
            return -1;
        }

        // Headers completion
        if(parsedCmd.endsOnHeaderListStart() || parsedCmd.hasHeaders()) {
            return completeHeaders(ctx, parsedCmd, candidatesProvider, buffer, cursor, candidates);
        }

        // Completed.
        if(parsedCmd.endsOnPropertyListEnd()) {
            return buffer.length();
        }

        // Complete properties
        if (parsedCmd.hasProperties() || parsedCmd.endsOnPropertyListStart()
                || parsedCmd.endsOnNotOperator()) {
            return completeProperties(ctx, parsedCmd, candidatesProvider, buffer, candidates);
        }

        // Complete Operation name
        if (parsedCmd.hasOperationName() || parsedCmd.endsOnAddressOperationNameSeparator()) {
            return completeOperationName(ctx, parsedCmd, candidatesProvider, buffer, candidates);
        }

        // Finally Complete address
        return completeAddress(ctx, parsedCmd, candidatesProvider, buffer, candidates);
    }
1331458
private void complete(KSplit split, KCall call) {
		reset(call.getProcess());
		split.split(call);
	}
660466
def complete(self, sp_args, line, rl_prefix, rl_begidx, rl_endidx):
        
        # TODO: Optionally check that flags are not repeated (i.e. exclude
        #       them from the possible matches if they are already in the
        #       command line)
        # TODO: Support groups of mutually-exclusive flags, i.e. if one is
        #       already present, the others in the group are not accepted
        if len(sp_args) == 0 or not line.endswith(sp_args[-1]):
            # if line.endswith(sp_args[-1]) is False, it means that the last
            # sp_args is already complete
            return self.accepted_flags
        else:
            matches = []
            for arg in self.accepted_flags:
                if arg.startswith(sp_args[-1]):
                    matches.append(arg)
            if len(matches) == 1:
                # In general, SPLIT_ARGS and readline use different word
                #  delimiters, see e.g. the docs for
                #  readline.get_completer_delims()
                # If for example there's a 'foo-bar' argument, SPLIT_ARGS sees
                #  it as a single word, but readline by default will split it
                #  in two words, 'foo' and 'bar', and if 'foo-b' is entered in
                #  the command line, and Tab is pressed, the word will be
                #  completed as 'foo-bfoo-bar', unless we compensate here by
                #  subtracting the rl_prefix from the found match
                sub = len(sp_args[-1]) - len(rl_prefix)
                return [matches[0][sub:]]
            else:
                return matches
836973
public static <T> void completeFrom(CompletionStage<T> source, CompletableFuture<T> target) {
    source.whenComplete(
        (t, error) -> {
          if (error != null) {
            target.completeExceptionally(error);
          } else {
            target.complete(t);
          }
        });
  }
903726
@SuppressWarnings({ "rawtypes", "unchecked" })
  void complete() {

    if (this.range != null) {
      AbstractValidatorRange validator = null;
      if (this.valueType != null) {
        Class<?> valueClass = this.valueType.getAssignmentClass();
        if (this.valueType.isCollection()) {
          validator = new ValidatorCollectionSize(this.range);
        } else if (this.valueType.isMap()) {
          validator = new ValidatorMapSize(this.range);
        } else if (this.valueType.getComponentType() != null) {
          validator = new ValidatorArrayLength(this.range);
        } else if (this.mathUtil.getNumberType(valueClass) != null) {
          validator = new ValidatorRange<>(this.range);
        }
      }
      if (validator == null) {
        validator = new ValidatorRangeGeneric<>(this.range);
      }
      this.validatorRegistry.add(validator);
    }
  }
236096
def complete_help_subcommand(self, text: str, line: str, begidx: int, endidx: int) -> List[str]:
        """"""

        # Get all tokens through the one being completed
        tokens, _ = self.tokens_for_completion(line, begidx, endidx)

        if not tokens:
            return []

        # Must have at least 3 args for 'help command sub-command'
        if len(tokens) < 3:
            return []

        # Find where the command is by skipping past any flags
        cmd_index = 1
        for cur_token in tokens[cmd_index:]:
            if not cur_token.startswith('-'):
                break
            cmd_index += 1

        if cmd_index >= len(tokens):
            return []

        command = tokens[cmd_index]
        matches = []

        # Check if this is a command with an argparse function
        func = self.cmd_func(command)
        if func and hasattr(func, 'argparser'):
            completer = AutoCompleter(getattr(func, 'argparser'), self)
            matches = completer.complete_command_help(tokens[cmd_index:], text, line, begidx, endidx)

        return matches
1329709
public ExecutionResult withComplete() {
    return this.complete ? this : new ExecutionResult(result, failure, nonResult, waitNanos, true, success, successAll);
  }
1374365
def complete_set(self, cmd_param_text, full_cmd, *rest):
        
        complete_value = partial(complete_values, ["updated-value"])
        complete_version = partial(complete_values, [str(i) for i in range(1, 11)])
        completers = [self._complete_path, complete_value, complete_version]
        return complete(completers, cmd_param_text, full_cmd, *rest)
962832
private CompletableFuture<Void> completeWithRemoteCommand(AdvancedCache<?, ?> cache, RpcManager rpcManager,
         TxState state)
         throws Throwable {
      CommandsFactory commandsFactory = cache.getComponentRegistry().getCommandsFactory();
      CacheRpcCommand command = buildRemoteCommand(cache.getCacheConfiguration(), commandsFactory, state);
      CompletableFuture<Void> remote = rpcManager
            .invokeCommandOnAll(command, validOnly(), rpcManager.getSyncRpcOptions())
            .handle(handler())
            .toCompletableFuture();
      commandsFactory.initializeReplicableCommand(command, false);
      CompletableFuture<Void> local = command.invokeAsync().handle(handler());
      return CompletableFuture.allOf(remote, local);
   }
1366506
public void complete(VirtualConnection vc, TCPReadRequestContext rsc) {

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "complete() called: vc=" + vc);
        }
        // all we have to do is get the service context and continue the read
        // process

        if (vc instanceof OutboundVirtualConnection) {
            HttpOutboundServiceContextImpl osc = (HttpOutboundServiceContextImpl) vc.getStateMap().get(CallbackIDs.CALLBACK_HTTPOSC);
            osc.continueRead();
        } else {
            HttpInboundServiceContextImpl isc = (HttpInboundServiceContextImpl) vc.getStateMap().get(CallbackIDs.CALLBACK_HTTPISC);
            isc.continueRead();
        }
    }
1070703
@Override
    public void complete() {
        this.indexedNodeStore.complete();
        this.nodeIndexReader = this.indexedNodeStore.createReader();

        this.indexedWayStore.complete();
        this.wayIndexReader = this.indexedWayStore.createReader();

        LOGGER.info("handle coastlines" +
                (this.tagValues ? " and implicit way relations..." : "..."));
        // Prepare implicit way relations
        // (should be done here, before handling ways, although
        // the WayHandler does only process ids in HD Processor)
        int nWays = 0;
        ReleasableIterator<Way> wayReader = this.wayStore.iterate();
        while (wayReader.hasNext()) {
            if (this.progressLogs) {
                if (++nWays % 10000 == 0) {
                    System.out.print("Ways: " + this.nfCounts.format(nWays)
                            + " / " + this.nfCounts.format(getWaysNumber()) + "\r");
                }
            }

            Way way = wayReader.next();
            TDWay tdWay = TDWay.fromWay(way, this, this.preferredLanguages);
            if (tdWay == null) {
                continue;
            }
            prepareImplicitWayRelations(tdWay);
        }

        // handle implicit relations
        handleImplicitWayRelations();

        LOGGER.info("handle relations...");
        ReleasableIterator<Relation> relationReader = this.relationStore.iterate();
        RelationHandler relationHandler = new RelationHandler();
        while (relationReader.hasNext()) {
            Relation entry = relationReader.next();
            TDRelation tdRelation = TDRelation.fromRelation(entry, this, this.preferredLanguages);
            relationHandler.execute(tdRelation);
        }

        LOGGER.info("handle ways...");
        wayReader = this.wayStore.iterate();
        WayHandler wayHandler = new WayHandler();
        while (wayReader.hasNext()) {
            Way way = wayReader.next();
            TDWay tdWay = TDWay.fromWay(way, this, this.preferredLanguages);
            if (tdWay == null) {
                continue;
            }

            // #HDstoreData: handled here only for tag count - handled for writing in method: fromHDTileData()
            List<TDRelation> associatedRelations = this.additionalRelationTags.get(tdWay.getId());
            if (associatedRelations != null) {
                for (TDRelation tileDataRelation : associatedRelations) {
                    tdWay.mergeRelationInformation(tileDataRelation);
                }
            }

            wayHandler.execute(tdWay);
        }

        OSMTagMapping.getInstance().optimizePoiOrdering(this.histogramPoiTags);
        OSMTagMapping.getInstance().optimizeWayOrdering(this.histogramWayTags);
    }
617126
@Programmatic
    @Override
    public void complete(final Command command) {
        final CommandJdo commandJdo = asUserInitiatedCommandJdo(command);
        if(commandJdo == null) {
            return;
        }

        //
        // prior to 1.13.0 there was a guard here to not persist the command if the completedAt had been set.
        // as of 1.13.0, this field is populated by the framework, so the guard no longer makes sense.
        //
        // can't store target if too long (eg view models)
        if (commandJdo.getTargetStr() != null && commandJdo.getTargetStr().length() > JdoColumnLength.BOOKMARK) {
            commandJdo.setTargetStr(null);
        }

        if(commandJdo.shouldPersist()) {
            repositoryService.persist(commandJdo);
        }

    }
591192
@Override
    public void handle(CommandContext ctx, String commandLine) {
        String[] commands = commandLine.split(" ");
        if (commands.length != 1) {
            ctx.printLine("Invalid command.");
            return;
        }

        ctx.terminateSession();
    }
814430
@Override
	public List<String> listCommands( String app ) {

		this.logger.fine("Request: list all the commands in the " + app + " application.");
		List<String> result;
		Application application = this.manager.applicationMngr().findApplicationByName( app );
		if( application == null )
			result = new ArrayList<>( 0 );
		else
			result = this.manager.commandsMngr().listCommands( application );

		return result;
	}