summaryrefslogtreecommitdiffstats
path: root/auth/cli-editor/src/main
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-09-22 21:07:43 +0100
committerliamfallon <liam.fallon@ericsson.com>2018-09-22 21:15:22 +0100
commit6973ec9109fd2651e2284663b6c8039bd830a677 (patch)
treef1f02ef9e5400805e6c2179dc539ad15c3ce5334 /auth/cli-editor/src/main
parenta02548ec2e98a8a13cd76ecc83379b13cd26030b (diff)
Fix sonar problems in Apex
Fixed some easy to resolve Sonar issues. Issue-ID: POLICY-1034 Change-Id: Ia8e4606bd4307daca499b4a74c96135211e572fd Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'auth/cli-editor/src/main')
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineArgument.java50
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineCommand.java68
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java9
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java58
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java27
5 files changed, 181 insertions, 31 deletions
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineArgument.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineArgument.java
index f1a6e7867..6dd2f14ee 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineArgument.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineArgument.java
@@ -141,4 +141,54 @@ public class CommandLineArgument implements Comparable<CommandLineArgument> {
}
return description.compareTo(otherArgument.description);
}
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((argumentName == null) ? 0 : argumentName.hashCode());
+ result = prime * result + ((description == null) ? 0 : description.hashCode());
+ result = prime * result + (nullable ? 1231 : 1237);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null) {
+ return false;
+ }
+
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+
+ CommandLineArgument other = (CommandLineArgument) obj;
+ if (argumentName == null) {
+ if (other.argumentName != null) {
+ return false;
+ }
+ } else if (!argumentName.equals(other.argumentName)) {
+ return false;
+ }
+
+ if (description == null) {
+ if (other.description != null) {
+ return false;
+ }
+ } else if (!description.equals(other.description)) {
+ return false;
+ }
+
+ return nullable == other.nullable;
+ }
}
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineCommand.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineCommand.java
index 6c651cb6b..beba91554 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineCommand.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineCommand.java
@@ -214,12 +214,33 @@ public class CommandLineCommand implements Comparable<CommandLineCommand> {
return this.hashCode() - otherCommand.hashCode();
}
- final CommandLineCommand other = otherCommand;
+ int result = compareKeywordList(otherCommand);
+ if (result != 0) {
+ return result;
+ }
+
+ if (!argumentList.equals(otherCommand.argumentList)) {
+ return (argumentList.hashCode() - otherCommand.argumentList.hashCode());
+ }
+
+ if (systemCommand != otherCommand.systemCommand) {
+ return (this.hashCode() - otherCommand.hashCode());
+ }
+
+ return apiMethod.compareTo(otherCommand.apiMethod);
+ }
+ /**
+ * Compare the keyword lists of the commands.
+ *
+ * @param otherCommand the command to compare with
+ * @return the int
+ */
+ private int compareKeywordList(final CommandLineCommand otherCommand) {
for (int i = 0, j = 0;; i++, j++) {
if (i < keywordlist.size() && j < otherCommand.keywordlist.size()) {
- if (!keywordlist.get(i).equals(other.keywordlist.get(j))) {
- return keywordlist.get(i).compareTo(other.keywordlist.get(j));
+ if (!keywordlist.get(i).equals(otherCommand.keywordlist.get(j))) {
+ return keywordlist.get(i).compareTo(otherCommand.keywordlist.get(j));
}
} else if (i == keywordlist.size() && j == otherCommand.keywordlist.size()) {
break;
@@ -229,12 +250,43 @@ public class CommandLineCommand implements Comparable<CommandLineCommand> {
return 1;
}
}
- if (!argumentList.equals(other.argumentList)) {
- return (argumentList.hashCode() - other.argumentList.hashCode());
+
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((apiMethod == null) ? 0 : apiMethod.hashCode());
+ result = prime * result + argumentList.hashCode();
+ result = prime * result + ((description == null) ? 0 : description.hashCode());
+ result = prime * result + keywordlist.hashCode();
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + (systemCommand ? 1231 : 1237);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null) {
+ return false;
}
- if (systemCommand != other.systemCommand) {
- return (this.hashCode() - other.hashCode());
+
+ if (getClass() != obj.getClass()) {
+ return false;
}
- return apiMethod.compareTo(other.apiMethod);
+
+ return this.compareTo((CommandLineCommand) obj) == 0;
}
}
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java
index 4f0aeb58b..b5e82103d 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java
@@ -58,6 +58,7 @@ public class CommandLineEditorLoop {
// Recurring string constants
private static final String COMMAND = "command ";
+ private static final String COMMAND_LINE_ERROR = "command line error";
// The model handler that is handling the API towards the Apex model being editied
private final ApexModelHandler modelHandler;
@@ -134,7 +135,7 @@ public class CommandLineEditorLoop {
catch (final CommandLineException e) {
writer.println(e.getMessage());
errorCount++;
- LOGGER.debug("command line error", e);
+ LOGGER.debug(COMMAND_LINE_ERROR, e);
continue;
}
@@ -163,7 +164,7 @@ public class CommandLineEditorLoop {
catch (final CommandLineException e) {
writer.println(e.getMessage());
errorCount++;
- LOGGER.debug("command line error", e);
+ LOGGER.debug(COMMAND_LINE_ERROR, e);
continue;
}
@@ -204,10 +205,10 @@ public class CommandLineEditorLoop {
catch (final CommandLineException e) {
writer.println(e.getMessage());
errorCount++;
- LOGGER.debug("command line error", e);
+ LOGGER.debug(COMMAND_LINE_ERROR, e);
} catch (final Exception e) {
e.printStackTrace(writer);
- LOGGER.error("command line error", e);
+ LOGGER.error(COMMAND_LINE_ERROR, e);
}
}
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java
index a37d07fab..3465a6dd8 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java
@@ -107,6 +107,45 @@ public class CommandLineParameterParser {
"too many command line arguments specified : " + Arrays.toString(remainingArgs));
}
+ parseSIngleLetterOptions(commandLine, parameters);
+ parseDoubleLetterOptions(commandLine, parameters);
+
+ return parameters;
+ }
+
+ /**
+ * Parse options with just a single letter.
+ *
+ * @param commandLine the command line
+ * @param parameters the parsed parameters
+ */
+ private void parseDoubleLetterOptions(CommandLine commandLine, final CommandLineParameters parameters) {
+ if (commandLine.hasOption("nl")) {
+ parameters.setSuppressLog(true);
+ }
+ if (commandLine.hasOption("nm")) {
+ parameters.setSuppressModelOutput(true);
+ }
+ if (commandLine.hasOption("if")) {
+ parameters.setIgnoreCommandFailuresSet(true);
+ parameters.setIgnoreCommandFailures(Boolean.valueOf(commandLine.getOptionValue("if")));
+ } else {
+ parameters.setIgnoreCommandFailuresSet(false);
+ }
+ if (commandLine.hasOption("wd")) {
+ parameters.setWorkingDirectory(commandLine.getOptionValue("wd"));
+ } else {
+ parameters.setWorkingDirectory(Paths.get("").toAbsolutePath().toString());
+ }
+ }
+
+ /**
+ * Parse options with two letters.
+ *
+ * @param commandLine the command line
+ * @param parameters the parsed parameters
+ */
+ private void parseSIngleLetterOptions(CommandLine commandLine, final CommandLineParameters parameters) {
if (commandLine.hasOption('h')) {
parameters.setHelp(true);
}
@@ -122,31 +161,12 @@ public class CommandLineParameterParser {
if (commandLine.hasOption('l')) {
parameters.setLogFileName(commandLine.getOptionValue('l'));
}
- if (commandLine.hasOption("nl")) {
- parameters.setSuppressLog(true);
- }
- if (commandLine.hasOption("nm")) {
- parameters.setSuppressModelOutput(true);
- }
if (commandLine.hasOption('i')) {
parameters.setInputModelFileName(commandLine.getOptionValue('i'));
}
if (commandLine.hasOption('o')) {
parameters.setOutputModelFileName(commandLine.getOptionValue('o'));
}
- if (commandLine.hasOption("if")) {
- parameters.setIgnoreCommandFailuresSet(true);
- parameters.setIgnoreCommandFailures(Boolean.valueOf(commandLine.getOptionValue("if")));
- } else {
- parameters.setIgnoreCommandFailuresSet(false);
- }
- if (commandLine.hasOption("wd")) {
- parameters.setWorkingDirectory(commandLine.getOptionValue("wd"));
- } else {
- parameters.setWorkingDirectory(Paths.get("").toAbsolutePath().toString());
- }
-
- return parameters;
}
/**
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java
index c8bc7a083..c16bbf568 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java
@@ -186,4 +186,31 @@ public class KeywordNode implements Comparable<KeywordNode> {
}
return command.compareTo(otherKeywordNode.command);
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((children == null) ? 0 : children.hashCode());
+ result = prime * result + ((command == null) ? 0 : command.hashCode());
+ result = prime * result + ((keyword == null) ? 0 : keyword.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null) {
+ return false;
+ }
+
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+
+ return this.compareTo((KeywordNode) obj) == 0;
+ }
}