From 9b3ff5f270572a6760ff07dda9577cdadb53b088 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Tue, 7 Apr 2020 13:58:09 -0400 Subject: Address sonar issues in models Addressed the following sonar issues: - use RE2 instead of java.util Pattern for "+" and "*" - don't use deprecated methods - for Date(long), sonar appeared not to parse the argument's type correctly. Modified the code slightly to make sonar happy - duplicate blocks of code - either log or throw - missing assert in junit - for SDNR & VFC, eliminated threads, as they are unnecessary - duplicate code block in different branches - useless assignments - redeclaring abstract methods - cyclomatic complexity - used lombok in some cases (e.g., EqualsAndHashCode) - assert argument order - actually deleted ControlLoopTargetType, because it is not needed and sonar complains regardless of which order is used - add private constructor to utility classes - use StandardCharsets instead of literals Also: - added logback-test.xml to SO to eliminate the voluminous output from the junit test Issue-ID: POLICY-2305 Change-Id: I586c331781bedbd54a115a71847d04d293689445 Signed-off-by: Jim Hahn --- .../main/java/org/onap/policy/models/base/PfConceptContainer.java | 5 ++++- .../src/main/java/org/onap/policy/models/base/PfTimestampKey.java | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'models-base') diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java index b94900430..97522c4d9 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java @@ -21,6 +21,7 @@ package org.onap.policy.models.base; +import com.google.re2j.Pattern; import java.lang.reflect.ParameterizedType; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -73,6 +74,8 @@ public class PfConceptContainer ex implements PfConceptGetter, PfAuthorative>> { private static final long serialVersionUID = -324211738823208318L; + private static final Pattern KEY_ID_PATTERN = Pattern.compile(PfKey.KEY_ID_REGEXP); + @EmbeddedId private PfConceptKey key; @@ -183,7 +186,7 @@ public class PfConceptContainer ex for (Entry incomingConceptEntry : incomingConceptMap.entrySet()) { PfConceptKey conceptKey = new PfConceptKey(); - if (incomingConceptEntry.getKey().matches(PfKey.KEY_ID_REGEXP)) { + if (KEY_ID_PATTERN.matches(incomingConceptEntry.getKey())) { conceptKey = new PfConceptKey(incomingConceptEntry.getKey()); } else { conceptKey.setName(incomingConceptEntry.getKey()); diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java index a2f11290d..5be9b5f58 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java @@ -3,6 +3,7 @@ * ONAP Policy Model * ================================================================================ * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,7 +63,8 @@ public class PfTimestampKey extends PfKeyImpl { */ public PfTimestampKey(@NonNull final PfTimestampKey copyConcept) { super(copyConcept); - this.timeStamp = new Date(copyConcept.getTimeStamp().getTime()); + long millis = copyConcept.getTimeStamp().getTime(); + this.timeStamp = new Date(millis); } /** -- cgit 1.2.3-korg