diff options
author | vempo <vitaliy.emporopulo@amdocs.com> | 2018-10-25 19:27:22 +0300 |
---|---|---|
committer | Avi Gaffa <avi.gaffa@amdocs.com> | 2018-10-28 06:58:23 +0000 |
commit | 933cdbd4c20f18fe47f253bd721baf6ae996e906 (patch) | |
tree | d8298cf67446c13b688ceb1446a15516da698fc5 /common/onap-common-configuration-management/onap-configuration-management-api/src/main/java | |
parent | edc8d7bbb0faad568b367e60012db476525c288c (diff) |
Code formatting of configuration framework
Fixed code formatting, removed meaningless Javadoc comments,
added copyright headers, minor (and safe) static analysis fixes.
Change-Id: I3eda1f242905da5b80e024cf30a69ff59381fc43
Issue-ID: SDC-1867
Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'common/onap-common-configuration-management/onap-configuration-management-api/src/main/java')
6 files changed, 513 insertions, 1055 deletions
diff --git a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/Config.java b/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/Config.java index 406f45af92..73ddc5d273 100644 --- a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/Config.java +++ b/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/Config.java @@ -1,3 +1,19 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + package org.onap.config.api; import java.lang.annotation.ElementType; @@ -5,17 +21,9 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -/** - * The interface Config. - */ @Target({ElementType.TYPE, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) public @interface Config { - /** - * Key string. - * - * @return the string - */ String key(); } diff --git a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/Configuration.java b/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/Configuration.java index 58eedd7575..3232d49277 100644 --- a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/Configuration.java +++ b/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/Configuration.java @@ -1,831 +1,338 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + package org.onap.config.api; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; -/** - * The interface Configuration. - */ public interface Configuration { - /** - * The constant tenant. - */ - public static ThreadLocal<String> tenant = new ThreadLocal<>(); - - /** - * Sets tenant id. - * - * @param id the id - */ - public static void setTenantId(String id) { - if (id != null && id.trim().length() > 0) { - tenant.set(id); - } - } - - /** - * Gets as string. - * - * @param key the key - * @return the as string - */ - public default String getAsString(String key) { - return getAsString(null, key); - } - - /** - * Gets as string. - * - * @param namespace the namespace - * @param key the key - * @return the as string - */ - public default String getAsString(String namespace, String key) { - return getAsString(tenant.get(), namespace, key); - } - - /** - * Gets as string. - * - * @param tenantId the tenant id - * @param namespace the namespace - * @param key the key - * @return the as string - */ - public default String getAsString(String tenantId, String namespace, String key) { - return get(tenantId, namespace, key, String.class); - } - - /** - * Gets as byte value. - * - * @param key the key - * @return the as byte value - */ - public default Byte getAsByteValue(String key) { - return getAsByteValue(null, key); - } - - /** - * Gets as byte value. - * - * @param namespace the namespace - * @param key the key - * @return the as byte value - */ - public default Byte getAsByteValue(String namespace, String key) { - return getAsByteValue(tenant.get(), namespace, key); - } - - /** - * Gets as byte value. - * - * @param tenantId the tenant id - * @param namespace the namespace - * @param key the key - * @return the as byte value - */ - public default Byte getAsByteValue(String tenantId, String namespace, String key) { - return get(tenantId, namespace, key, Byte.class); - } - - /** - * Gets as short value. - * - * @param key the key - * @return the as short value - */ - public default Short getAsShortValue(String key) { - return getAsShortValue(null, key); - } - - /** - * Gets as short value. - * - * @param namespace the namespace - * @param key the key - * @return the as short value - */ - public default Short getAsShortValue(String namespace, String key) { - return getAsShortValue(tenant.get(), namespace, key); - } - - /** - * Gets as short value. - * - * @param tenantId the tenant id - * @param namespace the namespace - * @param key the key - * @return the as short value - */ - public default Short getAsShortValue(String tenantId, String namespace, String key) { - return get(tenantId, namespace, key, Short.class); - } - - /** - * Gets as integer value. - * - * @param key the key - * @return the as integer value - */ - public default Integer getAsIntegerValue(String key) { - return getAsIntegerValue(null, key); - } - - /** - * Gets as integer value. - * - * @param namespace the namespace - * @param key the key - * @return the as integer value - */ - public default Integer getAsIntegerValue(String namespace, String key) { - return getAsIntegerValue(tenant.get(), namespace, key); - } - - /** - * Gets as integer value. - * - * @param tenantId the tenant id - * @param namespace the namespace - * @param key the key - * @return the as integer value - */ - public default Integer getAsIntegerValue(String tenantId, String namespace, String key) { - return get(tenantId, namespace, key, Integer.class); - } - - /** - * Gets as long value. - * - * @param key the key - * @return the as long value - */ - public default Long getAsLongValue(String key) { - return getAsLongValue(null, key); - } - - /** - * Gets as long value. - * - * @param namespace the namespace - * @param key the key - * @return the as long value - */ - public default Long getAsLongValue(String namespace, String key) { - return getAsLongValue(tenant.get(), namespace, key); - } - - /** - * Gets as long value. - * - * @param tenantId the tenant id - * @param namespace the namespace - * @param key the key - * @return the as long value - */ - public default Long getAsLongValue(String tenantId, String namespace, String key) { - return get(tenantId, namespace, key, Long.class); - } - - /** - * Gets as float value. - * - * @param key the key - * @return the as float value - */ - public default Float getAsFloatValue(String key) { - return getAsFloatValue(null, key); - } - - /** - * Gets as float value. - * - * @param namespace the namespace - * @param key the key - * @return the as float value - */ - public default Float getAsFloatValue(String namespace, String key) { - return getAsFloatValue(tenant.get(), namespace, key); - } - - /** - * Gets as float value. - * - * @param tenantId the tenant id - * @param namespace the namespace - * @param key the key - * @return the as float value - */ - public default Float getAsFloatValue(String tenantId, String namespace, String key) { - return get(tenantId, namespace, key, Float.class); - } - - /** - * Gets as double value. - * - * @param key the key - * @return the as double value - */ - public default Double getAsDoubleValue(String key) { - return getAsDoubleValue(null, key); - } - - /** - * Gets as double value. - * - * @param namespace the namespace - * @param key the key - * @return the as double value - */ - public default Double getAsDoubleValue(String namespace, String key) { - return getAsDoubleValue(tenant.get(), namespace, key); - } - - /** - * Gets as double value. - * - * @param tenantId the tenant id - * @param namespace the namespace - * @param key the key - * @return the as double value - */ - public default Double getAsDoubleValue(String tenantId, String namespace, String key) { - return get(tenantId, namespace, key, Double.class); - } - - /** - * Gets as boolean value. - * - * @param key the key - * @return the as boolean value - */ - public default Boolean getAsBooleanValue(String key) { - return getAsBooleanValue(null, key); - } - - /** - * Gets as boolean value. - * - * @param namespace the namespace - * @param key the key - * @return the as boolean value - */ - public default Boolean getAsBooleanValue(String namespace, String key) { - return getAsBooleanValue(tenant.get(), namespace, key); - } - - /** - * Gets as boolean value. - * - * @param tenantId the tenant id - * @param namespace the namespace - * @param key the key - * @return the as boolean value - */ - public default Boolean getAsBooleanValue(String tenantId, String namespace, String key) { - return get(tenantId, namespace, key, Boolean.class); - } - - /** - * Gets as char value. - * - * @param key the key - * @return the as char value - */ - public default Character getAsCharValue(String key) { - return getAsCharValue(null, key); - } - - /** - * Gets as char value. - * - * @param namespace the namespace - * @param key the key - * @return the as char value - */ - public default Character getAsCharValue(String namespace, String key) { - return getAsCharValue(tenant.get(), namespace, key); - } - - /** - * Gets as char value. - * - * @param tenantId the tenant id - * @param namespace the namespace - * @param key the key - * @return the as char value - */ - public default Character getAsCharValue(String tenantId, String namespace, String key) { - return get(tenantId, namespace, key, Character.class); - } - - /** - * Populate configuration t. - * - * @param <T> the type parameter - * @param clazz the clazz - * @return the t - */ - public default <T> T populateConfiguration(Class<T> clazz) { - return populateConfiguration(null, clazz); - } - - /** - * Populate configuration t. - * - * @param <T> the type parameter - * @param namespace the namespace - * @param clazz the clazz - * @return the t - */ - public default <T> T populateConfiguration(String namespace, Class<T> clazz) { - return populateConfiguration(tenant.get(), namespace, clazz); - } - - /** - * Populate configuration t. - * - * @param <T> the type parameter - * @param tenantId the tenant id - * @param namespace the namespace - * @param clazz the clazz - * @return the t - */ - public default <T> T populateConfiguration(String tenantId, String namespace, Class<T> clazz) { - return get(tenantId, namespace, null, clazz, Hint.EXTERNAL_LOOKUP); - } - - /** - * Gets dynamic configuration. - * - * @param <T> the type parameter - * @param key the key - * @param clazz the clazz - * @param defaultValue the default value - * @return the dynamic configuration - */ - public default <T> DynamicConfiguration<T> getDynamicConfiguration(String key, Class<T> clazz, - T defaultValue) { - return getDynamicConfiguration(null, key, clazz, defaultValue); - } - - /** - * Gets dynamic configuration. - * - * @param <T> the type parameter - * @param namespace the namespace - * @param key the key - * @param clazz the clazz - * @param defaultValue the default value - * @return the dynamic configuration - */ - public default <T> DynamicConfiguration<T> getDynamicConfiguration(String namespace, String key, - Class<T> clazz, - T defaultValue) { - return getDynamicConfiguration(tenant.get(), namespace, key, clazz, defaultValue); - } - - /** - * Gets dynamic configuration. - * - * @param <T> the type parameter - * @param tenant the tenant - * @param namespace the namespace - * @param key the key - * @param clazz the clazz - * @param defaultValue the default value - * @return the dynamic configuration - */ - public default <T> DynamicConfiguration<T> getDynamicConfiguration(String tenant, - String namespace, String key, - Class<T> clazz, - T defaultValue) { - return DynamicConfiguration - .getDynamicConfiguration(tenant, namespace, key, clazz, defaultValue, this); - } - - /** - * Gets dynamic configuration values. - * - * @param <T> the type parameter - * @param key the key - * @param clazz the clazz - * @param defaultValue the default value - * @return the dynamic configuration values - */ - public default <T> DynamicConfiguration<List<T>> getDynamicConfigurationValues(String key, - Class<T> clazz, - T defaultValue) { - return getDynamicConfigurationValues(null, key, clazz, defaultValue); - } - - /** - * Gets dynamic configuration values. - * - * @param <T> the type parameter - * @param namespace the namespace - * @param key the key - * @param clazz the clazz - * @param defaultValue the default value - * @return the dynamic configuration values - */ - public default <T> DynamicConfiguration<List<T>> getDynamicConfigurationValues(String namespace, - String key, - Class<T> clazz, - T defaultValue) { - return getDynamicConfigurationValues(tenant.get(), namespace, key, clazz, defaultValue); - } - - /** - * Gets dynamic configuration values. - * - * @param <T> the type parameter - * @param tenant the tenant - * @param namespace the namespace - * @param key the key - * @param clazz the clazz - * @param defaultValue the default value - * @return the dynamic configuration values - */ - public default <T> DynamicConfiguration<List<T>> getDynamicConfigurationValues(String tenant, - String namespace, - String key, - Class<T> clazz, - T defaultValue) { - return DynamicConfiguration - .getDynConfiguration(tenant, namespace, key, clazz, defaultValue, this); - } - - /** - * Gets as string values. - * - * @param key the key - * @return the as string values - */ - public default List<String> getAsStringValues(String key) { - return getAsStringValues(null, key); - } - - /** - * Gets as string values. - * - * @param namespace the namespace - * @param key the key - * @return the as string values - */ - public default List<String> getAsStringValues(String namespace, String key) { - return getAsStringValues(tenant.get(), namespace, key); - } - - /** - * Gets as string values. - * - * @param tenantId the tenant id - * @param namespace the namespace - * @param key the key - * @return the as string values - */ - public default List<String> getAsStringValues(String tenantId, String namespace, String key) { - String[] tempArray = get(tenantId, namespace, key, String[].class); - return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray); - } - - /** - * Gets as byte values. - * - * @param key the key - * @return the as byte values - */ - public default List<Byte> getAsByteValues(String key) { - return getAsByteValues(null, key); - } - - /** - * Gets as byte values. - * - * @param namespace the namespace - * @param key the key - * @return the as byte values - */ - public default List<Byte> getAsByteValues(String namespace, String key) { - return getAsByteValues(tenant.get(), namespace, key); - } - - /** - * Gets as byte values. - * - * @param tenantId the tenant id - * @param namespace the namespace - * @param key the key - * @return the as byte values - */ - public default List<Byte> getAsByteValues(String tenantId, String namespace, String key) { - Byte[] tempArray = get(tenantId, namespace, key, Byte[].class); - return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray); - } - - /** - * Gets as short values. - * - * @param key the key - * @return the as short values - */ - public default List<Short> getAsShortValues(String key) { - return getAsShortValues(null, key); - } - - /** - * Gets as short values. - * - * @param namespace the namespace - * @param key the key - * @return the as short values - */ - public default List<Short> getAsShortValues(String namespace, String key) { - return getAsShortValues(tenant.get(), namespace, key); - } - - /** - * Gets as short values. - * - * @param tenantId the tenant id - * @param namespace the namespace - * @param key the key - * @return the as short values - */ - public default List<Short> getAsShortValues(String tenantId, String namespace, String key) { - Short[] tempArray = get(tenantId, namespace, key, Short[].class); - return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray); - } - - /** - * Gets as integer values. - * - * @param key the key - * @return the as integer values - */ - public default List<Integer> getAsIntegerValues(String key) { - return getAsIntegerValues(null, key); - } - - /** - * Gets as integer values. - * - * @param namespace the namespace - * @param key the key - * @return the as integer values - */ - public default List<Integer> getAsIntegerValues(String namespace, String key) { - return getAsIntegerValues(tenant.get(), namespace, key); - } - - /** - * Gets as integer values. - * - * @param tenantId the tenant id - * @param namespace the namespace - * @param key the key - * @return the as integer values - */ - public default List<Integer> getAsIntegerValues(String tenantId, String namespace, String key) { - Integer[] tempArray = get(tenantId, namespace, key, Integer[].class); - return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray); - } - - /** - * Gets as double values. - * - * @param key the key - * @return the as double values - */ - public default List<Double> getAsDoubleValues(String key) { - return getAsDoubleValues(null, key); - } - - /** - * Gets as double values. - * - * @param namespace the namespace - * @param key the key - * @return the as double values - */ - public default List<Double> getAsDoubleValues(String namespace, String key) { - return getAsDoubleValues(tenant.get(), namespace, key); - } - - /** - * Gets as double values. - * - * @param tenantId the tenant id - * @param namespace the namespace - * @param key the key - * @return the as double values - */ - public default List<Double> getAsDoubleValues(String tenantId, String namespace, String key) { - Double[] tempArray = get(tenantId, namespace, key, Double[].class); - return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray); - } - - /** - * Gets as float values. - * - * @param key the key - * @return the as float values - */ - public default List<Float> getAsFloatValues(String key) { - return getAsFloatValues(null, key); - } - - /** - * Gets as float values. - * - * @param namespace the namespace - * @param key the key - * @return the as float values - */ - public default List<Float> getAsFloatValues(String namespace, String key) { - return getAsFloatValues(tenant.get(), namespace, key); - } - - /** - * Gets as float values. - * - * @param tenantId the tenant id - * @param namespace the namespace - * @param key the key - * @return the as float values - */ - public default List<Float> getAsFloatValues(String tenantId, String namespace, String key) { - Float[] tempArray = get(tenantId, namespace, key, Float[].class); - return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray); - } - - /** - * Gets as boolean values. - * - * @param key the key - * @return the as boolean values - */ - public default List<Boolean> getAsBooleanValues(String key) { - return getAsBooleanValues(null, key); - } - - /** - * Gets as boolean values. - * - * @param namespace the namespace - * @param key the key - * @return the as boolean values - */ - public default List<Boolean> getAsBooleanValues(String namespace, String key) { - return getAsBooleanValues(tenant.get(), namespace, key); - } - - /** - * Gets as boolean values. - * - * @param tenantId the tenant id - * @param namespace the namespace - * @param key the key - * @return the as boolean values - */ - public default List<Boolean> getAsBooleanValues(String tenantId, String namespace, String key) { - Boolean[] tempArray = get(tenantId, namespace, key, Boolean[].class); - return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray); - } - - /** - * Gets as character values. - * - * @param key the key - * @return the as character values - */ - public default List<Character> getAsCharacterValues(String key) { - return getAsCharacterValues(null, key); - } - - /** - * Gets as character values. - * - * @param namespace the namespace - * @param key the key - * @return the as character values - */ - public default List<Character> getAsCharacterValues(String namespace, String key) { - return getAsCharacterValues(tenant.get(), namespace, key); - } - - /** - * Gets as character values. - * - * @param tenantId the tenant id - * @param namespace the namespace - * @param key the key - * @return the as character values - */ - public default List<Character> getAsCharacterValues(String tenantId, String namespace, - String key) { - Character[] tempArray = get(tenantId, namespace, key, Character[].class); - return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray); - } - - /** - * Get t. - * - * @param <T> the type parameter - * @param tenant the tenant - * @param namespace the namespace - * @param key the key - * @param clazz the clazz - * @param hints the hints - * @return the t - */ - public <T> T get(String tenant, String namespace, String key, Class<T> clazz, Hint... hints); - - /** - * Add configuration change listener. - * - * @param key the key - * @param myself the myself - */ - public default void addConfigurationChangeListener(String key, - ConfigurationChangeListener myself) { - addConfigurationChangeListener(null, key, myself); - } - - /** - * Add configuration change listener. - * - * @param namespace the namespace - * @param key the key - * @param myself the myself - */ - public default void addConfigurationChangeListener(String namespace, String key, - ConfigurationChangeListener myself) { - addConfigurationChangeListener(tenant.get(), namespace, key, myself); - } - - /** - * Add configuration change listener. - * - * @param tenant the tenant - * @param namespace the namespace - * @param key the key - * @param myself the myself - */ - public void addConfigurationChangeListener(String tenant, String namespace, String key, - ConfigurationChangeListener myself); - - /** - * Remove configuration change listener. - * - * @param key the key - * @param myself the myself - */ - public default void removeConfigurationChangeListener(String key, - ConfigurationChangeListener myself) { - removeConfigurationChangeListener(null, key, myself); - } - - /** - * Remove configuration change listener. - * - * @param namespace the namespace - * @param key the key - * @param myself the myself - */ - public default void removeConfigurationChangeListener(String namespace, String key, - ConfigurationChangeListener myself) { - removeConfigurationChangeListener(tenant.get(), namespace, key, myself); - } - - /** - * Remove configuration change listener. - * - * @param tenant the tenant - * @param namespace the namespace - * @param key the key - * @param myself the myself - */ - public void removeConfigurationChangeListener(String tenant, String namespace, String key, - ConfigurationChangeListener myself); - - public default <T> Map<String, T> populateMap(String key, Class<T> clazz){ - return populateMap(null, key, clazz); - } - public default <T> Map<String, T> populateMap(String namespace, String key, Class<T> clazz){ - return populateMap(tenant.get(), namespace, key, clazz); - } - public <T> Map<String, T> populateMap(String tenantId, String namespace, String key, Class<T> clazz); - - public default Map generateMap(String key){ - return generateMap(null, key); - } - public default Map generateMap(String namespace, String key){ - return generateMap(tenant.get(), namespace, key); - } - public Map generateMap(String tenantId, String namespace, String key); + ThreadLocal<String> TENANT = new ThreadLocal<>(); + + /** + * Sets tenant for current thread. + * + * @param id tenant id; may be <code>null</code> in which case a default will be used. + */ + static void setTenantId(String id) { + + if (id != null && id.trim().length() > 0) { + TENANT.set(id); + } else { + TENANT.remove(); + } + } + + default String getAsString(String key) { + return getAsString(null, key); + } + + default String getAsString(String namespace, String key) { + return getAsString(TENANT.get(), namespace, key); + } + + default String getAsString(String tenantId, String namespace, String key) { + return get(tenantId, namespace, key, String.class); + } + + <T> T get(String tenant, String namespace, String key, Class<T> clazz, Hint... hints); + + default Byte getAsByteValue(String key) { + return getAsByteValue(null, key); + } + + default Byte getAsByteValue(String namespace, String key) { + return getAsByteValue(TENANT.get(), namespace, key); + } + + default Byte getAsByteValue(String tenantId, String namespace, String key) { + return get(tenantId, namespace, key, Byte.class); + } + + default Short getAsShortValue(String key) { + return getAsShortValue(null, key); + } + + default Short getAsShortValue(String namespace, String key) { + return getAsShortValue(TENANT.get(), namespace, key); + } + + default Short getAsShortValue(String tenantId, String namespace, String key) { + return get(tenantId, namespace, key, Short.class); + } + + default Integer getAsIntegerValue(String key) { + return getAsIntegerValue(null, key); + } + + default Integer getAsIntegerValue(String namespace, String key) { + return getAsIntegerValue(TENANT.get(), namespace, key); + } + + default Integer getAsIntegerValue(String tenantId, String namespace, String key) { + return get(tenantId, namespace, key, Integer.class); + } + + default Long getAsLongValue(String key) { + return getAsLongValue(null, key); + } + + default Long getAsLongValue(String namespace, String key) { + return getAsLongValue(TENANT.get(), namespace, key); + } + + default Long getAsLongValue(String tenantId, String namespace, String key) { + return get(tenantId, namespace, key, Long.class); + } + + default Float getAsFloatValue(String key) { + return getAsFloatValue(null, key); + } + + default Float getAsFloatValue(String namespace, String key) { + return getAsFloatValue(TENANT.get(), namespace, key); + } + + default Float getAsFloatValue(String tenantId, String namespace, String key) { + return get(tenantId, namespace, key, Float.class); + } + + default Double getAsDoubleValue(String key) { + return getAsDoubleValue(null, key); + } + + default Double getAsDoubleValue(String namespace, String key) { + return getAsDoubleValue(TENANT.get(), namespace, key); + } + + default Double getAsDoubleValue(String tenantId, String namespace, String key) { + return get(tenantId, namespace, key, Double.class); + } + + default Boolean getAsBooleanValue(String key) { + return getAsBooleanValue(null, key); + } + + default Boolean getAsBooleanValue(String namespace, String key) { + return getAsBooleanValue(TENANT.get(), namespace, key); + } + + default Boolean getAsBooleanValue(String tenantId, String namespace, String key) { + return get(tenantId, namespace, key, Boolean.class); + } + + default Character getAsCharValue(String key) { + return getAsCharValue(null, key); + } + + default Character getAsCharValue(String namespace, String key) { + return getAsCharValue(TENANT.get(), namespace, key); + } + + default Character getAsCharValue(String tenantId, String namespace, String key) { + return get(tenantId, namespace, key, Character.class); + } + + default <T> T populateConfiguration(Class<T> clazz) { + return populateConfiguration(null, clazz); + } + + default <T> T populateConfiguration(String namespace, Class<T> clazz) { + return populateConfiguration(TENANT.get(), namespace, clazz); + } + + default <T> T populateConfiguration(String tenantId, String namespace, Class<T> clazz) { + return get(tenantId, namespace, null, clazz, Hint.EXTERNAL_LOOKUP); + } + + default <T> DynamicConfiguration<T> getDynamicConfiguration(String key, Class<T> clazz, T defaultValue) { + return getDynamicConfiguration(null, key, clazz, defaultValue); + } + + default <T> DynamicConfiguration<T> getDynamicConfiguration(String namespace, String key, Class<T> clazz, + T defaultValue) { + return getDynamicConfiguration(TENANT.get(), namespace, key, clazz, defaultValue); + } + + default <T> DynamicConfiguration<T> getDynamicConfiguration(String tenant, String namespace, String key, + Class<T> clazz, T defaultValue) { + return DynamicConfiguration.getDynamicConfiguration(tenant, namespace, key, clazz, defaultValue, this); + } + + default <T> DynamicConfiguration<List<T>> getDynamicConfigurationValues(String key, Class<T> clazz, + T defaultValue) { + return getDynamicConfigurationValues(null, key, clazz, defaultValue); + } + + default <T> DynamicConfiguration<List<T>> getDynamicConfigurationValues(String namespace, String key, + Class<T> clazz, T defaultValue) { + return getDynamicConfigurationValues(TENANT.get(), namespace, key, clazz, defaultValue); + } + + default <T> DynamicConfiguration<List<T>> getDynamicConfigurationValues(String tenant, String namespace, String key, + Class<T> clazz, T defaultValue) { + return DynamicConfiguration.getDynConfiguration(tenant, namespace, key, clazz, defaultValue, this); + } + + default List<String> getAsStringValues(String key) { + return getAsStringValues(null, key); + } + + default List<String> getAsStringValues(String namespace, String key) { + return getAsStringValues(TENANT.get(), namespace, key); + } + + default List<String> getAsStringValues(String tenantId, String namespace, String key) { + String[] tempArray = get(tenantId, namespace, key, String[].class); + return tempArray == null ? Collections.emptyList() : Arrays.asList(tempArray); + } + + default List<Byte> getAsByteValues(String key) { + return getAsByteValues(null, key); + } + + default List<Byte> getAsByteValues(String namespace, String key) { + return getAsByteValues(TENANT.get(), namespace, key); + } + + default List<Byte> getAsByteValues(String tenantId, String namespace, String key) { + Byte[] tempArray = get(tenantId, namespace, key, Byte[].class); + return tempArray == null ? Collections.emptyList() : Arrays.asList(tempArray); + } + + default List<Short> getAsShortValues(String key) { + return getAsShortValues(null, key); + } + + default List<Short> getAsShortValues(String namespace, String key) { + return getAsShortValues(TENANT.get(), namespace, key); + } + + default List<Short> getAsShortValues(String tenantId, String namespace, String key) { + Short[] tempArray = get(tenantId, namespace, key, Short[].class); + return tempArray == null ? Collections.emptyList() : Arrays.asList(tempArray); + } + + default List<Integer> getAsIntegerValues(String key) { + return getAsIntegerValues(null, key); + } + + default List<Integer> getAsIntegerValues(String namespace, String key) { + return getAsIntegerValues(TENANT.get(), namespace, key); + } + + default List<Integer> getAsIntegerValues(String tenantId, String namespace, String key) { + Integer[] tempArray = get(tenantId, namespace, key, Integer[].class); + return tempArray == null ? Collections.emptyList() : Arrays.asList(tempArray); + } + + default List<Double> getAsDoubleValues(String key) { + return getAsDoubleValues(null, key); + } + + default List<Double> getAsDoubleValues(String namespace, String key) { + return getAsDoubleValues(TENANT.get(), namespace, key); + } + + default List<Double> getAsDoubleValues(String tenantId, String namespace, String key) { + Double[] tempArray = get(tenantId, namespace, key, Double[].class); + return tempArray == null ? Collections.emptyList() : Arrays.asList(tempArray); + } + + default List<Float> getAsFloatValues(String key) { + return getAsFloatValues(null, key); + } + + default List<Float> getAsFloatValues(String namespace, String key) { + return getAsFloatValues(TENANT.get(), namespace, key); + } + + default List<Float> getAsFloatValues(String tenantId, String namespace, String key) { + Float[] tempArray = get(tenantId, namespace, key, Float[].class); + return tempArray == null ? Collections.emptyList() : Arrays.asList(tempArray); + } + + default List<Boolean> getAsBooleanValues(String key) { + return getAsBooleanValues(null, key); + } + + default List<Boolean> getAsBooleanValues(String namespace, String key) { + return getAsBooleanValues(TENANT.get(), namespace, key); + } + + default List<Boolean> getAsBooleanValues(String tenantId, String namespace, String key) { + Boolean[] tempArray = get(tenantId, namespace, key, Boolean[].class); + return tempArray == null ? Collections.emptyList() : Arrays.asList(tempArray); + } + + default List<Character> getAsCharacterValues(String key) { + return getAsCharacterValues(null, key); + } + + default List<Character> getAsCharacterValues(String namespace, String key) { + return getAsCharacterValues(TENANT.get(), namespace, key); + } + + default List<Character> getAsCharacterValues(String tenantId, String namespace, String key) { + Character[] tempArray = get(tenantId, namespace, key, Character[].class); + return tempArray == null ? Collections.emptyList() : Arrays.asList(tempArray); + } + + default void addConfigurationChangeListener(String key, ConfigurationChangeListener myself) { + addConfigurationChangeListener(null, key, myself); + } + + default void addConfigurationChangeListener(String namespace, String key, ConfigurationChangeListener myself) { + addConfigurationChangeListener(TENANT.get(), namespace, key, myself); + } + + void addConfigurationChangeListener(String tenant, String namespace, String key, + ConfigurationChangeListener myself); + + default void removeConfigurationChangeListener(String key, ConfigurationChangeListener myself) { + removeConfigurationChangeListener(null, key, myself); + } + + default void removeConfigurationChangeListener(String namespace, String key, ConfigurationChangeListener myself) { + removeConfigurationChangeListener(TENANT.get(), namespace, key, myself); + } + + void removeConfigurationChangeListener(String tenant, String namespace, String key, + ConfigurationChangeListener myself); + + default <T> Map<String, T> populateMap(String key, Class<T> clazz) { + return populateMap(null, key, clazz); + } + + default <T> Map<String, T> populateMap(String namespace, String key, Class<T> clazz) { + return populateMap(TENANT.get(), namespace, key, clazz); + } + + <T> Map<String, T> populateMap(String tenantId, String namespace, String key, Class<T> clazz); + + default Map generateMap(String key) { + return generateMap(null, key); + } + + default Map generateMap(String namespace, String key) { + return generateMap(TENANT.get(), namespace, key); + } + + Map generateMap(String tenantId, String namespace, String key); } diff --git a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/ConfigurationChangeListener.java b/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/ConfigurationChangeListener.java index 451a75f3ae..dddd751383 100644 --- a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/ConfigurationChangeListener.java +++ b/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/ConfigurationChangeListener.java @@ -1,14 +1,29 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + package org.onap.config.api; public interface ConfigurationChangeListener { - public default void notify(String tenantId, String component, String key, Object oldValue, - Object newValue) { - } + default void notify(String tenantId, String component, String key, Object oldValue, Object newValue) { + } - public default void notify(String component, String key, Object oldValue, Object newValue) { - } + default void notify(String component, String key, Object oldValue, Object newValue) { + } - public default void notify(String key, Object oldValue, Object newValue) { - } + default void notify(String key, Object oldValue, Object newValue) { + } } diff --git a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/ConfigurationManager.java b/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/ConfigurationManager.java index 0e8f1409a0..d91fdb15f4 100644 --- a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/ConfigurationManager.java +++ b/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/ConfigurationManager.java @@ -1,98 +1,52 @@ -package org.onap.config.api; +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ +package org.onap.config.api; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Proxy; import java.util.Collection; +import java.util.Iterator; import java.util.Map; import java.util.ServiceLoader; -/** - * The interface Configuration manager. - */ public interface ConfigurationManager extends Configuration { - /** - * The constant config. - */ - public static final Configuration config = lookup(); + Configuration CONFIG = lookup(); + + static Configuration lookup() { + + if (CONFIG == null) { + ServiceLoader<ConfigurationManager> loader = ServiceLoader.load(ConfigurationManager.class); + Iterator<ConfigurationManager> configManagers = loader.iterator(); + return configManagers.hasNext() ? configManagers.next() : null; + } - /** - * Lookup configuration. - * - * @return the configuration - */ - public static Configuration lookup() { - if (config == null) { - ServiceLoader<ConfigurationManager> loader = ServiceLoader.load(ConfigurationManager.class); - for (ConfigurationManager configuration : loader) { - return (Configuration) Proxy.newProxyInstance(ConfigurationManager.class.getClassLoader(), - new Class[]{Configuration.class}, (object, method, args) -> { - try { - return method.invoke(configuration, args); - } catch (InvocationTargetException ite) { - throw ite.getTargetException(); - } - }); - } + return CONFIG; } - return config; - } - /** - * Gets configuration value. - * - * @param queryData the query data - * @return the configuration value - */ - public String getConfigurationValue(Map<String, Object> queryData); + String getConfigurationValue(Map<String, Object> queryData); - /** - * Update configuration value. - * - * @param updateData the update data - */ - public void updateConfigurationValue(Map<String, Object> updateData); + void updateConfigurationValue(Map<String, Object> updateData); - /** - * List configuration map. - * - * @param query the query - * @return the map - */ - public Map<String, String> listConfiguration(Map<String, Object> query); + Map<String, String> listConfiguration(Map<String, Object> query); - /** - * Update configuration values boolean. - * - * @param tenant the tenant - * @param namespace the namespace - * @param configKeyValueStore the config key value store - * @return the boolean - */ - public boolean updateConfigurationValues(String tenant, String namespace, - Map configKeyValueStore); + boolean updateConfigurationValues(String tenant, String namespace, Map configKeyValueStore); - /** - * Gets tenants. - * - * @return the tenants - */ - public Collection<String> getTenants(); + Collection<String> getTenants(); - /** - * Gets namespaces. - * - * @return the namespaces - */ - public Collection<String> getNamespaces(); + Collection<String> getNamespaces(); - /** - * Gets keys. - * - * @param tenant the tenant - * @param namespace the namespace - * @return the keys - */ - public Collection<String> getKeys(String tenant, String namespace); + Collection<String> getKeys(String tenant, String namespace); } diff --git a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/DynamicConfiguration.java b/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/DynamicConfiguration.java index 969749b260..c2973a493f 100644 --- a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/DynamicConfiguration.java +++ b/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/DynamicConfiguration.java @@ -1,146 +1,104 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + package org.onap.config.api; import java.util.Arrays; +import java.util.Collections; import java.util.List; -/** - * The type Dynamic configuration. - * - * @param <T> the type parameter - */ + public class DynamicConfiguration<T> { - /** - * The Tenant. - */ - String tenant; - /** - * The Namespace. - */ - String namespace; - /** - * The Key. - */ - String key; - /** - * The Configuration. - */ - Configuration configuration; - /** - * The Clazz. - */ - Class clazz; - /** - * The Default value. - */ - T defaultValue; + private String tenant; + + private String namespace; + + private String key; + + private Configuration configuration; - /** - * Gets dynamic configuration. - * - * @param <T> the type parameter - * @param tenant the tenant - * @param namespace the namespace - * @param key the key - * @param clazz the clazz - * @param defaultValue the default value - * @param configuration the configuration - * @return the dynamic configuration - */ - public static <T> DynamicConfiguration<T> getDynamicConfiguration(String tenant, String namespace, - String key, Class<T> clazz, - T defaultValue, - Configuration configuration) { - DynamicConfiguration<T> dynamicConfiguration = new DynamicConfiguration<>(); - dynamicConfiguration.tenant = tenant; - dynamicConfiguration.namespace = namespace; - dynamicConfiguration.key = key; - dynamicConfiguration.clazz = clazz; - dynamicConfiguration.defaultValue = defaultValue; - dynamicConfiguration.configuration = configuration; - return dynamicConfiguration; - } + private Class clazz; + + private T defaultValue; + + public static <K> DynamicConfiguration<List<K>> getDynConfiguration(String tenant, String namespace, String key, + Class<K> clazz, K defaultValue, Configuration configuration) { + if (clazz.isPrimitive()) { + throw new RuntimeException("Only Wrapper classes like Integer, Long, Double, " + + "Boolean etc including String are supported."); + } + return getDynamicConfiguration(tenant, namespace, key, getArrayClass(clazz), + Collections.singletonList(defaultValue), configuration); + } - /** - * Gets dyn configuration. - * - * @param <K> the type parameter - * @param tenant the tenant - * @param namespace the namespace - * @param key the key - * @param clazz the clazz - * @param defaultValue the default value - * @param configuration the configuration - * @return the dyn configuration - */ - public static <K> DynamicConfiguration<List<K>> getDynConfiguration(String tenant, - String namespace, String key, - Class<K> clazz, - K defaultValue, - Configuration configuration) { - if (clazz.isPrimitive()) { - throw new RuntimeException( - "Only Wrapper classes like Integer, Long, Double, " - + "Boolean etc including String are supported."); + public static <T> DynamicConfiguration<T> getDynamicConfiguration(String tenant, String namespace, String key, + Class<T> clazz, T defaultValue, Configuration configuration) { + DynamicConfiguration<T> dynamicConfiguration = new DynamicConfiguration<>(); + dynamicConfiguration.tenant = tenant; + dynamicConfiguration.namespace = namespace; + dynamicConfiguration.key = key; + dynamicConfiguration.clazz = clazz; + dynamicConfiguration.defaultValue = defaultValue; + dynamicConfiguration.configuration = configuration; + return dynamicConfiguration; } - return getDynamicConfiguration(tenant, namespace, key, getArrayClass(clazz), - Arrays.asList(defaultValue), configuration); - } - /** - * Gets array class. - * - * @param clazz the clazz - * @return the array class - */ - public static Class getArrayClass(Class clazz) { - Class arrayClass = null; - switch (clazz.getName()) { - case "java.lang.Byte": - arrayClass = Byte[].class; - break; - case "java.lang.Short": - arrayClass = Short[].class; - break; - case "java.lang.Integer": - arrayClass = Integer[].class; - break; - case "java.lang.Long": - arrayClass = Long[].class; - break; - case "java.lang.Float": - arrayClass = Float[].class; - break; - case "java.lang.Double": - arrayClass = Double[].class; - break; - case "java.lang.Boolean": - arrayClass = Boolean[].class; - break; - case "java.lang.Character": - arrayClass = Character[].class; - break; - case "java.lang.String": - arrayClass = String[].class; - break; - default: + public static Class getArrayClass(Class clazz) { + Class arrayClass = null; + switch (clazz.getName()) { + case "java.lang.Byte": + arrayClass = Byte[].class; + break; + case "java.lang.Short": + arrayClass = Short[].class; + break; + case "java.lang.Integer": + arrayClass = Integer[].class; + break; + case "java.lang.Long": + arrayClass = Long[].class; + break; + case "java.lang.Float": + arrayClass = Float[].class; + break; + case "java.lang.Double": + arrayClass = Double[].class; + break; + case "java.lang.Boolean": + arrayClass = Boolean[].class; + break; + case "java.lang.Character": + arrayClass = Character[].class; + break; + case "java.lang.String": + arrayClass = String[].class; + break; + default: + } + return arrayClass; } - return arrayClass; - } - /** - * Get t. - * - * @return the t - */ - public T get() { - Object toReturn = configuration - .get(tenant, namespace, key, clazz, Hint.LATEST_LOOKUP, Hint.EXTERNAL_LOOKUP, - Hint.NODE_SPECIFIC); - if (toReturn != null && toReturn.getClass().isArray()) { - toReturn = Arrays.asList((Object[]) toReturn); + public T get() { + Object toReturn = configuration.get(tenant, namespace, key, clazz, Hint.LATEST_LOOKUP, Hint.EXTERNAL_LOOKUP, + Hint.NODE_SPECIFIC); + if (toReturn != null && toReturn.getClass().isArray()) { + toReturn = Arrays.asList((Object[]) toReturn); + } + return toReturn == null ? defaultValue : (T) toReturn; } - return toReturn == null ? defaultValue : (T) toReturn; - } } diff --git a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/Hint.java b/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/Hint.java index 17b58f6b0e..373b643ef2 100644 --- a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/Hint.java +++ b/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/Hint.java @@ -1,18 +1,34 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + package org.onap.config.api; public enum Hint { - DEFAULT(0b0), LATEST_LOOKUP(0b1), EXTERNAL_LOOKUP(0b10), NODE_SPECIFIC(0b100); + DEFAULT(0b0), LATEST_LOOKUP(0b1), EXTERNAL_LOOKUP(0b10), NODE_SPECIFIC(0b100); - private final int lookupHint; + private final int lookupHint; - private Hint(int hnt) { - lookupHint = hnt; - } + Hint(int hint) { + lookupHint = hint; + } - public int value() { - return lookupHint; - } + public int value() { + return lookupHint; + } } |