brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grk...@apache.org
Subject [11/13] git commit: Change coerced collection type and make mutable again
Date Sun, 05 Oct 2014 22:44:35 GMT
Change coerced collection type and make mutable again


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

Branch: refs/heads/master
Commit: a2de479c176e467bc79ed806a8eb17397a0aa022
Parents: af5c831
Author: Andrew Kennedy <grkvlt@apache.org>
Authored: Sat Sep 27 17:05:34 2014 +0100
Committer: Andrew Kennedy <grkvlt@apache.org>
Committed: Sun Oct 5 19:45:54 2014 +0100

----------------------------------------------------------------------
 .../brooklyn/event/basic/BasicConfigKey.java    |  2 +-
 .../java/brooklyn/util/flags/TypeCoercions.java | 24 +++++++-------------
 2 files changed, 9 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a2de479c/core/src/main/java/brooklyn/event/basic/BasicConfigKey.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/event/basic/BasicConfigKey.java b/core/src/main/java/brooklyn/event/basic/BasicConfigKey.java
index c511134..86250fd 100644
--- a/core/src/main/java/brooklyn/event/basic/BasicConfigKey.java
+++ b/core/src/main/java/brooklyn/event/basic/BasicConfigKey.java
@@ -214,7 +214,7 @@ public class BasicConfigKey<T> implements ConfigKeySelfExtracting<T>,
Serializab
     }
     
     protected Object resolveValue(Object v, ExecutionContext exec) throws ExecutionException,
InterruptedException {
-        if (v instanceof Iterable || v instanceof Map) {
+        if (v instanceof Collection || v instanceof Map) {
             return Tasks.resolveDeepValue(v, Object.class, exec, "config "+name);
         } else {
             return Tasks.resolveValue(v, getType(), exec, "config "+name);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a2de479c/core/src/main/java/brooklyn/util/flags/TypeCoercions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/flags/TypeCoercions.java b/core/src/main/java/brooklyn/util/flags/TypeCoercions.java
index e4bb5c2..f3caeaf 100644
--- a/core/src/main/java/brooklyn/util/flags/TypeCoercions.java
+++ b/core/src/main/java/brooklyn/util/flags/TypeCoercions.java
@@ -69,7 +69,6 @@ import com.google.common.base.Predicate;
 import com.google.common.collect.HashBasedTable;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
@@ -124,7 +123,7 @@ public class TypeCoercions {
 
         //recursive coercion of parameterized collections and map entries
         if (targetTypeToken.getType() instanceof ParameterizedType) {
-            if (value instanceof Iterable && Collection.class.isAssignableFrom(targetType))
{
+            if (value instanceof Collection && Collection.class.isAssignableFrom(targetType))
{
                 Type[] arguments = ((ParameterizedType) targetTypeToken.getType()).getActualTypeArguments();
                 if (arguments.length != 1) {
                     throw new IllegalStateException("Unexpected number of parameters in collection
type: " + arguments);
@@ -135,9 +134,9 @@ public class TypeCoercions {
                     coerced.add(coerce(entry, listEntryType));
                 }
                 if (Set.class.isAssignableFrom(targetType)) {
-                    return (T) ImmutableSet.copyOf(coerced);
+                    return (T) Sets.newLinkedHashSet(coerced);
                 } else {
-                    return (T) ImmutableList.copyOf(coerced);
+                    return (T) Lists.newArrayList(coerced);
                 }
             } else if (value instanceof Map && Map.class.isAssignableFrom(targetType))
{
                 Type[] arguments = ((ParameterizedType) targetTypeToken.getType()).getActualTypeArguments();
@@ -150,7 +149,7 @@ public class TypeCoercions {
                 for (Map.Entry entry : ((Map<?,?>) value).entrySet()) {
                     coerced.put(coerce(entry.getKey(), mapKeyType),  coerce(entry.getValue(),
mapValueType));
                 }
-                return (T) ImmutableMap.copyOf(coerced);
+                return (T) Maps.newLinkedHashMap(coerced);
             }
         }
 
@@ -477,24 +476,17 @@ public class TypeCoercions {
                 return new String(input);
             }
         });
-        registerAdapter(Iterable.class, Set.class, new Function<Iterable,Set>() {
+        registerAdapter(Collection.class, Set.class, new Function<Collection,Set>()
{
             @SuppressWarnings("unchecked")
             @Override
-            public Set apply(Iterable input) {
+            public Set apply(Collection input) {
                 return Sets.newLinkedHashSet(input);
             }
         });
-        registerAdapter(Iterable.class, List.class, new Function<Iterable,List>() {
+        registerAdapter(Collection.class, List.class, new Function<Collection,List>()
{
             @SuppressWarnings("unchecked")
             @Override
-            public List apply(Iterable input) {
-                return Lists.newArrayList(input);
-            }
-        });
-        registerAdapter(Iterable.class, Collection.class, new Function<Iterable,Collection>()
{
-            @SuppressWarnings("unchecked")
-            @Override
-            public Collection apply(Iterable input) {
+            public List apply(Collection input) {
                 return Lists.newArrayList(input);
             }
         });


Mime
View raw message