summaryrefslogtreecommitdiffstats
path: root/common-parameters
diff options
context:
space:
mode:
Diffstat (limited to 'common-parameters')
-rw-r--r--common-parameters/src/main/java/org/onap/policy/common/parameters/BeanValidationResult.java8
-rw-r--r--common-parameters/src/main/java/org/onap/policy/common/parameters/BeanValidator.java14
-rw-r--r--common-parameters/src/main/java/org/onap/policy/common/parameters/FieldValidator.java16
-rw-r--r--common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterException.java7
-rw-r--r--common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterService.java15
-rw-r--r--common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java10
-rw-r--r--common-parameters/src/main/java/org/onap/policy/common/parameters/ValueValidator.java4
7 files changed, 38 insertions, 36 deletions
diff --git a/common-parameters/src/main/java/org/onap/policy/common/parameters/BeanValidationResult.java b/common-parameters/src/main/java/org/onap/policy/common/parameters/BeanValidationResult.java
index fa0c66c0..e1620530 100644
--- a/common-parameters/src/main/java/org/onap/policy/common/parameters/BeanValidationResult.java
+++ b/common-parameters/src/main/java/org/onap/policy/common/parameters/BeanValidationResult.java
@@ -88,7 +88,7 @@ public class BeanValidationResult extends ValidationResultImpl {
* @return {@code true} if the value is not null, {@code false} otherwise
*/
public boolean validateNotNull(String subName, Object subObject) {
- ObjectValidationResult result = new ObjectValidationResult(subName, subObject);
+ var result = new ObjectValidationResult(subName, subObject);
if (result.validateNotNull()) {
return true;
@@ -126,7 +126,7 @@ public class BeanValidationResult extends ValidationResultImpl {
return true;
}
- BeanValidationResult result = new BeanValidationResult(listName, null);
+ var result = new BeanValidationResult(listName, null);
for (T item : list) {
if (item == null) {
result.addResult("item", item, ValidationStatus.INVALID, "null");
@@ -158,7 +158,7 @@ public class BeanValidationResult extends ValidationResultImpl {
return true;
}
- BeanValidationResult result = new BeanValidationResult(mapName, null);
+ var result = new BeanValidationResult(mapName, null);
for (Entry<String, V> ent : map.entrySet()) {
entryValidator.accept(result, ent);
}
@@ -186,7 +186,7 @@ public class BeanValidationResult extends ValidationResultImpl {
return null;
}
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
builder.append(initialIndentation);
builder.append('"');
diff --git a/common-parameters/src/main/java/org/onap/policy/common/parameters/BeanValidator.java b/common-parameters/src/main/java/org/onap/policy/common/parameters/BeanValidator.java
index 947def42..4ed7e42c 100644
--- a/common-parameters/src/main/java/org/onap/policy/common/parameters/BeanValidator.java
+++ b/common-parameters/src/main/java/org/onap/policy/common/parameters/BeanValidator.java
@@ -55,7 +55,7 @@ public class BeanValidator {
* @return the validation result
*/
public BeanValidationResult validateTop(String name, Object object) {
- BeanValidationResult result = new BeanValidationResult(name, object);
+ var result = new BeanValidationResult(name, object);
if (object == null) {
return result;
}
@@ -94,7 +94,7 @@ public class BeanValidator {
*/
private void validateFields(BeanValidationResult result, Object object, Class<?> clazz) {
for (Field field : clazz.getDeclaredFields()) {
- FieldValidator validator = makeFieldValidator(clazz, field);
+ var validator = makeFieldValidator(clazz, field);
validator.validateField(result, object);
}
}
@@ -337,8 +337,8 @@ public class BeanValidator {
Collection<?> list = (Collection<?>) value;
- BeanValidationResult result2 = new BeanValidationResult(fieldName, value);
- int count = 0;
+ var result2 = new BeanValidationResult(fieldName, value);
+ var count = 0;
for (Object item : list) {
itemValidator.validateValue(result2, String.valueOf(count++), item);
}
@@ -370,12 +370,12 @@ public class BeanValidator {
Map<?, ?> map = (Map<?, ?>) value;
- BeanValidationResult result2 = new BeanValidationResult(fieldName, value);
+ var result2 = new BeanValidationResult(fieldName, value);
for (Entry<?, ?> entry : map.entrySet()) {
String name = getEntryName(entry);
- BeanValidationResult result3 = new BeanValidationResult(name, entry);
+ var result3 = new BeanValidationResult(name, entry);
keyValidator.validateValue(result3, "key", entry.getKey());
valueValidator.validateValue(result3, "value", entry.getValue());
@@ -399,7 +399,7 @@ public class BeanValidator {
* @return a name for the entry
*/
protected <K, V> String getEntryName(Map.Entry<K, V> entry) {
- K key = entry.getKey();
+ var key = entry.getKey();
if (key == null) {
return "";
}
diff --git a/common-parameters/src/main/java/org/onap/policy/common/parameters/FieldValidator.java b/common-parameters/src/main/java/org/onap/policy/common/parameters/FieldValidator.java
index efe48bb3..51c5d57f 100644
--- a/common-parameters/src/main/java/org/onap/policy/common/parameters/FieldValidator.java
+++ b/common-parameters/src/main/java/org/onap/policy/common/parameters/FieldValidator.java
@@ -121,7 +121,7 @@ public class FieldValidator extends ValueValidator {
return;
}
- AnnotatedType tannot = field.getAnnotatedType();
+ var tannot = field.getAnnotatedType();
if (!(tannot instanceof AnnotatedParameterizedType)) {
return;
}
@@ -131,7 +131,7 @@ public class FieldValidator extends ValueValidator {
return;
}
- ItemValidator itemValidator = new ItemValidator(validator, targs[0]);
+ var itemValidator = new ItemValidator(validator, targs[0]);
if (itemValidator.isEmpty()) {
return;
}
@@ -149,7 +149,7 @@ public class FieldValidator extends ValueValidator {
return;
}
- AnnotatedType tannot = field.getAnnotatedType();
+ var tannot = field.getAnnotatedType();
if (!(tannot instanceof AnnotatedParameterizedType)) {
return;
}
@@ -159,8 +159,8 @@ public class FieldValidator extends ValueValidator {
return;
}
- ItemValidator keyValidator = new ItemValidator(validator, targs[0]);
- ItemValidator valueValidator = new ItemValidator(validator, targs[1]);
+ var keyValidator = new ItemValidator(validator, targs[0]);
+ var valueValidator = new ItemValidator(validator, targs[1]);
if (keyValidator.isEmpty() && valueValidator.isEmpty()) {
return;
}
@@ -226,7 +226,7 @@ public class FieldValidator extends ValueValidator {
public <T extends Annotation> T getAnnotation(Class<T> annotClass) {
// field annotation takes precedence over class annotation
- T annot = field.getAnnotation(annotClass);
+ var annot = field.getAnnotation(annotClass);
if (annot != null) {
setFieldAnnotated(true);
return annot;
@@ -243,8 +243,8 @@ public class FieldValidator extends ValueValidator {
* @return the field's "getter" method, or {@code null} if it is not found
*/
private Method getAccessor(Class<?> clazz, String fieldName) {
- String capname = StringUtils.capitalize(fieldName);
- Method accessor2 = getMethod(clazz, "get" + capname);
+ var capname = StringUtils.capitalize(fieldName);
+ var accessor2 = getMethod(clazz, "get" + capname);
if (accessor2 != null) {
return accessor2;
}
diff --git a/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterException.java b/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterException.java
index 0b29a4e6..84faa9c8 100644
--- a/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterException.java
+++ b/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterException.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * 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.
@@ -84,15 +85,15 @@ public class ParameterException extends Exception {
/**
* Build a cascaded message from an exception and all its nested exceptions.
- *
+ *
* @param throwable the top level exception
* @return cascaded message string
*/
public static String buildCascadedMessage(final Throwable throwable) {
- final StringBuilder builder = new StringBuilder();
+ final var builder = new StringBuilder();
builder.append(throwable.getMessage());
- for (Throwable t = throwable; t != null; t = t.getCause()) {
+ for (var t = throwable; t != null; t = t.getCause()) {
builder.append("\ncaused by: ");
builder.append(t.getMessage());
}
diff --git a/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterService.java b/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterService.java
index 358e5535..7bf0ac5f 100644
--- a/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterService.java
+++ b/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterService.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -27,10 +28,10 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* The parameter service makes ONAP PF parameter groups available to all classes in a JVM.
- *
+ *
* <p>The reason for having a parameter service is to avoid having to pass parameters down long call chains in modules
* such as PDPs and editors. The parameter service makes correct and verified parameters available statically.
- *
+ *
* <p>The parameter service must be used with care because changing a parameter set anywhere in a JVM will affect all
* users of those parameters anywhere in the JVM.
*
@@ -70,7 +71,7 @@ public abstract class ParameterService {
if (overwrite && parameterGroupMap.containsKey(parameterGroup.getName())) {
deregister(parameterGroup);
}
-
+
register(parameterGroup);
}
@@ -104,7 +105,7 @@ public abstract class ParameterService {
*/
public static <T extends ParameterGroup> T get(final String parameterGroupName) {
@SuppressWarnings("unchecked")
- final T parameterGroup = (T) parameterGroupMap.get(parameterGroupName);
+ final var parameterGroup = (T) parameterGroupMap.get(parameterGroupName);
if (parameterGroup == null) {
throw new ParameterRuntimeException("\"" + parameterGroupName + "\" not found in parameter service");
diff --git a/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java b/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java
index 35837376..b68c62e2 100644
--- a/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java
+++ b/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * 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.
@@ -73,7 +73,7 @@ public class ParameterValidationResult implements ValidationResult {
* @param parameterValue field's value
*/
private void checkMinValue(final Field field, final Object parameterValue) {
- Min minAnnot = field.getAnnotation(Min.class);
+ var minAnnot = field.getAnnotation(Min.class);
if (minAnnot != null && ((Number) parameterValue).longValue() < minAnnot.value()) {
setResult(ValidationStatus.INVALID, "must be >= " + minAnnot.value());
}
@@ -86,7 +86,7 @@ public class ParameterValidationResult implements ValidationResult {
* @param parameterValue field's value
*/
private void checkMaxValue(final Field field, final Object parameterValue) {
- Max maxAnnot = field.getAnnotation(Max.class);
+ var maxAnnot = field.getAnnotation(Max.class);
if (maxAnnot != null && ((Number) parameterValue).longValue() > maxAnnot.value()) {
setResult(ValidationStatus.INVALID, "must be <= " + maxAnnot.value());
}
@@ -102,7 +102,7 @@ public class ParameterValidationResult implements ValidationResult {
* @return the field's annotation, or {@code null} if it does not exist
*/
private static <T extends Annotation> T getAnyAnnotation(final Field field, Class<T> annotClass) {
- T annot = field.getAnnotation(annotClass);
+ var annot = field.getAnnotation(annotClass);
if (annot != null) {
return annot;
}
@@ -157,7 +157,7 @@ public class ParameterValidationResult implements ValidationResult {
return null;
}
- StringBuilder validationResultBuilder = new StringBuilder();
+ var validationResultBuilder = new StringBuilder();
validationResultBuilder.append(initialIndentation);
validationResultBuilder.append("field \"");
diff --git a/common-parameters/src/main/java/org/onap/policy/common/parameters/ValueValidator.java b/common-parameters/src/main/java/org/onap/policy/common/parameters/ValueValidator.java
index 6a641a17..a8a0e614 100644
--- a/common-parameters/src/main/java/org/onap/policy/common/parameters/ValueValidator.java
+++ b/common-parameters/src/main/java/org/onap/policy/common/parameters/ValueValidator.java
@@ -103,7 +103,7 @@ public class ValueValidator {
* @param checker function to validate the value
*/
public <T extends Annotation> void addAnnotation(Class<T> annotClass, Checker checker) {
- T annot = getAnnotation(annotClass);
+ var annot = getAnnotation(annotClass);
if (annot != null) {
checkers.add(checker);
@@ -122,7 +122,7 @@ public class ValueValidator {
* @param checker function to validate the value
*/
public <T extends Annotation> void addAnnotation(Class<T> annotClass, CheckerWithAnnot<T> checker) {
- T annot = getAnnotation(annotClass);
+ var annot = getAnnotation(annotClass);
if (annot != null) {
checkers.add((result, fieldName, value) -> checker.test(result, fieldName, annot, value));
}