You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by pl...@apache.org on 2016/09/06 17:18:17 UTC
[21/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-114:
Added further files for collection support.
TAMAYA-114: Added further files for collection support.
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/8e237d9f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/8e237d9f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/8e237d9f
Branch: refs/heads/master
Commit: 8e237d9f8055e976c0f20db1b62d41c1482f4a57
Parents: 4607b3d
Author: anatole <an...@apache.org>
Authored: Sun Feb 14 23:34:07 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sun Feb 14 23:34:07 2016 +0100
----------------------------------------------------------------------
.../internal/AdaptiveCombinationPolicy.java | 45 ++++++++++++--
.../internal/ArrayListConverter.java | 65 +++++++++++++++++++-
.../internal/CollectionConverter.java | 36 +++++++++++
.../collections/internal/HashMapConverter.java | 52 +++++++++++++++-
.../collections/internal/HashSetConverter.java | 46 +++++++++++++-
.../internal/LinkedListConverter.java | 33 +++++++++-
.../collections/internal/ListConverter.java | 36 +++++++++++
.../collections/internal/MapConverter.java | 36 +++++++++++
.../collections/internal/SetConverter.java | 36 +++++++++++
.../internal/SortedMapConverter.java | 37 +++++++++++
.../internal/SortedSetConverter.java | 36 +++++++++++
.../collections/internal/TreeMapConverter.java | 16 ++++-
.../collections/internal/TreeSetConverter.java | 43 ++++++++++++-
.../org.apache.tamaya.spi.PropertyConverter | 30 +++++++++
...he.tamaya.spi.PropertyValueCombinationPolicy | 19 ++++++
.../collections/CollectionsBaseTests.java | 29 +++++++++
.../META-INF/javaconfiguration.properties | 30 ++++-----
...he.tamaya.spi.PropertyValueCombinationPolicy | 19 ------
18 files changed, 588 insertions(+), 56 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/AdaptiveCombinationPolicy.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/AdaptiveCombinationPolicy.java b/collections/src/main/java/org/apache/tamaya/collections/internal/AdaptiveCombinationPolicy.java
index 113d817..9170eb3 100644
--- a/collections/src/main/java/org/apache/tamaya/collections/internal/AdaptiveCombinationPolicy.java
+++ b/collections/src/main/java/org/apache/tamaya/collections/internal/AdaptiveCombinationPolicy.java
@@ -20,9 +20,11 @@ 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.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
@@ -40,8 +42,8 @@ public class AdaptiveCombinationPolicy implements PropertyValueCombinationPolicy
private Map<Class, PropertyValueCombinationPolicy> configuredPolicies = new ConcurrentHashMap<>();
@Override
- public String collect(String currentValue, String key, PropertySource propertySource) {
- String adaptiveCombinationPolicyClass = ConfigurationProvider.getConfiguration().get(key+"{combinationPolicy}");
+ public Map<String,String> collect(Map<String,String> currentValue, String key, PropertySource propertySource){
+ String adaptiveCombinationPolicyClass = ConfigurationProvider.getConfiguration().get('_' + key+".combinationPolicy");
if(adaptiveCombinationPolicyClass!=null){
PropertyValueCombinationPolicy delegatePolicy = null;
try{
@@ -57,9 +59,44 @@ public class AdaptiveCombinationPolicy implements PropertyValueCombinationPolicy
LOG.log(Level.SEVERE, "Error loading configured PropertyValueCombinationPolicy for key: " + key, e);
}
}
- String newValue = propertySource.get(key);
+ // check for default collection combination policies for lists, sets, maps etc.
+ String collectionType = ConfigurationProvider.getConfiguration().get('_' + key+".collection-type");
+ if(collectionType!=null) {
+ if (collectionType.startsWith("java.util.")) {
+ collectionType = collectionType.substring("java.util.".length());
+ }
+ switch(collectionType){
+ case "List":
+ case "ArrayList":
+ case "LinkedList":
+ case "Collection":
+ case "Set":
+ case "HashSet":
+ case "TreeSet":
+ case "SortedSet":
+ case "Map":
+ case "HashMap":
+ case "ConcurrentHashMap":
+ case "TreeMap":
+ case "SortedMap":
+ PropertyValue newValue = propertySource.get(key);
+ if(newValue!=null){
+ Map<String,String> newMapValue = new HashMap<>(currentValue);
+ String oldVal = newMapValue.get(key);
+ if(oldVal!=null){
+ newMapValue.put(key,oldVal + ',' + newValue.getValue());
+ }
+ return newMapValue;
+ }else{
+ return newValue.getConfigEntries();
+ }
+ default:
+ LOG.log(Level.SEVERE, "Unsupported collection-type for key: " + key + ": " + collectionType);
+ }
+ }
+ PropertyValue newValue = propertySource.get(key);
if(newValue!=null){
- return newValue;
+ return newValue.getConfigEntries();
}
return currentValue;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/ArrayListConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/ArrayListConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/ArrayListConverter.java
index 0d7e6f3..4c6b06d 100644
--- a/collections/src/main/java/org/apache/tamaya/collections/internal/ArrayListConverter.java
+++ b/collections/src/main/java/org/apache/tamaya/collections/internal/ArrayListConverter.java
@@ -18,17 +18,76 @@
*/
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.LinkedList;
+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<?>> {
+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) {
+ public ArrayList convert(String value, ConversionContext context) {
+ List<String> rawList = split(value);
+ String converterClass = context.getConfiguration().get('_' + context.getKey()+".collection-valueParser");
+ if(converterClass!=null){
+ try {
+ PropertyConverter<?> valueConverter = (PropertyConverter<?>) Class.forName(converterClass).newInstance();
+ ArrayList<Object> mlist = new ArrayList<>();
+ ConversionContext ctx = new ConversionContext.Builder(context.getConfiguration(), context.getKey(),
+ TypeLiteral.of(context.getTargetType().getType())).build();
+ for(String raw:rawList){
+ Object convValue = valueConverter.convert(raw, ctx);
+ if(convValue!=null){
+ mlist.add(convValue);
+ continue;
+ }
+ }
+ return mlist;
+
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Error convertion config to ArrayList type.", e);
+ }
+ }
return null;
}
+
+ static List<String> split(String value) {
+ List<String> result = new ArrayList<>();
+ int start = 0;
+ int end = value.indexOf(',',start);
+ while(end>0) {
+ if (end>0 && (value.charAt(end - 1) != '\\')) {
+ result.add(value.substring(start, end));
+ start = end + 1;
+ end = value.indexOf(',',start);
+ }else{
+ end = value.indexOf(',',end + 1);
+ }
+ end = value.indexOf(',',start);
+ }
+ if(start < value.length()){
+ result.add(value.substring(start));
+ }
+ return result;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/CollectionConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/CollectionConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/CollectionConverter.java
new file mode 100644
index 0000000..80d65cd
--- /dev/null
+++ b/collections/src/main/java/org/apache/tamaya/collections/internal/CollectionConverter.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.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) {
+ return Collections.unmodifiableCollection(ArrayListConverter.getInstance().convert(value, context));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/HashMapConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/HashMapConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/HashMapConverter.java
index 917c31e..76ded4f 100644
--- a/collections/src/main/java/org/apache/tamaya/collections/internal/HashMapConverter.java
+++ b/collections/src/main/java/org/apache/tamaya/collections/internal/HashMapConverter.java
@@ -18,17 +18,63 @@
*/
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.TreeSet;
+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<?,?>> {
+public class HashMapConverter implements PropertyConverter<HashMap> {
+ private static final Logger LOG = Logger.getLogger(ArrayListConverter.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) {
+ public HashMap convert(String value, ConversionContext context) {
+ List<String> rawList = ArrayListConverter.split(value);
+ String converterClass = context.getConfiguration().get('_' + context.getKey()+".collection-valueParser");
+ if(converterClass!=null){
+ try {
+ PropertyConverter<?> valueConverter = (PropertyConverter<?>) Class.forName(converterClass).newInstance();
+ HashMap<String,Object> mlist = new HashMap<>();
+ ConversionContext ctx = new ConversionContext.Builder(context.getConfiguration(), context.getKey(),
+ TypeLiteral.of(context.getTargetType().getType())).build();
+ for(String raw:rawList){
+ String[] items = splitItems(raw);
+ Object convValue = valueConverter.convert(items[1], ctx);
+ if(convValue!=null){
+ mlist.put(items[0], convValue);
+ continue;
+ }
+ }
+ return mlist;
+
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Error convertion config to HashMap type.", e);
+ }
+ }
return null;
}
+
+ static String[] splitItems(String raw) {
+ String[] items = new String[2];
+ // check for '[]'
+ // else split with ':'
+ return raw.split("::");
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/HashSetConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/HashSetConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/HashSetConverter.java
index d41b6a2..2c402fb 100644
--- a/collections/src/main/java/org/apache/tamaya/collections/internal/HashSetConverter.java
+++ b/collections/src/main/java/org/apache/tamaya/collections/internal/HashSetConverter.java
@@ -18,16 +18,58 @@
*/
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<?>> {
+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) {
+ public HashSet convert(String value, ConversionContext context) {
+ List<String> rawList = ArrayListConverter.split(value);
+ String converterClass = context.getConfiguration().get('_' + context.getKey()+".collection-valueParser");
+ if(converterClass!=null){
+ try {
+ PropertyConverter<?> valueConverter = (PropertyConverter<?>) Class.forName(converterClass).newInstance();
+ HashSet<Object> mlist = new HashSet<>();
+ ConversionContext ctx = new ConversionContext.Builder(context.getConfiguration(), context.getKey(),
+ TypeLiteral.of(context.getTargetType().getType())).build();
+ for(String raw:rawList){
+ Object convValue = valueConverter.convert(raw, ctx);
+ if(convValue!=null){
+ mlist.add(convValue);
+ continue;
+ }
+ }
+ return mlist;
+
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Error convertion config to HashSet type.", e);
+ }
+ }
return null;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/LinkedListConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/LinkedListConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/LinkedListConverter.java
index aaca08d..d41211c 100644
--- a/collections/src/main/java/org/apache/tamaya/collections/internal/LinkedListConverter.java
+++ b/collections/src/main/java/org/apache/tamaya/collections/internal/LinkedListConverter.java
@@ -18,16 +18,45 @@
*/
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<?>> {
+public class LinkedListConverter implements PropertyConverter<LinkedList> {
+ private static final Logger LOG = Logger.getLogger(LinkedListConverter.class.getName());
+
@Override
- public LinkedList<?> convert(String value) {
+ public LinkedList convert(String value, ConversionContext context) {
+ List<String> rawList = ArrayListConverter.split(value);
+ String converterClass = context.getConfiguration().get('_' + context.getKey()+".collection-valueParser");
+ if(converterClass!=null){
+ try {
+ PropertyConverter<?> valueConverter = (PropertyConverter<?>) Class.forName(converterClass).newInstance();
+ LinkedList<Object> mlist = new LinkedList<>();
+ ConversionContext ctx = new ConversionContext.Builder(context.getConfiguration(), context.getKey(),
+ TypeLiteral.of(context.getTargetType().getType())).build();
+ for(String raw:rawList){
+ Object convValue = valueConverter.convert(raw, ctx);
+ if(convValue!=null){
+ mlist.add(convValue);
+ continue;
+ }
+ }
+ return mlist;
+
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Error convertion config to ArrayList type.", e);
+ }
+ }
return null;
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/ListConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/ListConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/ListConverter.java
new file mode 100644
index 0000000..2299bac
--- /dev/null
+++ b/collections/src/main/java/org/apache/tamaya/collections/internal/ListConverter.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.List;
+
+/**
+ * PropertyConverter for gnerating a LIST representation of values.
+ */
+public class ListConverter implements PropertyConverter<List> {
+
+ @Override
+ public List convert(String value, ConversionContext context) {
+ return Collections.unmodifiableList(ArrayListConverter.getInstance().convert(value, context));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/MapConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/MapConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/MapConverter.java
new file mode 100644
index 0000000..dcd2919
--- /dev/null
+++ b/collections/src/main/java/org/apache/tamaya/collections/internal/MapConverter.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.Map;
+
+/**
+ * PropertyConverter for gnerating HashMap representation of a values.
+ */
+public class MapConverter implements PropertyConverter<Map> {
+
+ @Override
+ public Map convert(String value, ConversionContext context) {
+ return Collections.unmodifiableMap(HashMapConverter.getInstance().convert(value, context));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/SetConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/SetConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/SetConverter.java
new file mode 100644
index 0000000..ddf19ad
--- /dev/null
+++ b/collections/src/main/java/org/apache/tamaya/collections/internal/SetConverter.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.Set;
+
+/**
+ * PropertyConverter for gnerating a LIST representation of values.
+ */
+public class SetConverter implements PropertyConverter<Set<?>> {
+
+ @Override
+ public Set convert(String value, ConversionContext context) {
+ return Collections.unmodifiableSet(HashSetConverter.getInstance().convert(value, context));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/SortedMapConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/SortedMapConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/SortedMapConverter.java
new file mode 100644
index 0000000..1015751
--- /dev/null
+++ b/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-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/SortedSetConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/SortedSetConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/SortedSetConverter.java
new file mode 100644
index 0000000..c0b8065
--- /dev/null
+++ b/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-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/TreeMapConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/TreeMapConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/TreeMapConverter.java
index 6e74d5c..08b92fd 100644
--- a/collections/src/main/java/org/apache/tamaya/collections/internal/TreeMapConverter.java
+++ b/collections/src/main/java/org/apache/tamaya/collections/internal/TreeMapConverter.java
@@ -18,17 +18,29 @@
*/
package org.apache.tamaya.collections.internal;
+import org.apache.tamaya.spi.ConversionContext;
import org.apache.tamaya.spi.PropertyConverter;
-import java.util.HashMap;
import java.util.TreeMap;
/**
* PropertyConverter for gnerating HashMap representation of a values.
*/
public class TreeMapConverter implements PropertyConverter<TreeMap<?,?>> {
+
+ /** 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) {
+ public TreeMap<?, ?> convert(String value, ConversionContext context) {
return null;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/TreeSetConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/TreeSetConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/TreeSetConverter.java
index 2797c91..fca00de 100644
--- a/collections/src/main/java/org/apache/tamaya/collections/internal/TreeSetConverter.java
+++ b/collections/src/main/java/org/apache/tamaya/collections/internal/TreeSetConverter.java
@@ -18,17 +18,56 @@
*/
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.HashSet;
+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) {
+ public TreeSet convert(String value, ConversionContext context) {
+ List<String> rawList = ArrayListConverter.split(value);
+ String converterClass = context.getConfiguration().get('_' + context.getKey()+".collection-valueParser");
+ if(converterClass!=null){
+ try {
+ PropertyConverter<?> valueConverter = (PropertyConverter<?>) Class.forName(converterClass).newInstance();
+ TreeSet<Object> mlist = new TreeSet<>();
+ ConversionContext ctx = new ConversionContext.Builder(context.getConfiguration(), context.getKey(),
+ TypeLiteral.of(context.getTargetType().getType())).build();
+ for(String raw:rawList){
+ Object convValue = valueConverter.convert(raw, ctx);
+ if(convValue!=null){
+ mlist.add(convValue);
+ continue;
+ }
+ }
+ return mlist;
+
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Error convertion config to HashSet type.", e);
+ }
+ }
return null;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/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
new file mode 100644
index 0000000..c4cf2ae
--- /dev/null
+++ b/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
@@ -0,0 +1,30 @@
+#
+# 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.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-sandbox/blob/8e237d9f/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy
----------------------------------------------------------------------
diff --git a/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy b/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy
new file mode 100644
index 0000000..6b7a67b
--- /dev/null
+++ b/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-sandbox/blob/8e237d9f/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
new file mode 100644
index 0000000..ca100ea
--- /dev/null
+++ b/collections/src/test/java/org/apache/tamaya/collections/CollectionsBaseTests.java
@@ -0,0 +1,29 @@
+package org.apache.tamaya.collections;
+
+import org.junit.Test;
+
+/**
+ * Created by atsticks on 14.02.16.
+ */
+public class CollectionsBaseTests {
+
+ @Test
+ public void testList_String(){
+
+ }
+
+ @Test
+ public void testSet_String(){
+
+ }
+
+ @Test
+ public void testMap_String(){
+
+ }
+
+ @Test
+ public void testCollection_String(){
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/test/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/collections/src/test/resources/META-INF/javaconfiguration.properties b/collections/src/test/resources/META-INF/javaconfiguration.properties
index 9848617..ca3c66e 100644
--- a/collections/src/test/resources/META-INF/javaconfiguration.properties
+++ b/collections/src/test/resources/META-INF/javaconfiguration.properties
@@ -18,34 +18,26 @@
#
# Similar to etcd all keys starting with a _ are hidden by default (only directly accessible).
-# Examples for collection syntax
+# Config for base tests (no combination policy)
+base.items=1,2,3,4,5,6,7,8,9,0
+base.map=1::a, 2::b, 3::c, [4:: ]
+# Config for tests with combination policy
list=a,b,c
_list.collection-type=List
-#list.{collection-combinationPolicy}=MyLeftAppendingCombinationPolicy
-
-arrayList=d;e;f
+arrayList=d,e,f
_arrayList.collection-type=java.util.ArrayList
-_arrayList.collection-separator=;
-#_arrayList.collection-valueParser=myParserClass
-
linkedList=g,h,i
_linkedList.collection-type=java.util.LinkedList
-
set=a,b,b
_set.collection-type=java.util.Set
-_set.eval-combinationPolicy=WarnOnDuplicates
-
sortedSet=a,c,b
_sortedSet.collection-type=java.util.TreeSet
-
-map=1:a,2:b,3:c
+map=1::a, 2::b, 3::c
_map.collection-type=Map
-#_map.collection-keyParser=myParserClass
-#_map.collection-valueParser=myParserClass
-
-sortedMap=|3:c||1:a||2:b|
-_sortedMap.collection-type=java.util.TreeMap
-
-concurrentMap=|3:c||1:a||2:b|
+sortedmap=[3 :: c], 1 :: a, 2 :: b
+_sortedmap.collection-type=SorteedMap
+treemap=[3 :: c], 1 :: a, 2 :: b
+_treemap.collection-type=java.util.TreeMap
+concurrentMap=[3::c], 1::a, key::value
_concurrentMap.collection-type=java.util.ConcurrentHashMap
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy
----------------------------------------------------------------------
diff --git a/collections/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy b/collections/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy
deleted file mode 100644
index 6b7a67b..0000000
--- a/collections/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy
+++ /dev/null
@@ -1,19 +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.internal.AdaptiveCombinationPolicy
\ No newline at end of file