You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2016/02/27 22:40:36 UTC
[3/6] incubator-tamaya git commit: Moved collections module into
active modules folder.
Moved collections module into active modules folder.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/314ad28d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/314ad28d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/314ad28d
Branch: refs/heads/master
Commit: 314ad28dac5e558331724e9ad5f6eec3d9152f57
Parents: 6d9abde
Author: anatole <an...@apache.org>
Authored: Sat Feb 27 22:12:31 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Feb 27 22:12:31 2016 +0100
----------------------------------------------------------------------
modules/collections/pom.xml | 75 ++++++
.../internal/AdaptiveCombinationPolicy.java | 126 ++++++++++
.../internal/ArrayListConverter.java | 64 ++++++
.../internal/CollectionConverter.java | 63 +++++
.../internal/ConcurrentHashMapConverter.java | 65 ++++++
.../collections/internal/HashMapConverter.java | 64 ++++++
.../collections/internal/HashSetConverter.java | 65 ++++++
.../collections/internal/ItemTokenizer.java | 171 ++++++++++++++
.../internal/LinkedListConverter.java | 64 ++++++
.../collections/internal/ListConverter.java | 55 +++++
.../collections/internal/MapConverter.java | 59 +++++
.../collections/internal/SetConverter.java | 55 +++++
.../internal/SortedMapConverter.java | 37 +++
.../internal/SortedSetConverter.java | 36 +++
.../collections/internal/TreeMapConverter.java | 62 +++++
.../collections/internal/TreeSetConverter.java | 64 ++++++
.../org.apache.tamaya.spi.PropertyConverter | 31 +++
...he.tamaya.spi.PropertyValueCombinationPolicy | 19 ++
.../collections/CollectionAdvancedTests.java | 99 ++++++++
.../collections/CollectionsBaseTests.java | 227 +++++++++++++++++++
.../CollectionsTypedReadOnlyTests.java | 173 ++++++++++++++
.../collections/CollectionsTypedTests.java | 208 +++++++++++++++++
.../collections/MyUpperCaseConverter.java | 33 +++
.../META-INF/javaconfiguration.properties | 73 ++++++
sandbox/collections/pom.xml | 75 ------
.../internal/AdaptiveCombinationPolicy.java | 126 ----------
.../internal/ArrayListConverter.java | 64 ------
.../internal/CollectionConverter.java | 63 -----
.../internal/ConcurrentHashMapConverter.java | 65 ------
.../collections/internal/HashMapConverter.java | 64 ------
.../collections/internal/HashSetConverter.java | 65 ------
.../collections/internal/ItemTokenizer.java | 171 --------------
.../internal/LinkedListConverter.java | 64 ------
.../collections/internal/ListConverter.java | 55 -----
.../collections/internal/MapConverter.java | 59 -----
.../collections/internal/SetConverter.java | 55 -----
.../internal/SortedMapConverter.java | 37 ---
.../internal/SortedSetConverter.java | 36 ---
.../collections/internal/TreeMapConverter.java | 62 -----
.../collections/internal/TreeSetConverter.java | 64 ------
.../org.apache.tamaya.spi.PropertyConverter | 31 ---
...he.tamaya.spi.PropertyValueCombinationPolicy | 19 --
.../collections/CollectionAdvancedTests.java | 99 --------
.../collections/CollectionsBaseTests.java | 227 -------------------
.../CollectionsTypedReadOnlyTests.java | 173 --------------
.../collections/CollectionsTypedTests.java | 208 -----------------
.../collections/MyUpperCaseConverter.java | 33 ---
.../META-INF/javaconfiguration.properties | 73 ------
48 files changed, 1988 insertions(+), 1988 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/314ad28d/modules/collections/pom.xml
----------------------------------------------------------------------
diff --git a/modules/collections/pom.xml b/modules/collections/pom.xml
new file mode 100644
index 0000000..d5ed30b
--- /dev/null
+++ b/modules/collections/pom.xml
@@ -0,0 +1,75 @@
+<!--
+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.2-incubating-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>tamaya-collections</artifactId>
+ <name>Apache Tamaya Modules - Collections Support</name>
+ <packaging>bundle</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-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.apache.tamaya,
+ org.apache.tamaya.spi,
+ javax.annotation,
+ *
+ </Import-Package>
+ <Private-Package>
+ org.apache.tamaya.collections.internal
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/314ad28d/modules/collections/src/main/java/org/apache/tamaya/collections/internal/AdaptiveCombinationPolicy.java
----------------------------------------------------------------------
diff --git a/modules/collections/src/main/java/org/apache/tamaya/collections/internal/AdaptiveCombinationPolicy.java b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/AdaptiveCombinationPolicy.java
new file mode 100644
index 0000000..d86abe7
--- /dev/null
+++ b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/AdaptiveCombinationPolicy.java
@@ -0,0 +1,126 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
+
+import javax.annotation.Priority;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * PropertyValueCombinationPolicy that allows to configure a PropertyValueCombinationPolicy for each key
+ * individually, by adding a configured entry of the form
+ * {@code _key.combination-policy=collect|override|fqPolicyClassName}.
+ */
+@Priority(100)
+public class AdaptiveCombinationPolicy implements PropertyValueCombinationPolicy {
+ /** Logger. */
+ private static final Logger LOG = Logger.getLogger(AdaptiveCombinationPolicy.class.getName());
+
+ /**
+ * Collecting combination policy using (optional) {@code item-separator} parameter for determining the sparator
+ * to combine multiple config entries found.
+ */
+ private static final PropertyValueCombinationPolicy COLLECTING_POLICY = new PropertyValueCombinationPolicy(){
+ @Override
+ public Map<String, String> collect(Map<String, String> currentValue, String key, PropertySource propertySource) {
+ // check for default collection combination policies for lists, sets, maps etc.
+ final String SEPARATOR = ConfigurationProvider.getConfiguration().getOrDefault('_' + key+".item-separator", ",");
+ PropertyValue newValue = propertySource.get(key);
+ if(newValue!=null){
+ Map<String,String> newMapValue = new HashMap<>();
+ if(currentValue!=null){
+ newMapValue.putAll(currentValue);
+ }
+ String oldVal = newMapValue.get(key);
+ newMapValue.putAll(newValue.getConfigEntries());
+ if(oldVal!=null){
+ newMapValue.put(key,oldVal + SEPARATOR + newValue.getValue());
+ }
+ return newMapValue;
+ }else{
+ if(currentValue!=null){
+ return currentValue;
+ }
+ return Collections.emptyMap();
+ }
+ }
+ };
+
+ /** Cache for loaded custom combination policies. */
+ private Map<Class, PropertyValueCombinationPolicy> configuredPolicies = new ConcurrentHashMap<>();
+
+ @Override
+ public Map<String,String> collect(Map<String,String> currentValue, String key, PropertySource propertySource){
+ if(key.startsWith("_")){
+ PropertyValue newValue = propertySource.get(key);
+ if(newValue!=null){
+ return newValue.getConfigEntries();
+ }
+ return currentValue;
+ }
+ String adaptiveCombinationPolicyClass = ConfigurationProvider.getConfiguration().getOrDefault(
+ '_' + key+".combination-policy", "override");
+ PropertyValueCombinationPolicy combinationPolicy = null;
+ switch(adaptiveCombinationPolicyClass){
+ case "collect":
+ case "COLLECT":
+ if(LOG.isLoggable(Level.FINEST)){
+ LOG.finest("Using collecting combination policy for key: " + key + "");
+ }
+ combinationPolicy = COLLECTING_POLICY;
+ break;
+ case "override":
+ case "OVERRIDE":
+ if(LOG.isLoggable(Level.FINEST)){
+ LOG.finest("Using default (overriding) combination policy for key: " + key + "");
+ }
+ combinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
+ break;
+ default:
+ try{
+ Class<PropertyValueCombinationPolicy> clazz = (Class<PropertyValueCombinationPolicy>)
+ Class.forName(adaptiveCombinationPolicyClass);
+ combinationPolicy = configuredPolicies.get(clazz);
+ if(combinationPolicy==null){
+ combinationPolicy = clazz.newInstance();
+ configuredPolicies.put(clazz, combinationPolicy);
+ }
+ if(LOG.isLoggable(Level.FINEST)){
+ LOG.finest("Using custom combination policy "+adaptiveCombinationPolicyClass+" for " +
+ "key: " + key + "");
+ }
+ }
+ catch(Exception e){
+ LOG.log(Level.SEVERE, "Error loading configured PropertyValueCombinationPolicy for " +
+ "key: " + key + ", using default (overriding) policy.", e);
+ combinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
+ }
+ }
+ return combinationPolicy.collect(currentValue, key, propertySource);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/314ad28d/modules/collections/src/main/java/org/apache/tamaya/collections/internal/ArrayListConverter.java
----------------------------------------------------------------------
diff --git a/modules/collections/src/main/java/org/apache/tamaya/collections/internal/ArrayListConverter.java b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/ArrayListConverter.java
new file mode 100644
index 0000000..8281395
--- /dev/null
+++ b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/ArrayListConverter.java
@@ -0,0 +1,64 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+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 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) {
+ List<String> rawList = ItemTokenizer.split(value, context);
+ ArrayList<Object> mlist = new ArrayList<>();
+ for(String raw:rawList){
+ Object convValue = ItemTokenizer.convertValue(raw, context);
+ if (convValue != null) {
+ mlist.add(convValue);
+ }else{
+ LOG.log(Level.SEVERE, "Failed to convert collection value type for '"+raw+"'.");
+ }
+ }
+ return mlist;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/314ad28d/modules/collections/src/main/java/org/apache/tamaya/collections/internal/CollectionConverter.java
----------------------------------------------------------------------
diff --git a/modules/collections/src/main/java/org/apache/tamaya/collections/internal/CollectionConverter.java b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/CollectionConverter.java
new file mode 100644
index 0000000..0d9a799
--- /dev/null
+++ b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/CollectionConverter.java
@@ -0,0 +1,63 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * PropertyConverter for gnerating a LIST representation of values.
+ */
+public class CollectionConverter implements PropertyConverter<Collection> {
+
+ @Override
+ public Collection convert(String value, ConversionContext context) {
+ String collectionType = context.getConfiguration().getOrDefault('_' + context.getKey()+".collection-type", "List");
+ if(collectionType.startsWith("java.util.")){
+ collectionType = collectionType.substring("java.util.".length());
+ }
+ Collection result = null;
+ switch(collectionType){
+ case "List":
+ case "ArrayList":
+ default:
+ result = ArrayListConverter.getInstance().convert(value, context);
+ break;
+ 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;
+ }
+ if(context.getConfiguration().getOrDefault('_' + context.getKey()+".read-only",
+ Boolean.class, Boolean.TRUE)){
+ return Collections.unmodifiableCollection(result);
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/314ad28d/modules/collections/src/main/java/org/apache/tamaya/collections/internal/ConcurrentHashMapConverter.java
----------------------------------------------------------------------
diff --git a/modules/collections/src/main/java/org/apache/tamaya/collections/internal/ConcurrentHashMapConverter.java b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/ConcurrentHashMapConverter.java
new file mode 100644
index 0000000..131b41c
--- /dev/null
+++ b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/ConcurrentHashMapConverter.java
@@ -0,0 +1,65 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.HashMap;
+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 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) {
+ List<String> rawList = ItemTokenizer.split(value, context);
+ ConcurrentHashMap result = new ConcurrentHashMap(rawList.size());
+ for(String raw:rawList){
+ String[] items = ItemTokenizer.splitMapEntry(raw, context);
+ Object convValue = ItemTokenizer.convertValue(items[1], context);
+ if(convValue!=null){
+ result.put(items[0], convValue);
+ }else{
+ LOG.log(Level.SEVERE, "Failed to convert collection value type for '"+raw+"'.");
+ }
+ }
+ return result;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/314ad28d/modules/collections/src/main/java/org/apache/tamaya/collections/internal/HashMapConverter.java
----------------------------------------------------------------------
diff --git a/modules/collections/src/main/java/org/apache/tamaya/collections/internal/HashMapConverter.java b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/HashMapConverter.java
new file mode 100644
index 0000000..6a3ac97
--- /dev/null
+++ b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/HashMapConverter.java
@@ -0,0 +1,64 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.logging.Level;
+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 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) {
+ List<String> rawList = ItemTokenizer.split(value, context);
+ HashMap result = new HashMap(rawList.size());
+ for(String raw:rawList){
+ String[] items = ItemTokenizer.splitMapEntry(raw, context);
+ Object convValue = ItemTokenizer.convertValue(items[1], context);
+ if(convValue!=null){
+ result.put(items[0], convValue);
+ }else{
+ LOG.log(Level.SEVERE, "Failed to convert collection value type for '"+raw+"'.");
+ }
+ }
+ return result;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/314ad28d/modules/collections/src/main/java/org/apache/tamaya/collections/internal/HashSetConverter.java
----------------------------------------------------------------------
diff --git a/modules/collections/src/main/java/org/apache/tamaya/collections/internal/HashSetConverter.java b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/HashSetConverter.java
new file mode 100644
index 0000000..40b204f
--- /dev/null
+++ b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/HashSetConverter.java
@@ -0,0 +1,65 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedList;
+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 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) {
+ List<String> rawList = ItemTokenizer.split(value, context);
+ HashSet<Object> result = new HashSet<>();
+ for(String raw:rawList){
+ String[] items = ItemTokenizer.splitMapEntry(raw, context);
+ Object convValue = ItemTokenizer.convertValue(items[1], context);
+ if(convValue!=null){
+ result.add(convValue);
+ }else{
+ LOG.log(Level.SEVERE, "Failed to convert collection value type for '"+raw+"'.");
+ }
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/314ad28d/modules/collections/src/main/java/org/apache/tamaya/collections/internal/ItemTokenizer.java
----------------------------------------------------------------------
diff --git a/modules/collections/src/main/java/org/apache/tamaya/collections/internal/ItemTokenizer.java b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/ItemTokenizer.java
new file mode 100644
index 0000000..7d213a4
--- /dev/null
+++ b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/ItemTokenizer.java
@@ -0,0 +1,171 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+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 value.
+ */
+final class ItemTokenizer {
+
+ private static final Logger LOG = Logger.getLogger(ItemTokenizer.class.getName());
+
+ /**
+ * Private singleton.
+ */
+ private ItemTokenizer(){}
+
+ /**
+ * Splits the given value using the given separator. Matcjhing 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 context the conversion context.
+ * @return the tokenized value as list, in order of occurrence.
+ */
+ public static List<String> split(String value, ConversionContext context){
+ return split(value, ConfigurationProvider.getConfiguration().getOrDefault(
+ '_' + context.getKey()+ "" +
+ "item-separator", ","));
+ }
+
+ /**
+ * Splits the given value using the given separator. Matcjhing 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 (end>0 && (value.charAt(end - 1) != '\\')) {
+ result.add(value.substring(start, end));
+ start = end + separator.length();
+ end = value.indexOf(separator,start);
+ }else{
+ end = value.indexOf(separator,end + separator.length());
+ }
+ end = value.indexOf(separator,start);
+ }
+ if(start < value.length()){
+ result.add(value.substring(start));
+ }
+ return result;
+ }
+
+ /**
+ * plits the given String value as a map entry, splitting it into key and value part with the given separator.
+ * If the value cannot be split then {@code key = value = mapEntry} is used for further processing. key or value
+ * parts are normally trimmed, unless they are enmcosed with brackets {@code []}.
+ * @param mapEntry the entry, not null.
+ * @param context the conversion context.
+ * @return an array of length 2, with the trimmed and parsed key/value pair.
+ */
+ public static String[] splitMapEntry(String mapEntry, ConversionContext context){
+ return splitMapEntry(mapEntry, ConfigurationProvider.getConfiguration().getOrDefault(
+ '_' + context.getKey()+".map-entry-separator", "::"));
+ }
+
+ /**
+ * Splits the given String value as a map entry, splitting it into key and value part with the given separator.
+ * If the value cannot be split then {@code key = value = mapEntry} is used for further processing. key or value
+ * 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/value 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 value into the required collection target type, defined by the context.
+ * @param value the raw String value.
+ * @param context the context
+ * @return the parsed value, or null.
+ */
+ public static Object convertValue(String value, ConversionContext context) {
+ String converterClass = context.getConfiguration().get('_' + context.getKey() + ".item-converter");
+ List<PropertyConverter<Object>> valueConverters = new ArrayList<>(1);
+ if (converterClass != null) {
+ try {
+ valueConverters.add((PropertyConverter<Object>) Class.forName(converterClass).newInstance());
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Error convertion config to ArrayList type.", e);
+ }
+ }
+ if (TypeLiteral.getTypeParameters(context.getTargetType().getType()).length>0) {
+ valueConverters.addAll(context.getConfigurationContext().getPropertyConverters(
+ TypeLiteral.of(TypeLiteral.getTypeParameters(context.getTargetType().getType())[0])));
+ }
+ ConversionContext ctx = new ConversionContext.Builder(context.getConfiguration(),
+ context.getConfigurationContext(), context.getKey(),
+ TypeLiteral.of(context.getTargetType().getType())).build();
+ Object result = null;
+ if (valueConverters.isEmpty()) {
+ return value;
+ } else {
+ for (PropertyConverter<Object> conv : valueConverters) {
+ try {
+ result = conv.convert(value, ctx);
+ 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 value type for '" + value + "'.");
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/314ad28d/modules/collections/src/main/java/org/apache/tamaya/collections/internal/LinkedListConverter.java
----------------------------------------------------------------------
diff --git a/modules/collections/src/main/java/org/apache/tamaya/collections/internal/LinkedListConverter.java b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/LinkedListConverter.java
new file mode 100644
index 0000000..4389a54
--- /dev/null
+++ b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/LinkedListConverter.java
@@ -0,0 +1,64 @@
+/*
+ * 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.internal;
+
+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 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) {
+ List<String> rawList = ItemTokenizer.split(value, context);
+ LinkedList<Object> result = new LinkedList<>();
+ for(String raw:rawList){
+ String[] items = ItemTokenizer.splitMapEntry(raw, context);
+ Object convValue = ItemTokenizer.convertValue(items[1], context);
+ if(convValue!=null){
+ result.add(convValue);
+ continue;
+ }else{
+ LOG.log(Level.SEVERE, "Failed to convert collection value type for '"+raw+"'.");
+ }
+ }
+ return result;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/314ad28d/modules/collections/src/main/java/org/apache/tamaya/collections/internal/ListConverter.java
----------------------------------------------------------------------
diff --git a/modules/collections/src/main/java/org/apache/tamaya/collections/internal/ListConverter.java b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/ListConverter.java
new file mode 100644
index 0000000..65fc54e
--- /dev/null
+++ b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/ListConverter.java
@@ -0,0 +1,55 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * PropertyConverter for gnerating a LIST representation of values.
+ */
+public class ListConverter implements PropertyConverter<List> {
+
+ @Override
+ public List convert(String value, ConversionContext context) {
+ String collectionType = context.getConfiguration().getOrDefault('_' + context.getKey()+".collection-type", "List");
+ if(collectionType.startsWith("java.util.")){
+ collectionType = collectionType.substring("java.util.".length());
+ }
+ List result = null;
+ switch(collectionType){
+ case "List":
+ case "ArrayList":
+ default:
+ result = ArrayListConverter.getInstance().convert(value, context);
+ break;
+ case "LinkedList":
+ result = LinkedListConverter.getInstance().convert(value, context);
+ break;
+ }
+ if(context.getConfiguration().getOrDefault('_' + context.getKey()+".read-only",
+ Boolean.class, Boolean.TRUE)){
+ return Collections.unmodifiableList(result);
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/314ad28d/modules/collections/src/main/java/org/apache/tamaya/collections/internal/MapConverter.java
----------------------------------------------------------------------
diff --git a/modules/collections/src/main/java/org/apache/tamaya/collections/internal/MapConverter.java b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/MapConverter.java
new file mode 100644
index 0000000..606e14f
--- /dev/null
+++ b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/MapConverter.java
@@ -0,0 +1,59 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * PropertyConverter for gnerating HashMap representation of a values.
+ */
+public class MapConverter implements PropertyConverter<Map> {
+
+ @Override
+ public Map convert(String value, ConversionContext context) {
+ String collectionType = context.getConfiguration().getOrDefault('_' + context.getKey()+".collection-type", "Map");
+ if(collectionType.startsWith("java.util.")){
+ collectionType = collectionType.substring("java.util.".length());
+ }
+ Map result = null;
+ switch(collectionType){
+ case "Map":
+ case "HashMap":
+ default:
+ result = HashMapConverter.getInstance().convert(value, context);
+ break;
+ case "TreeMap":
+ result = TreeMapConverter.getInstance().convert(value, context);
+ break;
+ case "ConcurrentHashMap":
+ result = ConcurrentHashMapConverter.getInstance().convert(value, context);
+ break;
+ }
+ if(context.getConfiguration().getOrDefault('_' + context.getKey()+".read-only",
+ Boolean.class, Boolean.TRUE)){
+ return Collections.unmodifiableMap(result);
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/314ad28d/modules/collections/src/main/java/org/apache/tamaya/collections/internal/SetConverter.java
----------------------------------------------------------------------
diff --git a/modules/collections/src/main/java/org/apache/tamaya/collections/internal/SetConverter.java b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/SetConverter.java
new file mode 100644
index 0000000..75301bc
--- /dev/null
+++ b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/SetConverter.java
@@ -0,0 +1,55 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+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 = context.getConfiguration().getOrDefault('_' + context.getKey()+".collection-type", "Set");
+ if(collectionType.startsWith("java.util.")){
+ collectionType = collectionType.substring("java.util.".length());
+ }
+ Set result = null;
+ switch(collectionType){
+ case "Set":
+ case "HashSet":
+ default:
+ result = HashSetConverter.getInstance().convert(value, context);
+ break;
+ case "TreeSet":
+ result = TreeSetConverter.getInstance().convert(value, context);
+ break;
+ }
+ if(context.getConfiguration().getOrDefault('_' + context.getKey()+".read-only",
+ Boolean.class, Boolean.TRUE)){
+ return Collections.unmodifiableSet(result);
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/314ad28d/modules/collections/src/main/java/org/apache/tamaya/collections/internal/SortedMapConverter.java
----------------------------------------------------------------------
diff --git a/modules/collections/src/main/java/org/apache/tamaya/collections/internal/SortedMapConverter.java b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/SortedMapConverter.java
new file mode 100644
index 0000000..1015751
--- /dev/null
+++ b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/SortedMapConverter.java
@@ -0,0 +1,37 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Collections;
+import java.util.SortedMap;
+import java.util.SortedSet;
+
+/**
+ * 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/blob/314ad28d/modules/collections/src/main/java/org/apache/tamaya/collections/internal/SortedSetConverter.java
----------------------------------------------------------------------
diff --git a/modules/collections/src/main/java/org/apache/tamaya/collections/internal/SortedSetConverter.java b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/SortedSetConverter.java
new file mode 100644
index 0000000..c0b8065
--- /dev/null
+++ b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/SortedSetConverter.java
@@ -0,0 +1,36 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Collections;
+import java.util.SortedSet;
+
+/**
+ * PropertyConverter for gnerating a LIST representation of values.
+ */
+public class SortedSetConverter implements PropertyConverter<SortedSet> {
+
+ @Override
+ public SortedSet convert(String value, ConversionContext context) {
+ return Collections.unmodifiableSortedSet(TreeSetConverter.getInstance().convert(value, context));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/314ad28d/modules/collections/src/main/java/org/apache/tamaya/collections/internal/TreeMapConverter.java
----------------------------------------------------------------------
diff --git a/modules/collections/src/main/java/org/apache/tamaya/collections/internal/TreeMapConverter.java b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/TreeMapConverter.java
new file mode 100644
index 0000000..fef25fe
--- /dev/null
+++ b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/TreeMapConverter.java
@@ -0,0 +1,62 @@
+/*
+ * 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.internal;
+
+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 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) {
+ List<String> rawList = ItemTokenizer.split(value, context);
+ TreeMap result = new TreeMap();
+ for(String raw:rawList){
+ String[] items = ItemTokenizer.splitMapEntry(raw, context);
+ Object convValue = ItemTokenizer.convertValue(items[1], context);
+ if(convValue!=null){
+ result.put(items[0], convValue);
+ }else{
+ LOG.log(Level.SEVERE, "Failed to convert collection value type for '"+raw+"'.");
+ }
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/314ad28d/modules/collections/src/main/java/org/apache/tamaya/collections/internal/TreeSetConverter.java
----------------------------------------------------------------------
diff --git a/modules/collections/src/main/java/org/apache/tamaya/collections/internal/TreeSetConverter.java b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/TreeSetConverter.java
new file mode 100644
index 0000000..9206f07
--- /dev/null
+++ b/modules/collections/src/main/java/org/apache/tamaya/collections/internal/TreeSetConverter.java
@@ -0,0 +1,64 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+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 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) {
+ List<String> rawList = ItemTokenizer.split(value, context);
+ TreeSet<Object> result = new TreeSet<>();
+ for(String raw:rawList){
+ String[] items = ItemTokenizer.splitMapEntry(raw, context);
+ Object convValue = ItemTokenizer.convertValue(items[1], context);
+ if(convValue!=null){
+ result.add(convValue);
+ continue;
+ }else{
+ LOG.log(Level.SEVERE, "Failed to convert collection value type for '"+raw+"'.");
+ }
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/314ad28d/modules/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
----------------------------------------------------------------------
diff --git a/modules/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter b/modules/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
new file mode 100644
index 0000000..9a93a69
--- /dev/null
+++ b/modules/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
@@ -0,0 +1,31 @@
+#
+# 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.internal.ArrayListConverter
+org.apache.tamaya.collections.internal.CollectionConverter
+org.apache.tamaya.collections.internal.HashMapConverter
+org.apache.tamaya.collections.internal.ConcurrentHashMapConverter
+org.apache.tamaya.collections.internal.HashSetConverter
+org.apache.tamaya.collections.internal.LinkedListConverter
+org.apache.tamaya.collections.internal.ListConverter
+org.apache.tamaya.collections.internal.MapConverter
+org.apache.tamaya.collections.internal.SetConverter
+org.apache.tamaya.collections.internal.SortedSetConverter
+org.apache.tamaya.collections.internal.SortedMapConverter
+org.apache.tamaya.collections.internal.TreeMapConverter
+org.apache.tamaya.collections.internal.TreeSetConverter
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/314ad28d/modules/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy
----------------------------------------------------------------------
diff --git a/modules/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy b/modules/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy
new file mode 100644
index 0000000..6b7a67b
--- /dev/null
+++ b/modules/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy
@@ -0,0 +1,19 @@
+#
+# 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.internal.AdaptiveCombinationPolicy
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/314ad28d/modules/collections/src/test/java/org/apache/tamaya/collections/CollectionAdvancedTests.java
----------------------------------------------------------------------
diff --git a/modules/collections/src/test/java/org/apache/tamaya/collections/CollectionAdvancedTests.java b/modules/collections/src/test/java/org/apache/tamaya/collections/CollectionAdvancedTests.java
new file mode 100644
index 0000000..ddabb23
--- /dev/null
+++ b/modules/collections/src/test/java/org/apache/tamaya/collections/CollectionAdvancedTests.java
@@ -0,0 +1,99 @@
+package org.apache.tamaya.collections;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+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-list=a,b,c|d,e,f|g,h,i
+ * _sep-list.collection-type=List
+ * _sep-list.collection-separator=|
+ * </pre>
+ */
+ @Test
+ public void testCustomSeparator(){
+ Configuration config = ConfigurationProvider.getConfiguration();
+ 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-list=CHF,USD,YEN
+ * _currency-list.collection-type=List
+ * </pre>
+ */
+ @Test
+ public void testTypedContent(){
+ Configuration config = ConfigurationProvider.getConfiguration();
+ 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-list=a,b,c
+ * _parser-list.collection-type=List
+ * _parser-list.item-converter=org.apache.tamaya.collections.MyUpperCaseConverter
+ * </pre>
+ */
+ @Test
+ public void testCustomParser(){
+ Configuration config = ConfigurationProvider.getConfiguration();
+ 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 = ConfigurationProvider.getConfiguration();
+ 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/blob/314ad28d/modules/collections/src/test/java/org/apache/tamaya/collections/CollectionsBaseTests.java
----------------------------------------------------------------------
diff --git a/modules/collections/src/test/java/org/apache/tamaya/collections/CollectionsBaseTests.java b/modules/collections/src/test/java/org/apache/tamaya/collections/CollectionsBaseTests.java
new file mode 100644
index 0000000..34c82cb
--- /dev/null
+++ b/modules/collections/src/test/java/org/apache/tamaya/collections/CollectionsBaseTests.java
@@ -0,0 +1,227 @@
+/*
+ * 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.ConfigurationProvider;
+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 = ConfigurationProvider.getConfiguration();
+ 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 = ConfigurationProvider.getConfiguration();
+ 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 = ConfigurationProvider.getConfiguration();
+ 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 = ConfigurationProvider.getConfiguration();
+ 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 = ConfigurationProvider.getConfiguration();
+ 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 = ConfigurationProvider.getConfiguration();
+ 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 = ConfigurationProvider.getConfiguration();
+ 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 = ConfigurationProvider.getConfiguration();
+ 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 = ConfigurationProvider.getConfiguration();
+ 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 = ConfigurationProvider.getConfiguration();
+ 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 = ConfigurationProvider.getConfiguration();
+ 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 = ConfigurationProvider.getConfiguration();
+ 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/blob/314ad28d/modules/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedReadOnlyTests.java
----------------------------------------------------------------------
diff --git a/modules/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedReadOnlyTests.java b/modules/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedReadOnlyTests.java
new file mode 100644
index 0000000..7882512
--- /dev/null
+++ b/modules/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedReadOnlyTests.java
@@ -0,0 +1,173 @@
+/*
+ * 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.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+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>
+ */
+public class CollectionsTypedReadOnlyTests {
+
+ @Test(expected=UnsupportedOperationException.class)
+ public void testArrayListList_1(){
+ Configuration config = ConfigurationProvider.getConfiguration();
+ 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 = ConfigurationProvider.getConfiguration();
+ List<String> items = (List<String>) config.get("typed.arraylist", List.class);
+ assertNotNull(items);
+ assertFalse(items.isEmpty());
+ assertEquals(10, items.size());
+ items.add("test");
+ }
+
+ @Test(expected=UnsupportedOperationException.class)
+ public void testLinkedListList_1(){
+ Configuration config = ConfigurationProvider.getConfiguration();
+ List<String> items = config.get("typed.linkedlist", new TypeLiteral<List<String>>(){});
+ assertNotNull(items);
+ assertFalse(items.isEmpty());
+ assertEquals(10, items.size());
+ items.add("test");
+ }
+
+ @Test(expected=UnsupportedOperationException.class)
+ public void testLinkedListList_2(){
+ Configuration config = ConfigurationProvider.getConfiguration();
+ List<String> items = (List<String>) config.get("typed.linkedlist", List.class);
+ assertNotNull(items);
+ assertFalse(items.isEmpty());
+ assertEquals(10, items.size());
+ items.add("test");
+ }
+
+
+ @Test(expected=UnsupportedOperationException.class)
+ public void testHashSet_1(){
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Set<String> items = config.get("typed.hashset", new TypeLiteral<Set<String>>(){});
+ assertNotNull(items);
+ assertFalse(items.isEmpty());
+ assertEquals(10, items.size());
+ items.add("test");
+ }
+ @Test(expected=UnsupportedOperationException.class)
+ public void testHashSet_2(){
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Set<String> items = (Set<String>) config.get("typed.hashset", Set.class);
+ assertNotNull(items);
+ assertFalse(items.isEmpty());
+ assertEquals(10, items.size());
+ items.add("test");
+ }
+
+ @Test(expected=UnsupportedOperationException.class)
+ public void testTreeSet_1(){
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Set<String> items = config.get("typed.treeset", new TypeLiteral<Set<String>>(){});
+ assertNotNull(items);
+ assertFalse(items.isEmpty());
+ assertEquals(10, items.size());
+ items.add("test");
+ }
+ @Test(expected=UnsupportedOperationException.class)
+ public void testTreeSet_2(){
+ Configuration config = ConfigurationProvider.getConfiguration();
+ 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 = ConfigurationProvider.getConfiguration();
+ 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 = ConfigurationProvider.getConfiguration();
+ 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(expected=UnsupportedOperationException.class)
+ public void testTreeMap_1(){
+ Configuration config = ConfigurationProvider.getConfiguration();
+ 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(expected=UnsupportedOperationException.class)
+ public void testTreeMap_2(){
+ Configuration config = ConfigurationProvider.getConfiguration();
+ 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");
+ }
+
+}