polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [31/50] [abbrv] zest-qi4j git commit: QI-318 Explicit Character/char support
Date Fri, 17 Apr 2015 16:05:51 GMT
QI-318 Explicit Character/char support


Project: http://git-wip-us.apache.org/repos/asf/zest-qi4j/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-qi4j/commit/85c1ca26
Tree: http://git-wip-us.apache.org/repos/asf/zest-qi4j/tree/85c1ca26
Diff: http://git-wip-us.apache.org/repos/asf/zest-qi4j/diff/85c1ca26

Branch: refs/heads/master
Commit: 85c1ca26a6b2ab58bf5fa31e046127003708236b
Parents: d6dc0c9
Author: Paul Merlin <paul@nosphere.org>
Authored: Sun Feb 17 01:43:21 2013 +0100
Committer: Paul Merlin <paul@nosphere.org>
Committed: Sun Feb 17 01:43:21 2013 +0100

----------------------------------------------------------------------
 core/api/src/docs/valuecomposite.txt            |  1 +
 .../org/qi4j/api/value/ValueDeserializer.java   |  1 +
 .../org/qi4j/api/value/ValueSerializer.java     |  1 +
 .../spi/value/ValueDeserializerAdapter.java     |  9 +++++++++
 .../qi4j/spi/value/ValueSerializerAdapter.java  |  2 ++
 .../AbstractCollectionSerializationTest.java    | 21 ++++++++++++++++++++
 .../AbstractPlainValueSerializationTest.java    | 10 ++++++++++
 7 files changed, 45 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/85c1ca26/core/api/src/docs/valuecomposite.txt
----------------------------------------------------------------------
diff --git a/core/api/src/docs/valuecomposite.txt b/core/api/src/docs/valuecomposite.txt
index 7536401..d5a0e05 100644
--- a/core/api/src/docs/valuecomposite.txt
+++ b/core/api/src/docs/valuecomposite.txt
@@ -51,6 +51,7 @@ EntityComposites and EntityReferences are serialized as their identity string.
 Plain Values can be one of :
 
     * String,
+    * Character or char,
     * Boolean or boolean,
     * Integer or int,
     * Long or long,

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/85c1ca26/core/api/src/main/java/org/qi4j/api/value/ValueDeserializer.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/qi4j/api/value/ValueDeserializer.java b/core/api/src/main/java/org/qi4j/api/value/ValueDeserializer.java
index b40c56a..d17657d 100644
--- a/core/api/src/main/java/org/qi4j/api/value/ValueDeserializer.java
+++ b/core/api/src/main/java/org/qi4j/api/value/ValueDeserializer.java
@@ -42,6 +42,7 @@ import org.qi4j.functional.Function2;
  * </p>
  * <ul>
  *     <li>String,</li>
+ *     <li>Character or char,</li>
  *     <li>Boolean or boolean,</li>
  *     <li>Integer or int,</li>
  *     <li>Long or long,</li>

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/85c1ca26/core/api/src/main/java/org/qi4j/api/value/ValueSerializer.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/qi4j/api/value/ValueSerializer.java b/core/api/src/main/java/org/qi4j/api/value/ValueSerializer.java
index a18f4db..3f68ffc 100644
--- a/core/api/src/main/java/org/qi4j/api/value/ValueSerializer.java
+++ b/core/api/src/main/java/org/qi4j/api/value/ValueSerializer.java
@@ -41,6 +41,7 @@ import org.qi4j.functional.Function;
  * </p>
  * <ul>
  *     <li>String,</li>
+ *     <li>Character or char,</li>
  *     <li>Boolean or boolean,</li>
  *     <li>Integer or int,</li>
  *     <li>Long or long,</li>

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/85c1ca26/core/spi/src/main/java/org/qi4j/spi/value/ValueDeserializerAdapter.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/qi4j/spi/value/ValueDeserializerAdapter.java b/core/spi/src/main/java/org/qi4j/spi/value/ValueDeserializerAdapter.java
index e5285fc..35dfcd8 100644
--- a/core/spi/src/main/java/org/qi4j/spi/value/ValueDeserializerAdapter.java
+++ b/core/spi/src/main/java/org/qi4j/spi/value/ValueDeserializerAdapter.java
@@ -71,6 +71,7 @@ import static org.qi4j.functional.Iterables.*;
  * </p>
  * <ul>
  *     <li>String,</li>
+ *     <li>Character or char,</li>
  *     <li>Boolean or boolean,</li>
  *     <li>Integer or int,</li>
  *     <li>Long or long,</li>
@@ -136,6 +137,14 @@ public abstract class ValueDeserializerAdapter<InputType, InputNodeType>
                 return input.toString();
             }
         } );
