diff options
Diffstat (limited to 'auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIEditorLoop.java')
-rw-r--r-- | auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIEditorLoop.java | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIEditorLoop.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIEditorLoop.java index 560648901..4eacde04b 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIEditorLoop.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIEditorLoop.java @@ -20,6 +20,8 @@ package org.onap.policy.apex.auth.clieditor; +import static org.onap.policy.apex.model.utilities.TreeMapUtils.findMatchingEntries; + import java.io.BufferedReader; import java.io.File; import java.io.IOException; @@ -170,7 +172,7 @@ public class CLIEditorLoop { try { // Parse the line into a list of commands and arguments - final ArrayList<String> commandWords = parser.parse(line, logicBlock); + final List<String> commandWords = parser.parse(line, logicBlock); // Find the command, if the command is null, then we are simply changing position in // the hierarchy @@ -240,7 +242,7 @@ public class CLIEditorLoop { * @return The found command */ - private CLICommand findCommand(final ArrayList<String> commandWords) { + private CLICommand findCommand(final List<String> commandWords) { CLICommand command = null; final KeywordNode startKeywordNode = keywordNodeDeque.peek(); @@ -258,8 +260,8 @@ public class CLIEditorLoop { // If the node entries found is not equal to one, then we have either no command or more // than one command matching final List<Entry<String, KeywordNode>> foundNodeEntries = - TreeMapUtils.findMatchingEntries(searchKeywordNode.getChildren(), commandWords.get(i)); - if (foundNodeEntries.size() == 0) { + findMatchingEntries(searchKeywordNode.getChildren(), commandWords.get(i)); + if (foundNodeEntries.isEmpty()) { unwindStack(startKeywordNode); throw new CLIException("command not found: " + stringAL2String(commandWords)); } else if (foundNodeEntries.size() > 1) { @@ -311,7 +313,7 @@ public class CLIEditorLoop { * @return the argument values */ private TreeMap<String, CLIArgumentValue> getArgumentValues(final CLICommand command, - final ArrayList<String> commandWords) { + final List<String> commandWords) { final TreeMap<String, CLIArgumentValue> argumentValues = new TreeMap<>(); for (final CLIArgument argument : command.getArgumentList()) { if (argument != null) { @@ -338,13 +340,11 @@ public class CLIEditorLoop { // Now check all mandatory arguments are set for (final CLIArgumentValue argumentValue : argumentValues.values()) { - if (!argumentValue.isSpecified()) { - // Argument values are null by default so if this argument is not nullable it is - // mandatory - if (!argumentValue.getCliArgument().isNullable()) { - throw new CLIException("command " + stringAL2String(commandWords) + ": " + " mandatory argument \"" - + argumentValue.getCliArgument().getArgumentName() + "\" not specified"); - } + // Argument values are null by default so if this argument is not nullable it is + // mandatory + if (!argumentValue.isSpecified() && !argumentValue.getCliArgument().isNullable()) { + throw new CLIException("command " + stringAL2String(commandWords) + ": " + " mandatory argument \"" + + argumentValue.getCliArgument().getArgumentName() + "\" not specified"); } } @@ -358,7 +358,7 @@ public class CLIEditorLoop { * @param commandWords The command words entered by the user * @return the arguments as an entry array list */ - private ArrayList<Entry<String, String>> getCommandArguments(final ArrayList<String> commandWords) { + private ArrayList<Entry<String, String>> getCommandArguments(final List<String> commandWords) { final ArrayList<Entry<String, String>> arguments = new ArrayList<>(); // Iterate over the command words, arguments are of the format name=value @@ -398,11 +398,11 @@ public class CLIEditorLoop { * @return the result of execution of the command */ private ApexAPIResult exceuteSystemCommand(final CLICommand command, final PrintWriter writer) { - if (command.getName().equals("back")) { + if ("back".equals(command.getName())) { return executeBackCommand(); - } else if (command.getName().equals("help")) { + } else if ("help".equals(command.getName())) { return executeHelpCommand(writer); - } else if (command.getName().equals("quit")) { + } else if ("quit".equals(command.getName())) { return executeQuitCommand(); } else { return new ApexAPIResult(RESULT.SUCCESS); |