diff options
author | Jim Hahn <jrh3@att.com> | 2021-05-12 13:25:06 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2021-05-12 13:31:28 -0400 |
commit | d00c73842c6f8e7bb00b29d2fb5dd63b9cde4bfe (patch) | |
tree | f311f6070754db545754ed287455f90261f4c424 /models-base | |
parent | 385e119cf90ee2ba83377115c98b3cf60f993158 (diff) |
Fix sonars in policy models
Fixed:
- a few other "var" cases
- use re2j instead of java.util.regex
- use correct class for constants
- remove unused constants
Issue-ID: POLICY-3094
Change-Id: Ifcb2b0623e8df0527f0a279e666d062422978ded
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-base')
9 files changed, 29 insertions, 27 deletions
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 e7cab460e..a98a7ac54 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 @@ -137,8 +137,8 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex this.conceptMap = new TreeMap<>(); for (final Entry<PfConceptKey, C> conceptMapEntry : copyConcept.conceptMap.entrySet()) { - PfConceptKey newK = new PfConceptKey(conceptMapEntry.getKey()); - C newC = PfUtils.makeCopy(conceptMapEntry.getValue()); + var newK = new PfConceptKey(conceptMapEntry.getKey()); + var newC = PfUtils.makeCopy(conceptMapEntry.getValue()); this.conceptMap.put(newK, newC); } } @@ -186,7 +186,7 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex // Add the map entries one by one for (Entry<String, A> incomingConceptEntry : incomingConceptMap.entrySet()) { - PfConceptKey conceptKey = new PfConceptKey(); + var conceptKey = new PfConceptKey(); if (KEY_ID_PATTERN.matches(incomingConceptEntry.getKey())) { conceptKey = new PfConceptKey(incomingConceptEntry.getKey()); } else { @@ -203,7 +203,7 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex incomingConceptEntry.getValue().setVersion(findConceptField(conceptKey, conceptKey.getVersion(), incomingConceptEntry.getValue(), PfNameVersion::getDefinedVersion)); - C jpaConcept = getConceptNewInstance(); + var jpaConcept = getConceptNewInstance(); // This cast allows us to call the fromAuthorative method @SuppressWarnings("unchecked") PfAuthorative<A> authoritiveImpl = (PfAuthorative<A>) jpaConcept; @@ -260,7 +260,7 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex * @return the validation result */ private ValidationResult validateConceptMap() { - BeanValidationResult result = new BeanValidationResult("conceptMap", conceptMap); + var result = new BeanValidationResult("conceptMap", conceptMap); for (final Entry<PfConceptKey, C> conceptEntry : conceptMap.entrySet()) { BeanValidationResult result2 = null; @@ -318,7 +318,7 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex return getAll(conceptKeyName, conceptKeyVersion); } else { final Set<C> returnSet = new TreeSet<>(); - C foundConcept = get(conceptKeyName, conceptKeyVersion); + var foundConcept = get(conceptKeyName, conceptKeyVersion); if (foundConcept != null) { returnSet.add(foundConcept); } diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptGetterImpl.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptGetterImpl.java index 7a3e05582..3c186bbf8 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptGetterImpl.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptGetterImpl.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -54,7 +55,7 @@ public class PfConceptGetterImpl<C> implements PfConceptGetter<C> { Assertions.argumentNotNull(conceptKeyName, "conceptKeyName may not be null"); // The very fist key that could have this name - final PfConceptKey lowestArtifactKey = new PfConceptKey(conceptKeyName, PfKey.NULL_KEY_VERSION); + final var lowestArtifactKey = new PfConceptKey(conceptKeyName, PfKey.NULL_KEY_VERSION); // Check if we found a key for our name PfConceptKey foundKey = conceptMap.ceilingKey(lowestArtifactKey); @@ -100,7 +101,7 @@ public class PfConceptGetterImpl<C> implements PfConceptGetter<C> { } // The very fist key that could have this name - final PfConceptKey lowestArtifactKey = new PfConceptKey(conceptKeyName, PfKey.NULL_KEY_VERSION); + final var lowestArtifactKey = new PfConceptKey(conceptKeyName, PfKey.NULL_KEY_VERSION); if (conceptKeyVersion != null) { lowestArtifactKey.setVersion(conceptKeyVersion); } diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfKeyImpl.java b/models-base/src/main/java/org/onap/policy/models/base/PfKeyImpl.java index b6d12198c..3309fe9da 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfKeyImpl.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfKeyImpl.java @@ -169,7 +169,7 @@ public abstract class PfKeyImpl extends PfKey { } final PfKeyImpl otherConceptKey = (PfKeyImpl) otherKey; - final Compatibility compatibility = this.getCompatibility(otherConceptKey); + final var compatibility = this.getCompatibility(otherConceptKey); return !(compatibility == Compatibility.DIFFERENT || compatibility == Compatibility.MAJOR); } diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfModel.java b/models-base/src/main/java/org/onap/policy/models/base/PfModel.java index a73616df9..b7f074a5e 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfModel.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfModel.java @@ -160,7 +160,7 @@ public abstract class PfModel extends PfConcept { validateKeyNotNull(result, KEYS_TOKEN, artifactKey); - BeanValidationResult result2 = new BeanValidationResult(KEYS_TOKEN, artifactKey); + var result2 = new BeanValidationResult(KEYS_TOKEN, artifactKey); // Null key name start check if (artifactKey.getName().toUpperCase().startsWith(PfKey.NULL_KEY_NAME)) { @@ -191,7 +191,7 @@ public abstract class PfModel extends PfConcept { addResult(result, KEYS_TOKEN, referenceKey, IS_A_NULL_KEY); } - BeanValidationResult result2 = new BeanValidationResult(KEYS_TOKEN, referenceKey); + var result2 = new BeanValidationResult(KEYS_TOKEN, referenceKey); // Null parent key check if (referenceKey.getParentConceptKey().isNullKey()) { diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfModelService.java b/models-base/src/main/java/org/onap/policy/models/base/PfModelService.java index 1f4b8f66b..7353915b9 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfModelService.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfModelService.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -76,7 +77,7 @@ public abstract class PfModelService { */ @SuppressWarnings("unchecked") public static <M extends PfConcept> M getModel(@NonNull final String modelKey) { - final M model = (M) modelMap.get(modelKey); + final var model = (M) modelMap.get(modelKey); if (model == null) { throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java b/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java index 342fbab73..843fde333 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019, 2021 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. @@ -21,13 +21,13 @@ package org.onap.policy.models.base; +import com.google.re2j.Pattern; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.function.Function; import java.util.function.Predicate; -import java.util.regex.Pattern; /** * Interface for filtering a list of concepts. @@ -103,7 +103,7 @@ public interface PfObjectFilter<T> { return item -> true; } - Pattern pat = Pattern.compile(pattern); + var pat = Pattern.compile(pattern); return item -> { String value = extractor.apply(item); @@ -126,11 +126,11 @@ public interface PfObjectFilter<T> { List<T> filteredList = new ArrayList<>(originalList); Collections.sort(filteredList, versionComparator); - int icur = 0; - for (int j = 1; j < filteredList.size(); j++) { + var icur = 0; + for (var j = 1; j < filteredList.size(); j++) { // Get the current and last element - T curElement = filteredList.get(icur); - T lastElement = filteredList.get(j); + var curElement = filteredList.get(icur); + var lastElement = filteredList.get(j); /* * The list is sorted so if the last element name is the same as the current element name, the current diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java index b25d4632b..acbebf959 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019,2021 Nordix Foundation. - * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2021 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. @@ -205,7 +205,7 @@ public class PfReferenceKey extends PfKey { * the key ID in a format that respects the KEY_ID_REGEXP */ public PfReferenceKey(final String id) { - final String conditionedId = Assertions.validateStringParameter("id", id, REFERENCE_KEY_ID_REGEXP); + final var conditionedId = Assertions.validateStringParameter("id", id, REFERENCE_KEY_ID_REGEXP); // Split on colon, if the id passes the regular expression test above // it'll have just three colons separating the parent name, @@ -253,9 +253,9 @@ public class PfReferenceKey extends PfKey { @Override public boolean isNullKey() { - return (PfReferenceKey.NULL_KEY_NAME.equals(this.getParentKeyName()) && PfReferenceKey.NULL_KEY_VERSION - .equals(this.getParentKeyVersion()) && PfReferenceKey.NULL_KEY_NAME.equals(this.getParentLocalName()) - && PfReferenceKey.NULL_KEY_NAME.equals(this.getLocalName())); + return (PfKey.NULL_KEY_NAME.equals(this.getParentKeyName()) && PfKey.NULL_KEY_VERSION + .equals(this.getParentKeyVersion()) && PfKey.NULL_KEY_NAME.equals(this.getParentLocalName()) + && PfKey.NULL_KEY_NAME.equals(this.getLocalName())); } /** diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfValidator.java b/models-base/src/main/java/org/onap/policy/models/base/PfValidator.java index 57cc3c81f..db7b9d63e 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfValidator.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfValidator.java @@ -97,7 +97,7 @@ public class PfValidator extends BeanValidator { return true; } - PfKey pfkey = (PfKey) value; + var pfkey = (PfKey) value; if (annot.keyNotNull() && pfkey.isNullKey()) { result.addResult(fieldName, xlate(pfkey), ValidationStatus.INVALID, Validated.IS_A_NULL_KEY); return false; @@ -111,7 +111,7 @@ public class PfValidator extends BeanValidator { return true; } - BeanValidationResult result2 = new BeanValidationResult(fieldName, value); + var result2 = new BeanValidationResult(fieldName, value); PfKeyImpl keyimpl = (PfKeyImpl) pfkey; diff --git a/models-base/src/main/java/org/onap/policy/models/base/Validated.java b/models-base/src/main/java/org/onap/policy/models/base/Validated.java index 6ed1a845a..711dd7be6 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/Validated.java +++ b/models-base/src/main/java/org/onap/policy/models/base/Validated.java @@ -106,7 +106,7 @@ public class Validated { public static void validateKeyVersionNotNull(BeanValidationResult result, @NonNull String fieldName, PfConceptKey key) { if (key != null && key.isNullVersion()) { - BeanValidationResult result2 = new BeanValidationResult(fieldName, key); + var result2 = new BeanValidationResult(fieldName, key); result2.addResult(makeNullResult(PfKeyImpl.VERSION_TOKEN, key.getVersion())); result.addResult(result2); } |