public CommandTarget duplicate(String key) { return duplicate(key, null); }
public CommandTarget duplicate(String key) { return duplicate(key, null); }
private CommandTarget locateExactMatchingTarget(final String userInput)//exact matching throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { CommandTarget commandTarget = null; Map<String, CommandTarget> commandTargetsMap = commandManager.getCommands(); // Reverse sort the command names because we should start from longer names // E.g. Consider commands "A", "A B" & user input as "A B --opt1=val1" // In this case, "A B" is the most probable match & should be matched first // which can be achieved by reversing natural order of sorting. Set<String> commandNamesReverseSorted = new TreeSet<String>(Collections.reverseOrder()); commandNamesReverseSorted.addAll(commandTargetsMap.keySet()); // Now we need to locate the CommandTargets from the entries in the map for (final String commandName : commandNamesReverseSorted) { if (userInput.startsWith(commandName) && commandWordsMatch(userInput, commandName)) { // This means that the user has entered the command & name matches exactly commandTarget = commandTargetsMap.get(commandName); if (commandTarget != null) { String remainingBuffer = StringUtils.removeStart(userInput, commandName); commandTarget = commandTarget.duplicate(commandName, remainingBuffer); break; } } } return commandTarget; }
private CommandTarget locateExactMatchingTarget(final String userInput)//exact matching throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { CommandTarget commandTarget = null; Map<String, CommandTarget> commandTargetsMap = commandManager.getCommands(); // Reverse sort the command names because we should start from longer names // E.g. Consider commands "A", "A B" & user input as "A B --opt1=val1" // In this case, "A B" is the most probable match & should be matched first // which can be achieved by reversing natural order of sorting. Set<String> commandNamesReverseSorted = new TreeSet<String>(Collections.reverseOrder()); commandNamesReverseSorted.addAll(commandTargetsMap.keySet()); // Now we need to locate the CommandTargets from the entries in the map for (final String commandName : commandNamesReverseSorted) { if (userInput.startsWith(commandName) && commandWordsMatch(userInput, commandName)) { // This means that the user has entered the command & name matches exactly commandTarget = commandTargetsMap.get(commandName); if (commandTarget != null) { String remainingBuffer = StringUtils.removePrefix(userInput, commandName); commandTarget = commandTarget.duplicate(commandName, remainingBuffer); break; } } } return commandTarget; }