Moved collections, consul, etcd and hazelcast modules into extensions. Updated docs to match code.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/e0d15cb2 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/e0d15cb2 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/e0d15cb2 Branch: refs/heads/master Commit: e0d15cb28060388896351ea77e49ed56a988459c Parents: e6e9297 Author: Anatole Tresch <[email protected]> Authored: Thu Nov 8 00:26:28 2018 +0100 Committer: Anatole Tresch <[email protected]> Committed: Thu Nov 8 00:26:28 2018 +0100 ---------------------------------------------------------------------- collections/bnd.bnd | 27 - collections/pom.xml | 62 --- .../tamaya/collections/ArrayListConverter.java | 50 -- .../tamaya/collections/CollectionConverter.java | 317 ----------- .../collections/ConcurrentHashMapConverter.java | 53 -- .../tamaya/collections/HashMapConverter.java | 50 -- .../tamaya/collections/HashSetConverter.java | 52 -- .../tamaya/collections/ItemTokenizer.java | 166 ------ .../tamaya/collections/LinkedListConverter.java | 52 -- .../tamaya/collections/ListConverter.java | 60 --- .../apache/tamaya/collections/MapConverter.java | 63 --- .../apache/tamaya/collections/SetConverter.java | 59 --- .../tamaya/collections/SortedMapConverter.java | 36 -- .../tamaya/collections/SortedSetConverter.java | 37 -- .../tamaya/collections/TreeMapConverter.java | 52 -- .../tamaya/collections/TreeSetConverter.java | 52 -- .../org.apache.tamaya.spi.PropertyConverter | 31 -- .../collections/CollectionAdvancedTests.java | 116 ----- .../collections/CollectionsBaseTests.java | 226 -------- .../CollectionsTypedReadOnlyTests.java | 174 ------- .../collections/CollectionsTypedTests.java | 207 -------- .../collections/MyUpperCaseConverter.java | 33 -- .../META-INF/javaconfiguration.properties | 69 --- consul/bnd.bnd | 32 -- consul/pom.xml | 83 --- .../tamaya/consul/ConsulBackendConfig.java | 76 --- .../tamaya/consul/ConsulPropertySource.java | 247 --------- .../org.apache.tamaya.spi.PropertySource | 19 - .../tamaya/consul/ConsulPropertySourceTest.java | 76 --- .../apache/tamaya/consul/ConsulWriteTest.java | 86 --- etcd/bnd.bnd | 32 -- etcd/pom.xml | 80 --- .../org/apache/tamaya/etcd/EtcdAccessor.java | 519 ------------------- .../apache/tamaya/etcd/EtcdBackendConfig.java | 83 --- .../apache/tamaya/etcd/EtcdPropertySource.java | 276 ---------- .../org.apache.tamaya.spi.PropertySource | 19 - .../apache/tamaya/etcd/EtcdAccessorTest.java | 116 ----- .../tamaya/etcd/EtcdPropertySourceTest.java | 75 --- hazelcast/bnd.bnd | 29 -- hazelcast/pom.xml | 77 --- .../hazelcast/HazelcastPropertySource.java | 232 --------- .../java/org/apache/tamaya/hazelcast/Test.java | 41 -- pom.xml | 5 +- .../ConfiguredResourcesModelProviderSpi.java | 2 +- 44 files changed, 2 insertions(+), 4247 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/bnd.bnd ---------------------------------------------------------------------- diff --git a/collections/bnd.bnd b/collections/bnd.bnd deleted file mode 100644 index 61b2571..0000000 --- a/collections/bnd.bnd +++ /dev/null @@ -1,27 +0,0 @@ --buildpath: \ - osgi.annotation; version=6.0.0,\ - osgi.core; version=6.0,\ - osgi.cmpn; version=6.0 - --testpath: \ - ${junit} - -javac.source: 1.8 -javac.target: 1.8 - -Automatic-Module-Name: org.apache.tamaya.collections -Bundle-Version: ${version}.${tstamp} -Bundle-Name: Apache Tamaya - Collections Support -Bundle-SymbolicName: org.apache.tamaya.collections -Bundle-Description: Apacha Tamaya Config - Collections Support -Bundle-Category: Implementation -Bundle-Copyright: (C) Apache Foundation -Bundle-License: Apache Licence version 2 -Bundle-Vendor: Apache Software Foundation -Bundle-ContactAddress: [email protected] -Bundle-DocURL: http://tamaya.apache.org -Export-Package: \ - org.apache.tamaya.collections -Import-Package: \ - org.apache.tamaya,\ - org.apache.tamaya.spi http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/pom.xml ---------------------------------------------------------------------- diff --git a/collections/pom.xml b/collections/pom.xml deleted file mode 100644 index ecc922f..0000000 --- a/collections/pom.xml +++ /dev/null @@ -1,62 +0,0 @@ -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you 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 current 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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-sandbox</artifactId> - <version>0.4-incubating-SNAPSHOT</version> - </parent> - - <artifactId>tamaya-collections</artifactId> - <name>Apache Tamaya Modules - Collections Support</name> - <packaging>jar</packaging> - - <dependencies> - <dependency> - <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-core</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-spisupport</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-api</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>java-hamcrest</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - - -</project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/main/java/org/apache/tamaya/collections/ArrayListConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/ArrayListConverter.java b/collections/src/main/java/org/apache/tamaya/collections/ArrayListConverter.java deleted file mode 100644 index 2715cfc..0000000 --- a/collections/src/main/java/org/apache/tamaya/collections/ArrayListConverter.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.collections; - -import org.apache.tamaya.spi.ConversionContext; -import org.apache.tamaya.spi.PropertyConverter; - -import java.util.ArrayList; -import java.util.logging.Logger; - -/** - * PropertyConverter for gnerating ArrayList representation of a values. - */ -public class ArrayListConverter implements PropertyConverter<ArrayList> { - - private static final Logger LOG = Logger.getLogger(ArrayListConverter.class.getName()); - - /** The shared instance, used by other collection converters in this package.*/ - private static final ArrayListConverter INSTANCE = new ArrayListConverter(); - - /** - * Provide a shared instance, used by other collection converters in this package. - * @return the shared instance, never null. - */ - static ArrayListConverter getInstance(){ - return INSTANCE; - } - - @Override - public ArrayList convert(String value, ConversionContext context) { - return CollectionConverter.convertList(context, ArrayList::new); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/main/java/org/apache/tamaya/collections/CollectionConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/CollectionConverter.java b/collections/src/main/java/org/apache/tamaya/collections/CollectionConverter.java deleted file mode 100644 index 2cadd6e..0000000 --- a/collections/src/main/java/org/apache/tamaya/collections/CollectionConverter.java +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.collections; - -import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.spi.PropertyConverter; -import org.apache.tamaya.spi.ConversionContext; -import org.apache.tamaya.spi.PropertyValue; - -import java.lang.reflect.Type; -import java.util.*; -import java.util.function.Supplier; -import java.util.logging.Logger; - -/** - * PropertyConverter for gnerating a LIST representation of values. - */ -public final class CollectionConverter implements PropertyConverter<Collection> { - - private static final Logger LOG = Logger.getLogger(CollectionConverter.class.getName()); - public static final String VALUE_MAPPING = "collection-mapping"; - - private enum MappingType{ - /** The list values are identiified by parsing the node value(s) into items. - * Hereby only the items of the most significant config entry are considered. */ - value, - /** The list values are identiified by parsing the node value(s) into items, hereby - * the items of all values are combined. */ - value_all, - /** The list values are identiified by using the node's child value(s) as items. - * Hereby only the items of the most significant config entry are considered.*/ - node, - /** The list values are identiified by using the node's child value(s) as items. Hereby - * the items of all values are combined. */ - node_all, - /** This will guess the matching evaluation policy (value,bode) for each {@code PropertyValue} and - * combine the items of all values. */ - combine, - /** This will guess the matching evaluation policy (value,bode) on the most significant {@code PropertyValue} - * only. */ - override, - } - - private MappingType mappingType = MappingType.value_all; - - public static <T extends Collection> T convertList(ConversionContext context, - Supplier<T> collectionSupplier) { - MappingType mappingType = MappingType.valueOf((String)context.getMeta() - .getOrDefault(VALUE_MAPPING, MappingType.combine.toString())); - TypeLiteral<?> targetType = context.getTargetType(); - Type[] types = TypeLiteral.getTypeParameters(targetType.getType()); - TypeLiteral<?> collectionTargetType; - if(types.length>0) { - collectionTargetType = TypeLiteral.of(types[0]); - }else { - LOG.warning(String.format("No type information for Collection item type in '{0}', using String.", - context.getKey())); - collectionTargetType = TypeLiteral.of(String.class); - } - T result = collectionSupplier.get(); - switch (mappingType) { - case node_all: - return convertListByNodes(context.getValues(), context, - collectionTargetType, result, true); - case node: - return convertListByNodes(context.getValues(), context, - collectionTargetType, result, false); - case value: - return convertListByValues(context.getValues(), context, - collectionTargetType, result, false); - case value_all: - return convertListByValues(context.getValues(), context, - collectionTargetType, result, true); - case override: - return convertListWithBestGuess(context.getValues(), context, - collectionTargetType, result,false); - case combine: - default: - return convertListWithBestGuess(context.getValues(), context, - collectionTargetType, result,true); - } - } - - private static <T extends Collection> T convertListWithBestGuess(List<PropertyValue> values, - ConversionContext context, - TypeLiteral<?> targetType, - T result, - boolean combine) { - if(!combine){ - values = Collections.singletonList(values.get(0)); - LOG.finest(String.format("Combine deactivated, only checking for collection values in {0}.", values.get(0))); - }else{ - LOG.finest(String.format("Combine activated, checking for collection values in {0}.", values)); - } - // First: try value based approach - for (PropertyValue val : values) { - int valuesFound = 0; - List<String> tokenList = ItemTokenizer.split(val.getValue(), context); - for (String token : tokenList) { - Object o = ItemTokenizer.convertValue(token, targetType, context); - if (o != null) { - valuesFound++; - result.add(o); - } - } - if(valuesFound==0) { - LOG.finest(() -> String.format("No values found in {0} using value evaluation, checking for child nodes...", val)); - for(PropertyValue itemNode:val) { - String textValue = itemNode.getValue(); - if(textValue!=null) { - if (targetType.equals(TypeLiteral.of(String.class))) { - valuesFound++; - result.add(textValue); - } else { - Object o = ItemTokenizer.convertValue(itemNode.getValue(), targetType, context); - if (o != null) { - valuesFound++; - result.add(o); - } - } - } - } - } - if(valuesFound==0){ - LOG.warning(String.format("Failed to convert key '{0}' to type: {1}: no values found.", - val.getKey(), targetType)); - }else{ - LOG.finest(String.format("Found {2} collection values for key '{0}' with type: {1}: no values found.", - val.getKey(), targetType, valuesFound)); - } - } - - return result; - } - - private static <T extends Collection> T convertListByValues(List<PropertyValue> values, - ConversionContext context, - TypeLiteral<?> targetType, - T result, - boolean combine) { - if(!combine){ - values = Collections.singletonList(values.get(0)); - LOG.finest(String.format("Combine deactivated, only checking for collection values in {0}.", values.get(0))); - }else{ - LOG.finest(String.format("Combine activated, checking for collection values in {0}.", values)); - } - for (PropertyValue val : values) { - List<String> tokenList = ItemTokenizer.split(val.getValue(), context); - for (String token : tokenList) { - Object o = ItemTokenizer.convertValue(token, targetType, context); - if (o != null) { - result.add(o); - }else{ - LOG.warning(String.format("Failed to convert '{0}' to type: {1}, key: {2}", - token, targetType, val.getQualifiedKey())); - } - } - } - return result; - } - - private static <T extends Collection> T convertListByNodes(List<PropertyValue> values, - ConversionContext context, - TypeLiteral<?> targetType, - T result, - boolean combine) { - if(!combine){ - values = Collections.singletonList(values.get(0)); - } - for (PropertyValue val : values) { - for(PropertyValue itemNode:val) { - if(targetType.equals(TypeLiteral.of(String.class))){ - result.add(itemNode.getValue()); - }else { - Object o = ItemTokenizer.convertValue(itemNode.getValue(), targetType, context); - if (o != null) { - result.add(o); - }else{ - LOG.warning(String.format("Failed to convert '{0}' to type: {1}, key: {2}", - itemNode.getValue(), targetType, itemNode.getQualifiedKey())); - } - } - } - } - return result; - } - - public static <T extends Map> T convertMap(ConversionContext context, - Supplier<T> collectionSupplier) { - TypeLiteral<?> targetType = context.getTargetType(); - Type[] types = TypeLiteral.getTypeParameters(targetType.getType()); - TypeLiteral<?> collectionTargetType; - if (types.length > 1) { - collectionTargetType = TypeLiteral.of(types[1]); - } else { - LOG.warning(String.format("No type information for Map parameter types in '{0}', using String.", - context.getKey())); - collectionTargetType = TypeLiteral.of(String.class); - } - MappingType mappingType = MappingType.valueOf((String) context.getMeta() - .getOrDefault("mapping", "value_all")); - T result = collectionSupplier.get(); - switch (mappingType) { - case node_all: - return convertMapByNodes(context.getValues(), context, - collectionTargetType, result, true); - case node: - return convertMapByNodes(context.getValues(), context, - collectionTargetType, result, false); - case value: - return convertMapByValues(context.getValues(), context, - collectionTargetType, result, false); - default: - case value_all: - return convertMapByValues(context.getValues(), context, - collectionTargetType, result, true); - } - } - - - private static <T extends Map> T convertMapByValues(List<PropertyValue> values, - ConversionContext context, - TypeLiteral<?> targetType, - T result, - boolean combine) { - if(!combine){ - values = Collections.singletonList(values.get(0)); - LOG.finest(String.format("Combine deactivated, only checking for collection values in {0}.", values.get(0))); - }else{ - LOG.finest(String.format("Combine activated, checking for collection values in {0}.", values)); - } - for (PropertyValue val : values) { - List<String> tokenList = ItemTokenizer.split(val.getValue(), context); - for(String token:tokenList) { - String[] keyValue = ItemTokenizer.splitMapEntry(token, context); - Object o = ItemTokenizer.convertValue(keyValue[1], targetType, context); - if (o != null) { - result.put(keyValue[0], o); - }else{ - LOG.warning(String.format("Failed to convert '{0}' to type: {1}, key: {2}", - keyValue[1], targetType, val.getQualifiedKey())); - } - } - } - return result; - } - - private static <T extends Map> T convertMapByNodes(List<PropertyValue> values, - ConversionContext context, - TypeLiteral<?> targetType, - T result, - boolean combine) { - if(!combine){ - values = Collections.singletonList(values.get(0)); - LOG.finest(String.format("Combine deactivated, only checking for collection values in {0}.", values.get(0))); - }else{ - LOG.finest(String.format("Combine activated, checking for collection values in {0}.", values)); - } - for (PropertyValue val : values) { - for(PropertyValue itemNode:val) { - Object o = ItemTokenizer.convertValue(itemNode.getValue(), targetType, context); - if (o != null) { - result.put(itemNode.getKey(), o); - }else{ - LOG.warning(String.format("Failed to convert '{0}' to type: {1}, key: {2}", - itemNode.getValue(), targetType, itemNode.getQualifiedKey())); - } - } - } - return result; - } - - - @Override - public Collection convert(String value, ConversionContext context) { - String collectionType = (String)context.getMeta().getOrDefault("collection-type", "List"); - if (collectionType.startsWith("java.util.")) { - collectionType = collectionType.substring("java.util.".length()); - } - Collection result = null; - switch (collectionType) { - case "LinkedList": - result = LinkedListConverter.getInstance().convert(value, context); - break; - case "Set": - case "HashSet": - result = HashSetConverter.getInstance().convert(value, context); - break; - case "SortedSet": - case "TreeSet": - result = TreeSetConverter.getInstance().convert(value, context); - break; - case "List": - case "ArrayList": - default: - result = ArrayListConverter.getInstance().convert(value, context); - break; - } - return result; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/main/java/org/apache/tamaya/collections/ConcurrentHashMapConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/ConcurrentHashMapConverter.java b/collections/src/main/java/org/apache/tamaya/collections/ConcurrentHashMapConverter.java deleted file mode 100644 index 506ac00..0000000 --- a/collections/src/main/java/org/apache/tamaya/collections/ConcurrentHashMapConverter.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.collections; - -import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.spi.ConversionContext; -import org.apache.tamaya.spi.PropertyConverter; - -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * PropertyConverter for gnerating ConcurrentHashMap representation of a values. - */ -public class ConcurrentHashMapConverter implements PropertyConverter<ConcurrentHashMap> { - private static final Logger LOG = Logger.getLogger(ConcurrentHashMapConverter.class.getName()); - - /** The shared instance, used by other collection converters in this package.*/ - private static final ConcurrentHashMapConverter INSTANCE = new ConcurrentHashMapConverter(); - - /** - * Provide a shared instance, used by other collection converters in this package. - * @return the shared instance, never null. - */ - static ConcurrentHashMapConverter getInstance(){ - return INSTANCE; - } - - @Override - public ConcurrentHashMap convert(String value, ConversionContext context) { - return CollectionConverter.convertMap(context, ConcurrentHashMap::new); - } - - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/main/java/org/apache/tamaya/collections/HashMapConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/HashMapConverter.java b/collections/src/main/java/org/apache/tamaya/collections/HashMapConverter.java deleted file mode 100644 index 19ecb46..0000000 --- a/collections/src/main/java/org/apache/tamaya/collections/HashMapConverter.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.collections; - -import org.apache.tamaya.spi.ConversionContext; -import org.apache.tamaya.spi.PropertyConverter; - -import java.util.HashMap; -import java.util.logging.Logger; - -/** - * PropertyConverter for gnerating HashMap representation of a values. - */ -public class HashMapConverter implements PropertyConverter<HashMap> { - private static final Logger LOG = Logger.getLogger(HashMapConverter.class.getName()); - - /** The shared instance, used by other collection converters in this package.*/ - private static final HashMapConverter INSTANCE = new HashMapConverter(); - - /** - * Provide a shared instance, used by other collection converters in this package. - * @return the shared instance, never null. - */ - static HashMapConverter getInstance(){ - return INSTANCE; - } - - @Override - public HashMap convert(String value, ConversionContext context) { - return CollectionConverter.convertMap(context, HashMap::new); - } - - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/main/java/org/apache/tamaya/collections/HashSetConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/HashSetConverter.java b/collections/src/main/java/org/apache/tamaya/collections/HashSetConverter.java deleted file mode 100644 index 47a5044..0000000 --- a/collections/src/main/java/org/apache/tamaya/collections/HashSetConverter.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.collections; - -import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.spi.ConversionContext; -import org.apache.tamaya.spi.PropertyConverter; - -import java.util.HashSet; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * PropertyConverter for gnerating HashSet representation of a values. - */ -public class HashSetConverter implements PropertyConverter<HashSet> { - - private static final Logger LOG = Logger.getLogger(HashSetConverter.class.getName()); - - /** The shared instance, used by other collection converters in this package.*/ - private static final HashSetConverter INSTANCE = new HashSetConverter(); - - /** - * Provide a shared instance, used by other collection converters in this package. - * @return the shared instance, never null. - */ - static HashSetConverter getInstance(){ - return INSTANCE; - } - - @Override - public HashSet convert(String value, ConversionContext context) { - return CollectionConverter.convertList(context, HashSet::new); - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/main/java/org/apache/tamaya/collections/ItemTokenizer.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/ItemTokenizer.java b/collections/src/main/java/org/apache/tamaya/collections/ItemTokenizer.java deleted file mode 100644 index 98f5473..0000000 --- a/collections/src/main/java/org/apache/tamaya/collections/ItemTokenizer.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.collections; - -import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.spi.PropertyConverter; -import org.apache.tamaya.spi.ConversionContext; - -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Helper class that implements the tokenizing of the entries of a configuration createValue. - */ -final class ItemTokenizer { - - private static final Logger LOG = Logger.getLogger(ItemTokenizer.class.getName()); - - public static final String ITEM_SEPARATOR = "item-separator"; - public static final String MAP_ENTRY_SEPARATOR = "map-entry-separator"; - public static final String ITEM_CONVERTER = "item-converter"; - - /** - * Private singleton. - */ - private ItemTokenizer(){} - - /** - * Splits the given createValue using the given separator. Matcjhing is done by traversing the String createValue using - * {@code indexOf} calls, one by one. The last unresolvable item (without any next separator token) - * is added at the end of the createList. - * @param value the createValue, not null. - * @return the tokenized createValue as createList, in order of occurrence. - */ - public static List<String> split(String value, ConversionContext ctx){ - String itemSeparator = (String)ctx.getMeta().getOrDefault(ITEM_SEPARATOR, ","); - return split(value, itemSeparator); - } - - /** - * Splits the given createValue using the given separator. Matching is done by traversing the String value using - * {@code indexOf} calls, one by one. The last unresolvable item (without any next separator token) - * is added at the end of the list. - * @param value the value, not null. - * @param separator the separator to be used. - * @return the tokenized value as list, in order of occurrence. - */ - public static List<String> split(String value, final String separator) { - ArrayList<String> result = new ArrayList<>(); - int start = 0; - int end = value.indexOf(separator,start); - while(end>0) { - if (value.charAt(end - 1) != '\\') { - result.add(value.substring(start, end)); - start = end + separator.length(); - } - end = value.indexOf(separator,start); - } - if(start < value.length()){ - result.add(value.substring(start)); - } - return result; - } - - /** - * Splits the given String createValue as a map entry, splitting it into key and createValue part with the given separator. - * If the createValue cannot be split then {@code key = createValue = mapEntry} is used for further processing. key or createValue - * parts are normally trimmed, unless they are enclosed with brackets {@code []}. - * @param mapEntry the entry, not null. - * @return an array of length 2, with the trimmed and parsed key/createValue pair. - */ - public static String[] splitMapEntry(String mapEntry, ConversionContext ctx){ - String entrySeparator = (String)ctx.getMeta().getOrDefault(MAP_ENTRY_SEPARATOR, "="); - return splitMapEntry(mapEntry, entrySeparator); - } - - /** - * Splits the given String createValue as a map entry, splitting it into key and createValue part with the given separator. - * If the createValue cannot be split then {@code key = createValue = mapEntry} is used for further processing. key or createValue - * parts are normally trimmed, unless they are enmcosed with brackets {@code []}. - * @param mapEntry the entry, not null. - * @param separator the separator, not null. - * @return an array of length 2, with the trimmed and parsed key/createValue pair. - */ - public static String[] splitMapEntry(final String mapEntry, final String separator) { - int index = mapEntry.indexOf(separator); - String[] items; - if(index<0) { - items = new String[]{mapEntry, mapEntry}; - }else { - items = new String[]{mapEntry.substring(0,index), - mapEntry.substring(index+separator.length())}; - } - if(items[0].trim().startsWith("[")){ - items[0]= items[0].trim(); - items[0] = items[0].substring(1); - }else{ - items[0]= items[0].trim(); - } - if(items[1].trim().endsWith("]")){ - items[1] = items[1].substring(0,items[1].length()-1); - }else{ - items[1]= items[1].trim(); - } - return items; - } - - /** - * Parses the given createValue into the required collection target type, defined by the context. - * @param value the raw String createValue. - * @return the parsed createValue, or null. - */ - public static <T> T convertValue(String value, TypeLiteral<T> targetType, ConversionContext context) { - String converterClass = context.getMeta().get(ITEM_CONVERTER); - List<PropertyConverter<T>> valueConverters = new ArrayList<>(1); - if (converterClass != null) { - try { - valueConverters.add((PropertyConverter<T>) Class.forName(converterClass).getConstructor() - .newInstance()); - } catch (Exception e) { - LOG.log(Level.SEVERE, "Error convertion config to ArrayList type.", e); - } - } - valueConverters.addAll(context.getConfiguration().getContext().getPropertyConverters(targetType)); - if (valueConverters.isEmpty()) { - if(targetType.getRawType().equals(String.class)) { - return (T)value; - } - } else { - ConversionContext newContext = new ConversionContext.Builder(context.getConfiguration(), context.getKey(), - targetType).build(); - T result = null; - for (PropertyConverter<T> conv : valueConverters) { - try { - result = conv.convert(value, newContext); - if (result != null) { - return result; - } - } catch (Exception e) { - LOG.log(Level.SEVERE, "Error convertion config to ArrayList type.", e); - } - } - } - LOG.log(Level.SEVERE, "Failed to convert collection createValue type for '" + value + "'."); - return null; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/main/java/org/apache/tamaya/collections/LinkedListConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/LinkedListConverter.java b/collections/src/main/java/org/apache/tamaya/collections/LinkedListConverter.java deleted file mode 100644 index b769ab6..0000000 --- a/collections/src/main/java/org/apache/tamaya/collections/LinkedListConverter.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.collections; - -import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.spi.ConversionContext; -import org.apache.tamaya.spi.PropertyConverter; - -import java.util.LinkedList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * PropertyConverter for gnerating LinkedList representation of a values. - */ -public class LinkedListConverter implements PropertyConverter<LinkedList> { - private static final Logger LOG = Logger.getLogger(LinkedListConverter.class.getName()); - - /** The shared instance, used by other collection converters in this package.*/ - private static final LinkedListConverter INSTANCE = new LinkedListConverter(); - - /** - * Provide a shared instance, used by other collection converters in this package. - * @return the shared instance, never null. - */ - static LinkedListConverter getInstance(){ - return INSTANCE; - } - - @Override - public LinkedList convert(String value, ConversionContext context) { - return CollectionConverter.convertList(context, LinkedList::new); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/main/java/org/apache/tamaya/collections/ListConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/ListConverter.java b/collections/src/main/java/org/apache/tamaya/collections/ListConverter.java deleted file mode 100644 index 769be12..0000000 --- a/collections/src/main/java/org/apache/tamaya/collections/ListConverter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.collections; - -import org.apache.tamaya.spi.PropertyConverter; -import org.apache.tamaya.spi.ConversionContext; - -import java.util.Collections; -import java.util.List; -import java.util.function.Supplier; - -/** - * PropertyConverter for gnerating a LIST representation of values. - */ -public class ListConverter implements PropertyConverter<List> { - - @Override - public List convert(String value, ConversionContext context) { - String collectionType = "ArrayList"; - boolean readOnly = false; - if(context!=null) { - collectionType = (String)context.getMeta().getOrDefault("collection-type", "ArrayList"); - if (collectionType.startsWith("java.util.")) { - collectionType = collectionType.substring("java.util.".length()); - } - readOnly = Boolean.parseBoolean((String)context.getMeta().getOrDefault("read-only", "false")); - } - List result = null; - switch(collectionType){ - case "LinkedList": - result = LinkedListConverter.getInstance().convert(value, context); - break; - case "List": - case "ArrayList": - default: - result = ArrayListConverter.getInstance().convert(value, context); - break; - } - if(readOnly){ - return Collections.unmodifiableList(result); - } - return result; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/main/java/org/apache/tamaya/collections/MapConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/MapConverter.java b/collections/src/main/java/org/apache/tamaya/collections/MapConverter.java deleted file mode 100644 index 08fefff..0000000 --- a/collections/src/main/java/org/apache/tamaya/collections/MapConverter.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.collections; - -import org.apache.tamaya.spi.PropertyConverter; -import org.apache.tamaya.spi.ConversionContext; - -import java.util.Collections; -import java.util.Map; - -/** - * PropertyConverter for gnerating HashMap representation of a values. - */ -public class MapConverter implements PropertyConverter<Map> { - - @Override - public Map convert(String value, ConversionContext context) { - String collectionType = "HashMap"; - boolean readOnly = false; - if(context!=null) { - collectionType = (String)context.getMeta().getOrDefault("collection-type", "HashMap"); - if (collectionType.startsWith("java.util.")) { - collectionType = collectionType.substring("java.util.".length()); - } - readOnly = Boolean.parseBoolean((String)context.getMeta().getOrDefault("read-only", "false")); - } - Map result = null; - switch(collectionType){ - case "TreeMap": - case "SortedMap": - result = TreeMapConverter.getInstance().convert(value, context); - break; - case "ConcurrentHashMap": - result = ConcurrentHashMapConverter.getInstance().convert(value, context); - break; - case "Map": - case "HashMap": - default: - result = HashMapConverter.getInstance().convert(value, context); - break; - } - if(readOnly){ - return Collections.unmodifiableMap(result); - } - return result; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/main/java/org/apache/tamaya/collections/SetConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/SetConverter.java b/collections/src/main/java/org/apache/tamaya/collections/SetConverter.java deleted file mode 100644 index b66ef5b..0000000 --- a/collections/src/main/java/org/apache/tamaya/collections/SetConverter.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.collections; - -import org.apache.tamaya.spi.PropertyConverter; -import org.apache.tamaya.spi.ConversionContext; - -import java.util.Collections; -import java.util.Set; - -/** - * PropertyConverter for gnerating a LIST representation of values. - */ -public class SetConverter implements PropertyConverter<Set> { - - @Override - public Set convert(String value, ConversionContext context) { - String collectionType = "Set"; - boolean readOnly = false; - if(context!=null) { - collectionType = (String)context.getMeta().getOrDefault("collection-type", "HashSet"); - if (collectionType.startsWith("java.util.")) { - collectionType = collectionType.substring("java.util.".length()); - } - readOnly = Boolean.parseBoolean((String)context.getMeta().getOrDefault("read-only", "false")); - } - Set result; - switch(collectionType){ - case "TreeSet": - result = TreeSetConverter.getInstance().convert(value, context); - break; - case "Set": - case "HashSet": - default: - result = HashSetConverter.getInstance().convert(value, context); - break; - } - if(readOnly){ - return Collections.unmodifiableSet(result); - } - return result; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/main/java/org/apache/tamaya/collections/SortedMapConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/SortedMapConverter.java b/collections/src/main/java/org/apache/tamaya/collections/SortedMapConverter.java deleted file mode 100644 index 5416e28..0000000 --- a/collections/src/main/java/org/apache/tamaya/collections/SortedMapConverter.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.collections; - -import org.apache.tamaya.spi.ConversionContext; -import org.apache.tamaya.spi.PropertyConverter; - -import java.util.Collections; -import java.util.SortedMap; - -/** - * PropertyConverter for gnerating a LIST representation of values. - */ -public class SortedMapConverter implements PropertyConverter<SortedMap> { - - @Override - public SortedMap convert(String value, ConversionContext context) { - return Collections.unmodifiableSortedMap(TreeMapConverter.getInstance().convert(value, context)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/main/java/org/apache/tamaya/collections/SortedSetConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/SortedSetConverter.java b/collections/src/main/java/org/apache/tamaya/collections/SortedSetConverter.java deleted file mode 100644 index acac96c..0000000 --- a/collections/src/main/java/org/apache/tamaya/collections/SortedSetConverter.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.collections; - -import org.apache.tamaya.spi.ConversionContext; -import org.apache.tamaya.spi.PropertyConverter; - -import java.util.Collections; -import java.util.SortedSet; -import java.util.TreeSet; - -/** - * PropertyConverter for gnerating a LIST representation of values. - */ -public class SortedSetConverter implements PropertyConverter<SortedSet> { - - @Override - public SortedSet convert(String value, ConversionContext context) { - return TreeSetConverter.getInstance().convert(value, context); - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/main/java/org/apache/tamaya/collections/TreeMapConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/TreeMapConverter.java b/collections/src/main/java/org/apache/tamaya/collections/TreeMapConverter.java deleted file mode 100644 index b287dd9..0000000 --- a/collections/src/main/java/org/apache/tamaya/collections/TreeMapConverter.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.collections; - -import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.spi.ConversionContext; -import org.apache.tamaya.spi.PropertyConverter; - -import java.util.List; -import java.util.TreeMap; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * PropertyConverter for gnerating HashMap representation of a values. - */ -public class TreeMapConverter implements PropertyConverter<TreeMap> { - /** Logger used. */ - private static final Logger LOG = Logger.getLogger(HashMapConverter.class.getName()); - - /** The shared instance, used by other collection converters in this package.*/ - private static final TreeMapConverter INSTANCE = new TreeMapConverter(); - - /** - * Provide a shared instance, used by other collection converters in this package. - * @return the shared instance, never null. - */ - static TreeMapConverter getInstance(){ - return INSTANCE; - } - - @Override - public TreeMap convert(String value, ConversionContext context) { - return CollectionConverter.convertMap(context, TreeMap::new); - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/main/java/org/apache/tamaya/collections/TreeSetConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/TreeSetConverter.java b/collections/src/main/java/org/apache/tamaya/collections/TreeSetConverter.java deleted file mode 100644 index c5651f5..0000000 --- a/collections/src/main/java/org/apache/tamaya/collections/TreeSetConverter.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.collections; - -import org.apache.tamaya.spi.ConversionContext; -import org.apache.tamaya.spi.PropertyConverter; - -import java.util.Collections; -import java.util.List; -import java.util.TreeSet; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * PropertyConverter for gnerating HashSet representation of a values. - */ -public class TreeSetConverter implements PropertyConverter<TreeSet> { - - private static final Logger LOG = Logger.getLogger(TreeSetConverter.class.getName()); - - /** The shared instance, used by other collection converters in this package.*/ - private static final TreeSetConverter INSTANCE = new TreeSetConverter(); - - /** - * Provide a shared instance, used by other collection converters in this package. - * @return the shared instance, never null. - */ - static TreeSetConverter getInstance(){ - return INSTANCE; - } - - @Override - public TreeSet convert(String value, ConversionContext context) { - return CollectionConverter.convertList(context, TreeSet::new); - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter ---------------------------------------------------------------------- diff --git a/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter b/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter deleted file mode 100644 index 167bc27..0000000 --- a/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter +++ /dev/null @@ -1,31 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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 current 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. -# -org.apache.tamaya.collections.ArrayListConverter -org.apache.tamaya.collections.CollectionConverter -org.apache.tamaya.collections.HashMapConverter -org.apache.tamaya.collections.ConcurrentHashMapConverter -org.apache.tamaya.collections.HashSetConverter -org.apache.tamaya.collections.LinkedListConverter -org.apache.tamaya.collections.ListConverter -org.apache.tamaya.collections.MapConverter -org.apache.tamaya.collections.SetConverter -org.apache.tamaya.collections.SortedSetConverter -org.apache.tamaya.collections.SortedMapConverter -org.apache.tamaya.collections.TreeMapConverter -org.apache.tamaya.collections.TreeSetConverter http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/test/java/org/apache/tamaya/collections/CollectionAdvancedTests.java ---------------------------------------------------------------------- diff --git a/collections/src/test/java/org/apache/tamaya/collections/CollectionAdvancedTests.java b/collections/src/test/java/org/apache/tamaya/collections/CollectionAdvancedTests.java deleted file mode 100644 index f9ac048..0000000 --- a/collections/src/test/java/org/apache/tamaya/collections/CollectionAdvancedTests.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.collections; - -import org.apache.tamaya.Configuration; -import org.apache.tamaya.TypeLiteral; -import org.junit.Test; - -import java.util.Currency; -import java.util.List; -import java.util.Map; - -import static junit.framework.TestCase.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; - -/** - * Created by atsticks on 16.02.16. - */ -public class CollectionAdvancedTests { - - /** - * Tests if a custom separator works, Config is - * <pre> - * sep-createList=a,b,c|d,e,f|g,h,i - * _sep-createList.collection-type=List - * _sep-createList.collection-separator=| - * </pre> - */ - @Test - public void testCustomSeparator(){ - Configuration config = Configuration.current(); - List<String> items = config.get("sep-list", new TypeLiteral<List<String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(3, items.size()); - assertEquals("a,b,c", items.get(0)); - assertEquals("d,e,f", items.get(1)); - assertEquals("g,h,i", items.get(2)); - } - - /** - * Test typed content. - * <pre> - * currency-createList=CHF,USD,YEN - * _currency-createList.collection-type=List - * </pre> - */ - @Test - public void testTypedContent(){ - Configuration config = Configuration.current(); - List<Currency> items = config.get("currency-list", new TypeLiteral<List<Currency>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(3, items.size()); - assertEquals("CHF", items.get(0).getCurrencyCode()); - assertEquals("USD", items.get(1).getCurrencyCode()); - assertEquals("USS", items.get(2).getCurrencyCode()); - } - - /** - * Tests if a custom parser works, Config is - * <pre> - * parser-createList=a,b,c - * _parser-createList.collection-type=List - * _parser-createList.item-converter=org.apache.tamaya.collections.MyUpperCaseConverter - * </pre> - */ - @Test - public void testCustomParser(){ - Configuration config = Configuration.current(); - List<String> items = config.get("parser-list", new TypeLiteral<List<String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(3, items.size()); - assertEquals("(A)", items.get(0)); - assertEquals("(B)", items.get(1)); - assertEquals("(C)", items.get(2)); - } - - /** - * Redefined map format parsing, Config is as follows: - * <pre> - * redefined-map=0==none | 1==single | 2==any - * _redefined-map.map-entry-separator=== - * _redefined-map.item-separator=| - * </pre> - */ - @Test - public void testCustomMapParser(){ - Configuration config = Configuration.current(); - Map<String,String> items = config.get("redefined-map", Map.class); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(3, items.size()); - assertEquals("none", items.get("0")); - assertEquals("single", items.get("1")); - assertEquals("any", items.get("2")); - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/test/java/org/apache/tamaya/collections/CollectionsBaseTests.java ---------------------------------------------------------------------- diff --git a/collections/src/test/java/org/apache/tamaya/collections/CollectionsBaseTests.java b/collections/src/test/java/org/apache/tamaya/collections/CollectionsBaseTests.java deleted file mode 100644 index 8a531e3..0000000 --- a/collections/src/test/java/org/apache/tamaya/collections/CollectionsBaseTests.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.collections; - -import org.apache.tamaya.Configuration; -import org.apache.tamaya.TypeLiteral; -import org.junit.Test; - -import java.util.*; - -import static junit.framework.TestCase.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; - -/** - * Basic tests for Tamaya collection support. Relevant configs for this tests: - * <pre>base.items=1,2,3,4,5,6,7,8,9,0 - * base.map=1::a, 2::b, 3::c, [4:: ] - * </pre> - */ -public class CollectionsBaseTests { - - @Test - public void testList_String(){ - Configuration config = Configuration.current(); - List<String> items = config.get("base.items", new TypeLiteral<List<String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - items = (List<String>) config.get("base.items", List.class); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - } - - @Test - public void testArrayList_String(){ - Configuration config = Configuration.current(); - ArrayList<String> items = config.get("base.items", new TypeLiteral<ArrayList<String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - items = (ArrayList<String>) config.get("base.items", ArrayList.class); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - } - - @Test - public void testLinkedList_String(){ - Configuration config = Configuration.current(); - LinkedList<String> items = config.get("base.items", new TypeLiteral<LinkedList<String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - items = (LinkedList<String>) config.get("base.items", LinkedList.class); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - } - - @Test - public void testSet_String(){ - Configuration config = Configuration.current(); - Set<String> items = config.get("base.items", new TypeLiteral<Set<String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - items = (Set<String>) config.get("base.items", Set.class); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - } - - @Test - public void testSortedSet_String(){ - Configuration config = Configuration.current(); - Set<String> items = config.get("base.items", new TypeLiteral<SortedSet<String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - items = (SortedSet<String>) config.get("base.items", SortedSet.class); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - } - - @Test - public void testHashSet_String(){ - Configuration config = Configuration.current(); - Set<String> items = config.get("base.items", new TypeLiteral<HashSet<String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - items = (HashSet<String>) config.get("base.items", HashSet.class); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - } - - @Test - public void testTreeSet_String(){ - Configuration config = Configuration.current(); - TreeSet<String> items = config.get("base.items", new TypeLiteral<TreeSet<String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - items = (TreeSet<String>) config.get("base.items", TreeSet.class); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - } - - @Test - public void testMap_String(){ - Configuration config = Configuration.current(); - Map<String,String> items = config.get("base.map", new TypeLiteral<Map<String,String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(4, items.size()); - assertEquals("a", items.get("1")); - assertEquals("b", items.get("2")); - assertEquals("c", items.get("3")); - assertEquals(" ", items.get("4")); - items = (Map<String,String>) config.get("base.map", Map.class); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(4, items.size()); - assertEquals("a", items.get("1")); - assertEquals("b", items.get("2")); - assertEquals("c", items.get("3")); - assertEquals(" ", items.get("4")); - } - - @Test - public void testHashMap_String(){ - Configuration config = Configuration.current(); - Map<String,String> items = config.get("base.map", new TypeLiteral<HashMap<String,String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(4, items.size()); - assertEquals("a", items.get("1")); - assertEquals("b", items.get("2")); - assertEquals("c", items.get("3")); - assertEquals(" ", items.get("4")); - items = (HashMap<String,String>) config.get("base.map", HashMap.class); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(4, items.size()); - assertEquals("a", items.get("1")); - assertEquals("b", items.get("2")); - assertEquals("c", items.get("3")); - assertEquals(" ", items.get("4")); - } - - @Test - public void testSortedMap_String(){ - Configuration config = Configuration.current(); - Map<String,String> items = config.get("base.map", new TypeLiteral<SortedMap<String,String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(4, items.size()); - assertEquals("a", items.get("1")); - assertEquals("b", items.get("2")); - assertEquals("c", items.get("3")); - assertEquals(" ", items.get("4")); - items = (Map<String,String>) config.get("base.map", SortedMap.class); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(4, items.size()); - assertEquals("a", items.get("1")); - assertEquals("b", items.get("2")); - assertEquals("c", items.get("3")); - assertEquals(" ", items.get("4")); - } - - @Test - public void testTreeMap_String(){ - Configuration config = Configuration.current(); - TreeMap<String,String> items = config.get("base.map", new TypeLiteral<TreeMap<String,String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(4, items.size()); - assertEquals("a", items.get("1")); - assertEquals("b", items.get("2")); - assertEquals("c", items.get("3")); - assertEquals(" ", items.get("4")); - items = config.get("base.map", TreeMap.class); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(4, items.size()); - assertEquals("a", items.get("1")); - assertEquals("b", items.get("2")); - assertEquals("c", items.get("3")); - assertEquals(" ", items.get("4")); - } - - @Test - public void testCollection_String(){ - Configuration config = Configuration.current(); - Collection<String> items = config.get("base.items", new TypeLiteral<Collection<String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - items = (Collection<String>) config.get("base.items", Collection.class); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedReadOnlyTests.java ---------------------------------------------------------------------- diff --git a/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedReadOnlyTests.java b/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedReadOnlyTests.java deleted file mode 100644 index 848d1b3..0000000 --- a/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedReadOnlyTests.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.collections; - -import org.apache.tamaya.Configuration; -import org.apache.tamaya.TypeLiteral; -import org.junit.Ignore; -import org.junit.Test; - -import java.util.*; - -import static junit.framework.TestCase.assertEquals; -import static org.junit.Assert.*; - -/** - * Basic tests for Tamaya collection support. Relevant configs for this tests: - * <pre>base.items=1,2,3,4,5,6,7,8,9,0 - * base.map=1::a, 2::b, 3::c, [4:: ] - * </pre> - */ -//@Ignore("Readonly support has been deactivated as of now.") -public class CollectionsTypedReadOnlyTests { - - @Test(expected=UnsupportedOperationException.class) - public void testArrayListList_1(){ - Configuration config = Configuration.current(); - List<String> items = config.get("typed.arraylist", new TypeLiteral<List<String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - items.add("test"); - } - - @Test(expected=UnsupportedOperationException.class) - public void testArrayListList_2(){ - Configuration config = Configuration.current(); - List<String> items = (List<String>) config.get("typed.arraylist", List.class); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - items.add("test"); - } - - @Test - public void testLinkedListList_1(){ - Configuration config = Configuration.current(); - List<String> items = config.get("typed.linkedlist", new TypeLiteral<List<String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - items.add("test"); - } - - @Test - public void testLinkedListList_2(){ - Configuration config = Configuration.current(); - List<String> items = (List<String>) config.get("typed.linkedlist", List.class); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - items.add("test"); - } - - - @Test - public void testHashSet_1(){ - Configuration config = Configuration.current(); - Set<String> items = config.get("typed.hashset", new TypeLiteral<Set<String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - items.add("test"); - } - @Test - public void testHashSet_2(){ - Configuration config = Configuration.current(); - Set<String> items = (Set<String>) config.get("typed.hashset", Set.class); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - items.add("test"); - } - - @Test - public void testTreeSet_1(){ - Configuration config = Configuration.current(); - Set<String> items = config.get("typed.treeset", new TypeLiteral<Set<String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - items.add("test"); - } - @Test - public void testTreeSet_2(){ - Configuration config = Configuration.current(); - Set<String> items = items = (Set<String>) config.get("typed.treeset", Set.class); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(10, items.size()); - items.add("test"); - } - - @Test(expected=UnsupportedOperationException.class) - public void testHashMap_1(){ - Configuration config = Configuration.current(); - Map<String,String> items = config.get("typed.hashmap", new TypeLiteral<Map<String,String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(4, items.size()); - assertEquals("a", items.get("1")); - assertEquals("b", items.get("2")); - assertEquals("c", items.get("3")); - assertEquals(" ", items.get("4")); - items.put("g","hjhhj"); - } - @Test(expected=UnsupportedOperationException.class) - public void testHashMap_2(){ - Configuration config = Configuration.current(); - Map<String,String> items = (Map<String,String>) config.get("typed.hashmap", Map.class); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(4, items.size()); - assertEquals("a", items.get("1")); - assertEquals("b", items.get("2")); - assertEquals("c", items.get("3")); - assertEquals(" ", items.get("4")); - items.put("g","hjhhj"); - } - - - @Test - public void testTreeMap_1(){ - Configuration config = Configuration.current(); - Map<String,String> items = config.get("typed.treemap", new TypeLiteral<Map<String,String>>(){}); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(4, items.size()); - assertEquals("a", items.get("1")); - assertEquals("b", items.get("2")); - assertEquals("c", items.get("3")); - assertEquals(" ", items.get("4")); - items.put("g","hjhhj"); - } - @Test - public void testTreeMap_2(){ - Configuration config = Configuration.current(); - Map<String,String> items = (Map<String,String>) config.get("typed.treemap", Map.class); - assertNotNull(items); - assertFalse(items.isEmpty()); - assertEquals(4, items.size()); - assertEquals("a", items.get("1")); - assertEquals("b", items.get("2")); - assertEquals("c", items.get("3")); - assertEquals(" ", items.get("4")); - items.put("g","hjhhj"); - } - -}
