From 4723527133e158ba48bf5a1eb9eec731af2ae1f8 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Fri, 2 Feb 2018 09:43:33 -0500 Subject: [PATCH] Technical debt reduction * empty constructor * Unnecessary imports * try-with-resources * missing @Override * useless parens * proper boolean detection * useless imports * Use Set vs HashSet * moving statements to separate lines Issue-ID: POLICY-477 Change-Id: I5fae9c5c8e7d30f731a1caefc8a5271cf382e0a0 Signed-off-by: Pamela Dragosh --- .../main/java/org/onap/policy/api/PolicyEngineException.java | 1 + .../java/org/onap/policy/models/APIPolicyConfigResponse.java | 1 + .../main/java/org/onap/policy/std/ManualClientEndUEB.java | 3 ++- .../src/main/java/org/onap/policy/std/MatchStore.java | 12 +++++------- .../src/main/java/org/onap/policy/std/StdPolicyEngine.java | 10 +++++----- .../src/main/java/org/onap/policy/std/StdStatus.java | 8 ++++---- .../test/java/org/onap/policy/std/test/MatchStoreTest.java | 4 ++-- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyEngineException.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyEngineException.java index 6529a159e..90a3500d8 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyEngineException.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyEngineException.java @@ -29,6 +29,7 @@ public class PolicyEngineException extends Exception{ private static final long serialVersionUID = 4945973094200118969L; public PolicyEngineException() { + super(); } public PolicyEngineException(String message) { diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/models/APIPolicyConfigResponse.java b/PolicyEngineAPI/src/main/java/org/onap/policy/models/APIPolicyConfigResponse.java index e65413f50..045aa3dfb 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/models/APIPolicyConfigResponse.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/models/APIPolicyConfigResponse.java @@ -96,6 +96,7 @@ public class APIPolicyConfigResponse implements APIConfigResponse { public void setResponseAttributes(Map responseAttributes){ this.responseAttributes = responseAttributes; } + @Override public Map getResponseAttributes(){ return responseAttributes; } diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndUEB.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndUEB.java index 8590f6a5b..c04736e86 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndUEB.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndUEB.java @@ -62,7 +62,8 @@ public class ManualClientEndUEB { return null; } if(scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) { - boolean removed = false, updated = false; + boolean removed = false; + boolean updated = false; if(notification.getRemovedPolicies()!=null && !notification.getRemovedPolicies().isEmpty()){ removed = true; } diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/MatchStore.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/MatchStore.java index ecdafe43c..e5204d894 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/MatchStore.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/MatchStore.java @@ -22,16 +22,14 @@ package org.onap.policy.std; import java.util.Collection; import java.util.HashSet; +import java.util.Set; import org.onap.policy.api.LoadedPolicy; import org.onap.policy.api.NotificationType; import org.onap.policy.api.PDPNotification; import org.onap.policy.api.RemovedPolicy; -import org.onap.policy.std.StdLoadedPolicy; -import org.onap.policy.std.StdPDPNotification; -import org.onap.policy.std.StdRemovedPolicy; - -import org.onap.policy.common.logging.flexlogger.*; +import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.logging.flexlogger.Logger; public class MatchStore { private static HashSet matchStore = new HashSet<>(); @@ -41,7 +39,7 @@ public class MatchStore { // Empty Constructor } - public static HashSet getMatchStore() { + public static Set getMatchStore() { return matchStore; } @@ -98,7 +96,7 @@ public class MatchStore { } // IF not a match then add it to the MatchStore - if(match==false){ + if(! match){ matchStore.add(newMatch); } } diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java index d08ea29f9..e0a6d2d76 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java @@ -632,11 +632,11 @@ public class StdPolicyEngine { try { switch (policyConfigResponse.getType()) { case JSON: - JsonReader jsonReader = Json - .createReader(new StringReader(policyConfigResponse.getConfig())); - JsonObject object = jsonReader.readObject(); - jsonReader.close(); - policyConfig.setJsonObject(object); + try (JsonReader jsonReader = Json + .createReader(new StringReader(policyConfigResponse.getConfig())) ) { + JsonObject object = jsonReader.readObject(); + policyConfig.setJsonObject(object); + } break; case OTHER: policyConfig.setOther(policyConfigResponse.getConfig()); diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdStatus.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdStatus.java index b1b60dbd8..664c29c53 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdStatus.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdStatus.java @@ -152,7 +152,7 @@ public class StdStatus extends StdPolicyResponse implements PolicyConfig, Policy @Override public String getPolicyName() { if(policyName!=null && policyName.contains(".xml")){ - return (policyName.substring(0, policyName.substring(0, policyName.lastIndexOf('.')).lastIndexOf('.'))); + return policyName.substring(0, policyName.substring(0, policyName.lastIndexOf('.')).lastIndexOf('.')); } return policyName; } @@ -225,7 +225,7 @@ public class StdStatus extends StdPolicyResponse implements PolicyConfig, Policy public void setOther(String other) { this.other = other; } - + @Override public PolicyDecision getDecision() { return policyDecision; } @@ -236,11 +236,11 @@ public class StdStatus extends StdPolicyResponse implements PolicyConfig, Policy public void setDetails(String details){ this.details = details; } - + @Override public String getDetails(){ return details; } - + @Override public PolicyConfigType getPolicyType() { return type; } diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/MatchStoreTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/MatchStoreTest.java index e4116db1d..f5a86d17d 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/MatchStoreTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/MatchStoreTest.java @@ -23,8 +23,8 @@ package org.onap.policy.std.test; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import java.util.HashSet; import java.util.Hashtable; +import java.util.Set; import org.junit.After; import org.junit.Before; @@ -373,7 +373,7 @@ public class MatchStoreTest { public void testGetMatchStore_1() throws Exception { - HashSet result = MatchStore.getMatchStore(); + Set result = MatchStore.getMatchStore(); // add additional test code here // An unexpected exception was thrown in user code while executing this test: -- 2.16.6