Changeset 1243 for trunk/java-utils/src/main/java/de/ugoe/cs/util/console
- Timestamp:
- 06/28/13 14:38:46 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/java-utils/src/main/java/de/ugoe/cs/util/console/CommandExecuter.java
r1238 r1243 30 30 import java.util.jar.JarInputStream; 31 31 import java.util.logging.Level; 32 33 import de.ugoe.cs.util.StringTools; 32 34 33 35 /** … … 356 358 Command[] commands = getAvailableCommands(); 357 359 358 List<Command> matchingCommands = new ArrayList<Command>(); 359 for (Command command : commands) { 360 String commandName = command.getClass().getSimpleName().substring(3); 361 if (commandName.startsWith(commandPrefix)) { 362 matchingCommands.add(command); 363 } 364 } 360 String[] completions = new String[commands.length]; 365 361 366 StringBuffer completedPrefix = new StringBuffer(commandPrefix); 362 for (int i = 0; i < commands.length; i++) { 363 completions[i] = commands[i].getClass().getSimpleName().substring(3); 364 } 367 365 368 boolean foundCompletion = false; 369 370 while (!foundCompletion) { 371 char nextCompletionChar = 0; 372 for (Command command : matchingCommands) { 373 String commandName = command.getClass().getSimpleName().substring(3); 374 if (commandName.length() > completedPrefix.length()) { 375 if (nextCompletionChar == 0) { 376 nextCompletionChar = commandName.charAt(completedPrefix.length()); 377 } 378 else if (nextCompletionChar != commandName.charAt(completedPrefix.length())) { 379 foundCompletion = true; 380 } 381 } 382 else { 383 foundCompletion = true; 384 } 385 } 386 387 if (!foundCompletion && (nextCompletionChar != 0)) { 388 completedPrefix.append(nextCompletionChar); 389 } 390 else { 391 foundCompletion = true; 392 } 393 } 394 395 return completedPrefix.toString(); 366 return StringTools.autocomplete(commandPrefix, completions); 396 367 } 397 368 }
Note: See TracChangeset
for help on using the changeset viewer.