brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/5] brooklyn-server git commit: Add typeCoercion (String->TimeZone; number->Date)
Date Fri, 10 Mar 2017 13:51:13 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 025a3d82d -> ea18d9ab0


Add typeCoercion (String->TimeZone; number->Date)

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

Branch: refs/heads/master
Commit: acfcb91c311c177670629b54bd9d70a843e95611
Parents: 59624f5
Author: Aled Sage <aled.sage@gmail.com>
Authored: Wed Mar 8 21:03:02 2017 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Wed Mar 8 23:45:40 2017 +0000

----------------------------------------------------------------------
 .../coerce/CommonAdaptorTypeCoercions.java       | 19 +++++++++++++++++++
 .../util/javalang/coerce/TypeCoercionsTest.java  | 13 +++++++++++++
 2 files changed, 32 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/acfcb91c/utils/common/src/main/java/org/apache/brooklyn/util/javalang/coerce/CommonAdaptorTypeCoercions.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/javalang/coerce/CommonAdaptorTypeCoercions.java
b/utils/common/src/main/java/org/apache/brooklyn/util/javalang/coerce/CommonAdaptorTypeCoercions.java
index 94c93e9..03745e6 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/javalang/coerce/CommonAdaptorTypeCoercions.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/javalang/coerce/CommonAdaptorTypeCoercions.java
@@ -28,6 +28,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.TimeZone;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 
@@ -258,6 +259,24 @@ public class CommonAdaptorTypeCoercions {
                 return QuorumChecks.of(input);
             }
         });
+        registerAdapter(String.class, TimeZone.class, new Function<String,TimeZone>()
{
+            @Override
+            public TimeZone apply(final String input) {
+                return TimeZone.getTimeZone(input);
+            }
+        });
+        registerAdapter(Long.class, Date.class, new Function<Long,Date>() {
+            @Override
+            public Date apply(final Long input) {
+                return new Date(input);
+            }
+        });
+        registerAdapter(Integer.class, Date.class, new Function<Integer,Date>() {
+            @Override
+            public Date apply(final Integer input) {
+                return new Date(input);
+            }
+        });
     }
     
     @SuppressWarnings("rawtypes")

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/acfcb91c/utils/common/src/test/java/org/apache/brooklyn/util/javalang/coerce/TypeCoercionsTest.java
----------------------------------------------------------------------
diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/coerce/TypeCoercionsTest.java
b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/coerce/TypeCoercionsTest.java
index 0492ac5..1a3d560 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/coerce/TypeCoercionsTest.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/coerce/TypeCoercionsTest.java
@@ -28,9 +28,11 @@ import java.net.URI;
 import java.net.URL;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.TimeZone;
 
 import org.apache.brooklyn.test.Asserts;
 import org.apache.brooklyn.util.collections.MutableSet;
@@ -168,6 +170,17 @@ public class TypeCoercionsTest {
     }
 
     @Test
+    public void testCoerceStringToTimeZone() {
+        assertEquals(coerce("UTC", TimeZone.class).getID(), TimeZone.getTimeZone("UTC").getID());
+    }
+
+    @Test
+    public void testCoerceNumberToDate() {
+        assertEquals(coerce(1000L, Date.class), new Date(1000));
+        assertEquals(coerce(1000, Date.class), new Date(1000));
+    }
+
+    @Test
     public void testCoerceStringToEnum() {
         assertEquals(coerce("LOWERCASE", PerverseEnum.class), PerverseEnum.lowercase);
         assertEquals(coerce("CAMELCASE", PerverseEnum.class), PerverseEnum.camelCase);


Mime
View raw message