Order of commands preserved in command provider implementation
Minor correction in the CLIPrompter to avoid null pointer exception when cancel on promptChoice Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
eed6f43aea
commit
caa00f2a61
@ -36,8 +36,8 @@
|
||||
* Created on: Aug 6, 2014 */
|
||||
package fr.bigeon.gclc.command;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.bigeon.gclc.exception.CommandRunException;
|
||||
import fr.bigeon.gclc.exception.InvalidCommandName;
|
||||
@ -53,12 +53,12 @@ public class CommandProvider implements ICommandProvider {
|
||||
/** The space character */
|
||||
private static final String SPACE = " "; //$NON-NLS-1$
|
||||
/** The commands map */
|
||||
protected final Set<ICommand> commands;
|
||||
protected final List<ICommand> commands;
|
||||
|
||||
/** Create a command provider */
|
||||
public CommandProvider() {
|
||||
super();
|
||||
commands = new HashSet<>();
|
||||
commands = new ArrayList<>();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@ -70,6 +70,9 @@ public class CommandProvider implements ICommandProvider {
|
||||
if (name == null || name.startsWith(MINUS) || name.contains(SPACE)) {
|
||||
throw new InvalidCommandName();
|
||||
}
|
||||
if (commands.contains(value)) {
|
||||
return true;
|
||||
}
|
||||
return commands.add(value);
|
||||
}
|
||||
|
||||
|
@ -162,8 +162,11 @@ public class CLIPrompter {
|
||||
public static <U, T> T promptChoice(ConsoleManager manager, List<U> choices,
|
||||
Map<U, T> choicesMap, String message,
|
||||
String cancel) throws IOException {
|
||||
return choicesMap.get(choices.get(
|
||||
promptChoice(manager, choices, message, cancel).intValue()));
|
||||
Integer res = promptChoice(manager, choices, message, cancel);
|
||||
if (res == null) {
|
||||
return null;
|
||||
}
|
||||
return choicesMap.get(choices.get(res.intValue()));
|
||||
}
|
||||
|
||||
/** @param manager the manager
|
||||
|
Loading…
x
Reference in New Issue
Block a user