}
public static boolean checkString(String value) {
- return ((value != null) && (value.compareTo("") != 0));
+ return ((value != null) && (!value.isEmpty()));
}
public static ComplianceCheckResult check(TopologyConstraint tc) {
boolean result = true;
String message = "";
- LOG.info("tc = {}", tc.toString());
- if (tc.getAvoidTopology() == null || tc.getExcludeLink() == null || tc.getExcludeNode() == null || tc
- .getExcludePath() == null || tc.getIncludeLink() == null || tc.getIncludeNode() == null || tc
- .getIncludePath() == null || tc.getIncludeTopology() == null || tc
- .getPreferredTransportLayer() == null) {
+ LOG.info("tc = {}", tc);
+ if (checkNull(tc)) {
LOG.info("tc is null");
- result = true;
message = "Topology constraints are not managet yet";
- } else if (tc.getAvoidTopology().isEmpty() || tc.getExcludeLink().isEmpty() || tc.getExcludeNode().isEmpty()
- || tc
- .getExcludePath().isEmpty() || tc.getIncludeLink().isEmpty() || tc.getIncludeNode().isEmpty() || tc
- .getIncludePath().isEmpty() || tc.getIncludeTopology().isEmpty() || tc.getPreferredTransportLayer()
- .isEmpty()) {
+ } else if (checkEmpty(tc)) {
result = false;
message = "Topology constraints are not managet yet";
}
return new ComplianceCheckResult(result, message);
}
+
+ private static boolean checkNull(TopologyConstraint tc) {
+ if (tc == null) {
+ return true;
+ }
+ if (tc.getAvoidTopology() == null) {
+ return true;
+ }
+ if (tc.getExcludeLink() == null) {
+ return true;
+ }
+ if (tc.getExcludeNode() == null) {
+ return true;
+ }
+ if (tc.getExcludePath() == null) {
+ return true;
+ }
+ if (tc.getIncludeLink() == null) {
+ return true;
+ }
+ if (tc.getIncludeNode() == null) {
+ return true;
+ }
+ if (tc.getIncludePath() == null) {
+ return true;
+ }
+ if (tc.getIncludeTopology() == null) {
+ return true;
+ }
+ return tc.getPreferredTransportLayer() == null;
+ }
+
+ //Due to number of check to do, cyclomatic complexity cannot be easily improved
+ @java.lang.SuppressWarnings("squid:MethodCyclomaticComplexity")
+ private static boolean checkEmpty(TopologyConstraint tc) {
+ if (tc == null) {
+ return true;
+ }
+ if (tc.getAvoidTopology() != null && tc.getAvoidTopology().isEmpty()) {
+ return true;
+ }
+ if (tc.getExcludeLink() != null && tc.getExcludeLink().isEmpty()) {
+ return true;
+ }
+ if (tc.getExcludeNode() != null && tc.getExcludeNode().isEmpty()) {
+ return true;
+ }
+ if (tc.getExcludePath() != null && tc.getExcludePath().isEmpty()) {
+ return true;
+ }
+ if (tc.getIncludeLink() != null && tc.getIncludeLink().isEmpty()) {
+ return true;
+ }
+ if (tc.getIncludeNode() != null && tc.getIncludeNode().isEmpty()) {
+ return true;
+ }
+ if (tc.getIncludePath() != null && tc.getIncludePath().isEmpty()) {
+ return true;
+ }
+ if (tc.getIncludeTopology() != null && tc.getIncludeTopology().isEmpty()) {
+ return true;
+ }
+ return tc.getPreferredTransportLayer() != null && tc.getPreferredTransportLayer().isEmpty();
+
+ }
}