+        registerDeserializer( Character.class, new Function<Object, Character>()
+        {
+            @Override
+            public Character map( Object input )
+            {
+                return input.toString().charAt( 0 );
+            }
+        } );
         registerDeserializer( Boolean.class, new Function<Object, Boolean>()
         {
             @Override

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/85c1ca26/core/spi/src/main/java/org/qi4j/spi/value/ValueSerializerAdapter.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/qi4j/spi/value/ValueSerializerAdapter.java b/core/spi/src/main/java/org/qi4j/spi/value/ValueSerializerAdapter.java
index fbefa77..1fb9a91 100644
--- a/core/spi/src/main/java/org/qi4j/spi/value/ValueSerializerAdapter.java
+++ b/core/spi/src/main/java/org/qi4j/spi/value/ValueSerializerAdapter.java
@@ -61,6 +61,7 @@ import static org.qi4j.functional.Iterables.*;
  * </p>
  * <ul>
  *     <li>String,</li>
+ *     <li>Character or char,</li>
  *     <li>Boolean or boolean,</li>
  *     <li>Integer or int,</li>
  *     <li>Long or long,</li>
@@ -97,6 +98,7 @@ public abstract class ValueSerializerAdapter<OutputType>
     {
         // Primitive Value types
         registerSerializer( String.class, Functions.<Object, String>identity() );
+        registerSerializer( Character.class, Functions.<Object, Character>identity()
);
         registerSerializer( Boolean.class, Functions.<Object, Boolean>identity() );
         registerSerializer( Integer.class, Functions.<Object, Integer>identity() );
         registerSerializer( Long.class, Functions.<Object, Long>identity() );

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/85c1ca26/core/testsupport/src/main/java/org/qi4j/test/value/AbstractCollectionSerializationTest.java
----------------------------------------------------------------------
diff --git a/core/testsupport/src/main/java/org/qi4j/test/value/AbstractCollectionSerializationTest.java
b/core/testsupport/src/main/java/org/qi4j/test/value/AbstractCollectionSerializationTest.java
index 59f44cd..5c58c2a 100644
--- a/core/testsupport/src/main/java/org/qi4j/test/value/AbstractCollectionSerializationTest.java
+++ b/core/testsupport/src/main/java/org/qi4j/test/value/AbstractCollectionSerializationTest.java
@@ -133,6 +133,16 @@ public class AbstractCollectionSerializationTest
     }
 
     @Test
+    public void givenCollectionTypeWithCharacterAndNullElementWhenSerializingAndDeserializingExpectEquals()
+        throws Exception
+    {
+        String output = valueSerialization.serialize( characterCollection() );
+        CollectionType collectionType = new CollectionType( List.class, new ValueType( Character.class
) );
+        List<Character> list = valueSerialization.deserialize( collectionType, output
);
+        assertEquals( characterCollection(), list );
+    }
+
+    @Test
     public void givenCollectionTypeWithShortAndNullElementWhenSerializingAndDeserializingExpectEquals()
         throws Exception
     {
@@ -259,6 +269,17 @@ public class AbstractCollectionSerializationTest
         return value;
     }
 
+    private List<Character> characterCollection()
+    {
+        List<Character> value = new ArrayList<Character>();
+        value.add( 'Q' );
+        value.add( 'i' );
+        value.add( null );
+        value.add( '4' );
+        value.add( 'j' );
+        return value;
+    }
+
     private Collection<Short> shortCollection()
     {
         Collection<Short> value = new ArrayList<Short>();

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/85c1ca26/core/testsupport/src/main/java/org/qi4j/test/value/AbstractPlainValueSerializationTest.java
----------------------------------------------------------------------
diff --git a/core/testsupport/src/main/java/org/qi4j/test/value/AbstractPlainValueSerializationTest.java
b/core/testsupport/src/main/java/org/qi4j/test/value/AbstractPlainValueSerializationTest.java
index f4aca44..09ceb5a 100644
--- a/core/testsupport/src/main/java/org/qi4j/test/value/AbstractPlainValueSerializationTest.java
+++ b/core/testsupport/src/main/java/org/qi4j/test/value/AbstractPlainValueSerializationTest.java
@@ -50,6 +50,16 @@ public abstract class AbstractPlainValueSerializationTest
     protected ValueSerialization valueSerialization;
 
     @Test
+    public void givenCharacterValueWhenSerializingAndDeserializingExpectEquals()
+    {
+        String serialized = valueSerialization.serialize( 'q' );
+        assertThat( "Serialized", serialized, equalTo( "q" ) );
+
+        Character deserialized = valueSerialization.deserialize( Character.class, serialized
);
+        assertThat( "Deserialized", deserialized, equalTo( 'q' ) );
+    }
+
+    @Test
     public void givenEmptyStringValueWhenSerializingAndDeserializingExpectEquals()
     {
         String serialized = valueSerialization.serialize( "" );


Mime
View raw message