tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ple...@apache.org
Subject [22/50] [abbrv] incubator-tamaya-sandbox git commit: Added test and fixes for collection support.
Date Tue, 06 Sep 2016 17:18:18 GMT
Added test and fixes 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/0d9afc23
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/0d9afc23
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/0d9afc23

Branch: refs/heads/master
Commit: 0d9afc2375d6d62710ebbae104d256b5f0a59274
Parents: 8e237d9
Author: anatole <anatole@apache.org>
Authored: Mon Feb 15 01:51:23 2016 +0100
Committer: anatole <anatole@apache.org>
Committed: Mon Feb 15 01:51:23 2016 +0100

----------------------------------------------------------------------
 .../internal/AdaptiveCombinationPolicy.java     |  7 +++++
 .../collections/internal/HashMapConverter.java  | 27 ++++++++++++++++----
 .../internal/LinkedListConverter.java           |  2 +-
 .../collections/internal/SetConverter.java      |  2 +-
 .../collections/internal/TreeMapConverter.java  |  6 ++---
 .../collections/internal/TreeSetConverter.java  |  4 +--
 6 files changed, 36 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/0d9afc23/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 9170eb3..161e874 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
@@ -43,6 +43,13 @@ public class AdaptiveCombinationPolicy implements PropertyValueCombinationPolicy
 
     @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().get('_'
+ key+".combinationPolicy");
         if(adaptiveCombinationPolicyClass!=null){
             PropertyValueCombinationPolicy delegatePolicy = null;

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/0d9afc23/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 76ded4f..8091dc6 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
@@ -24,6 +24,7 @@ import org.apache.tamaya.spi.PropertyConverter;
 
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -68,13 +69,29 @@ public class HashMapConverter implements PropertyConverter<HashMap>
{
                 LOG.log(Level.SEVERE, "Error convertion config to HashMap type.", e);
             }
         }
-        return null;
+        HashMap<String,String> result = new HashMap<>();
+        for(String raw:rawList){
+            String[] items = splitItems(raw);
+            if(items!=null){
+                result.put(items[0], items[1]);
+            }
+        }
+        return result;
     }
 
     static String[] splitItems(String raw) {
-        String[] items = new String[2];
-        // check for '[]'
-        // else split with ':'
-        return raw.split("::");
+        String[] items = raw.split("::");
+        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;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/0d9afc23/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 d41211c..f1c2514 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
@@ -56,7 +56,7 @@ public class LinkedListConverter implements PropertyConverter<LinkedList>
{
                 LOG.log(Level.SEVERE, "Error convertion config to ArrayList type.", e);
             }
         }
-        return null;
+        return new LinkedList(rawList);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/0d9afc23/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
index ddf19ad..27fdee9 100644
--- a/collections/src/main/java/org/apache/tamaya/collections/internal/SetConverter.java
+++ b/collections/src/main/java/org/apache/tamaya/collections/internal/SetConverter.java
@@ -27,7 +27,7 @@ import java.util.Set;
 /**
  *  PropertyConverter for gnerating a LIST representation of values.
  */
-public class SetConverter implements PropertyConverter<Set<?>> {
+public class SetConverter implements PropertyConverter<Set> {
 
     @Override
     public Set convert(String value, ConversionContext context) {

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/0d9afc23/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 08b92fd..b350944 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
@@ -26,7 +26,7 @@ import java.util.TreeMap;
 /**
  *  PropertyConverter for gnerating HashMap representation of a values.
  */
-public class TreeMapConverter implements PropertyConverter<TreeMap<?,?>> {
+public class TreeMapConverter implements PropertyConverter<TreeMap> {
 
     /** The shared instance, used by other collection converters in this package.*/
     private static TreeMapConverter INSTANCE = new TreeMapConverter();
@@ -40,7 +40,7 @@ public class TreeMapConverter implements PropertyConverter<TreeMap<?,?>>
{
     }
 
     @Override
-    public TreeMap<?, ?> convert(String value, ConversionContext context) {
-        return null;
+    public TreeMap convert(String value, ConversionContext context) {
+        return new TreeMap<>(HashMapConverter.getInstance().convert(value, context));
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/0d9afc23/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 fca00de..32fee83 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
@@ -30,7 +30,7 @@ import java.util.logging.Logger;
 /**
  *  PropertyConverter for gnerating HashSet representation of a values.
  */
-public class TreeSetConverter implements PropertyConverter<TreeSet<?>> {
+public class TreeSetConverter implements PropertyConverter<TreeSet> {
 
     private static final Logger LOG = Logger.getLogger(TreeSetConverter.class.getName());
 
@@ -68,6 +68,6 @@ public class TreeSetConverter implements PropertyConverter<TreeSet<?>>
{
                 LOG.log(Level.SEVERE, "Error convertion config to HashSet type.", e);
             }
         }
-        return null;
+        return new TreeSet<>(rawList);
     }
 }


Mime
View raw message