diff options
Diffstat (limited to 'utils/src/main/java/org/onap/policy/common/utils/properties')
4 files changed, 36 insertions, 57 deletions
diff --git a/utils/src/main/java/org/onap/policy/common/utils/properties/BeanConfigurator.java b/utils/src/main/java/org/onap/policy/common/utils/properties/BeanConfigurator.java index 2ef91911..f8c52091 100644 --- a/utils/src/main/java/org/onap/policy/common/utils/properties/BeanConfigurator.java +++ b/utils/src/main/java/org/onap/policy/common/utils/properties/BeanConfigurator.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP - Common Modules * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * 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. @@ -20,6 +20,7 @@ package org.onap.policy.common.utils.properties; +import com.google.re2j.Pattern; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -45,6 +46,7 @@ import org.onap.policy.common.utils.properties.exception.PropertyMissingExceptio * <i>accept</i> includes the "empty" option. */ public class BeanConfigurator { + private static final Pattern COMMA_PAT = Pattern.compile(","); /** * The "empty" option that may appear within the {@link Property}'s <i>accept</i> @@ -414,7 +416,7 @@ public class BeanConfigurator { * @return {@code true} if the <i>accept</i> attribute includes "empty" */ protected boolean isEmptyOk(Property prop) { - for (String option : prop.accept().split(",")) { + for (String option : COMMA_PAT.split(prop.accept())) { if (ACCEPT_EMPTY.equals(option)) { return true; } @@ -495,7 +497,7 @@ public class BeanConfigurator { * @throws PropertyAccessException if a "get" method cannot be identified */ private Method getGetter(Field field, Property prop) throws PropertyAccessException { - String capnm = StringUtils.capitalize(field.getName()); + var capnm = StringUtils.capitalize(field.getName()); try { return getGetter(field, "get" + capnm); diff --git a/utils/src/main/java/org/onap/policy/common/utils/properties/PropertyObjectUtils.java b/utils/src/main/java/org/onap/policy/common/utils/properties/PropertyObjectUtils.java index 996f1b87..2b6e514f 100644 --- a/utils/src/main/java/org/onap/policy/common/utils/properties/PropertyObjectUtils.java +++ b/utils/src/main/java/org/onap/policy/common/utils/properties/PropertyObjectUtils.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * 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. @@ -18,28 +18,27 @@ package org.onap.policy.common.utils.properties; +import com.google.re2j.Pattern; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Utilities for generating POJOs from Properties. */ -public class PropertyObjectUtils { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class PropertyObjectUtils { public static final Logger logger = LoggerFactory.getLogger(PropertyObjectUtils.class); private static final Pattern NAME_PAT = Pattern.compile("\\[(\\d{1,3})\\]$"); - - private PropertyObjectUtils() { - // do nothing - } + private static final Pattern DOT_PAT = Pattern.compile("[.]"); /** * Converts a set of properties to a Map. Supports json-path style property names with @@ -58,7 +57,7 @@ public class PropertyObjectUtils { for (String name : properties.stringPropertyNames()) { if (name.startsWith(dottedPrefix)) { - String[] components = name.substring(pfxlen).split("[.]"); + String[] components = DOT_PAT.split(name.substring(pfxlen)); setProperty(map, components, properties.getProperty(name)); } } @@ -79,13 +78,13 @@ public class PropertyObjectUtils { final int lastComp = names.length - 1; // process all but the final component - for (int comp = 0; comp < lastComp; ++comp) { + for (var comp = 0; comp < lastComp; ++comp) { node = getNode(node, names[comp]); } // process the final component String name = names[lastComp]; - Matcher matcher = NAME_PAT.matcher(name); + var matcher = NAME_PAT.matcher(name); if (!matcher.find()) { // no subscript @@ -95,7 +94,7 @@ public class PropertyObjectUtils { // subscripted List<Object> array = getArray(node, name.substring(0, matcher.start())); - int index = Integer.parseInt(matcher.group(1)); + var index = Integer.parseInt(matcher.group(1)); expand(array, index); array.set(index, value); } @@ -109,7 +108,7 @@ public class PropertyObjectUtils { */ @SuppressWarnings("unchecked") private static Map<String, Object> getNode(Map<String, Object> map, String name) { - Matcher matcher = NAME_PAT.matcher(name); + var matcher = NAME_PAT.matcher(name); if (!matcher.find()) { // no subscript @@ -118,7 +117,7 @@ public class PropertyObjectUtils { // subscripted List<Object> array = getArray(map, name.substring(0, matcher.start())); - int index = Integer.parseInt(matcher.group(1)); + var index = Integer.parseInt(matcher.group(1)); expand(array, index); Object item = array.get(index); diff --git a/utils/src/main/java/org/onap/policy/common/utils/properties/SpecProperties.java b/utils/src/main/java/org/onap/policy/common/utils/properties/SpecProperties.java index ec7157d3..2ea94959 100644 --- a/utils/src/main/java/org/onap/policy/common/utils/properties/SpecProperties.java +++ b/utils/src/main/java/org/onap/policy/common/utils/properties/SpecProperties.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2018, 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018, 2020-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,10 +21,13 @@ package org.onap.policy.common.utils.properties; import java.util.Properties; +import lombok.AccessLevel; +import lombok.Getter; /** * Properties with an optional specialization (e.g., session name, controller name). */ +@Getter(AccessLevel.PROTECTED) public class SpecProperties extends Properties { private static final long serialVersionUID = 1L; @@ -89,7 +92,7 @@ public class SpecProperties extends Properties { return super.getProperty(key); } - String suffix = key.substring(prefix.length()); + var suffix = key.substring(prefix.length()); String val = super.getProperty(specPrefix + suffix); if (val != null) { @@ -99,14 +102,6 @@ public class SpecProperties extends Properties { return super.getProperty(key); } - protected String getPrefix() { - return prefix; - } - - protected String getSpecPrefix() { - return specPrefix; - } - @Override public final synchronized int hashCode() { throw new UnsupportedOperationException("SpecProperties cannot be hashed"); diff --git a/utils/src/main/java/org/onap/policy/common/utils/properties/exception/PropertyException.java b/utils/src/main/java/org/onap/policy/common/utils/properties/exception/PropertyException.java index 44edd428..3c03f38d 100644 --- a/utils/src/main/java/org/onap/policy/common/utils/properties/exception/PropertyException.java +++ b/utils/src/main/java/org/onap/policy/common/utils/properties/exception/PropertyException.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP Policy Engine - Common Modules * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018, 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. @@ -20,9 +20,12 @@ package org.onap.policy.common.utils.properties.exception; +import lombok.Getter; + /** * Exception associated with a Property. */ +@Getter public class PropertyException extends Exception { private static final long serialVersionUID = 1L; @@ -38,7 +41,7 @@ public class PropertyException extends Exception { /** * Constructor. - * + * * @param propName name of the property causing the exception, or {@code null} * @param fieldName name of the field causing the exception, or {@code null} */ @@ -51,7 +54,7 @@ public class PropertyException extends Exception { /** * Constructor. - * + * * @param propnm name of the property causing the exception, or {@code null} * @param fieldName name of the field causing the exception, or {@code null} * @param message error message @@ -65,7 +68,7 @@ public class PropertyException extends Exception { /** * Constructor. - * + * * @param propnm name of the property causing the exception, or {@code null} * @param fieldName name of the field causing the exception, or {@code null} * @param cause cause of the exception @@ -79,7 +82,7 @@ public class PropertyException extends Exception { /** * Constructor. - * + * * @param propnm name of the property causing the exception, or {@code null} * @param fieldName name of the field causing the exception, or {@code null} * @param message error message @@ -93,28 +96,8 @@ public class PropertyException extends Exception { } /** - * Get the property name. - * - * @return name of the property for which the exception was thrown, or {@code null} if - * no name was provided - */ - public String getPropertyName() { - return propertyName; - } - - /** - * Get the field name. - * - * @return name of the field for which the exception was thrown, or {@code null} if no - * field was provided - */ - public String getFieldName() { - return fieldName; - } - - /** * Make the message. - * + * * @param propnm name of the property causing the exception, or {@code null} * @param fieldName name of the field causing the exception, or {@code null} * @param message error message, never {@code null} @@ -126,13 +109,13 @@ public class PropertyException extends Exception { /** * Make the message. - * + * * @param propnm name of the property causing the exception, or {@code null} * @param fieldName name of the field causing the exception, or {@code null} * @return an error message composed of the two items */ private static String makeMessage(String propnm, String fieldName) { - StringBuilder bldr = new StringBuilder(50); + var bldr = new StringBuilder(50); if (propnm == null) { bldr.append("property exception"); |