tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [3/5] incubator-tamaya git commit: Fixed duplicate converter in list returned.
Date Wed, 17 Feb 2016 00:21:08 GMT
Fixed duplicate converter in list returned.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/97f62557
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/97f62557
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/97f62557

Branch: refs/heads/master
Commit: 97f62557382598e4c19dfa967610c078eea40234
Parents: ce626a1
Author: anatole <anatole@apache.org>
Authored: Wed Feb 17 00:52:15 2016 +0100
Committer: anatole <anatole@apache.org>
Committed: Wed Feb 17 00:52:15 2016 +0100

----------------------------------------------------------------------
 .../core/internal/PropertyConverterManager.java | 44 ++++++++------------
 1 file changed, 17 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/97f62557/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
b/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
index 72facc4..2ec48b4 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
@@ -31,13 +31,7 @@ import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
@@ -227,35 +221,26 @@ public class PropertyConverterManager {
         // direct mapped converters
         try {
             readLock.lock();
-            converters = List.class.cast(this.converters.get(targetType));
+            addConvertersToList(List.class.cast(this.converters.get(targetType)), converterList);
         } finally {
             readLock.unlock();
         }
-        if (converters != null) {
-            converterList.addAll(converters);
-        }
         // transitive converter
         try {
             readLock.lock();
-            converters = List.class.cast(this.transitiveConverters.get(targetType));
+            addConvertersToList(List.class.cast(this.transitiveConverters.get(targetType)),
converterList);
         } finally {
             readLock.unlock();
         }
-        if (converters != null) {
-            converterList.addAll(converters);
-        }
         // handling of java.lang wrapper classes
         TypeLiteral<T> boxedType = mapBoxedType(targetType);
         if (boxedType != null) {
             try {
                 readLock.lock();
-                converters = List.class.cast(this.converters.get(boxedType));
+                addConvertersToList(List.class.cast(this.converters.get(boxedType)), converterList);
             } finally {
                 readLock.unlock();
             }
-            if (converters != null) {
-                converterList.addAll(converters);
-            }
         }
         if (converterList.isEmpty()) {
             // adding any converters created on the fly, e.g. for enum types.
@@ -264,31 +249,36 @@ public class PropertyConverterManager {
                 register(targetType, defaultConverter);
                 try {
                     readLock.lock();
-                    converters = List.class.cast(this.converters.get(targetType));
+                    addConvertersToList(List.class.cast(this.converters.get(targetType)),
converterList);
                 } finally {
                     readLock.unlock();
                 }
             }
-            if (converters != null) {
-                converterList.addAll(converters);
-            }
         }
         // check for parametrized types, ignoring param type
         // direct mapped converters
         if(targetType.getType()!=null) {
             try {
                 readLock.lock();
-                converters = List.class.cast(this.converters.get(TypeLiteral.of(targetType.getRawType())));
+                addConvertersToList(List.class.cast(this.converters.get(
+                        TypeLiteral.of(targetType.getRawType()))), converterList);
             } finally {
                 readLock.unlock();
             }
-            if (converters != null) {
-                converterList.addAll(converters);
-            }
         }
         return converterList;
     }
 
+    private <T> void addConvertersToList(Collection<PropertyConverter<T>>
converters, List<PropertyConverter<T>> converterList) {
+        if (converters != null) {
+            for(PropertyConverter<T> conv:converters) {
+                if(!converterList.contains(conv)) {
+                    converterList.add(conv);
+                }
+            }
+        }
+    }
+
     /**
      * Maps native types to the corresponding boxed types.
      *


Mime
View raw message