felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1799445 - in /felix/trunk/converter/converter/src: main/java/org/apache/felix/converter/impl/ConverterImpl.java test/java/org/apache/felix/converter/impl/ConverterTest.java
Date Wed, 21 Jun 2017 13:56:45 GMT
Author: davidb
Date: Wed Jun 21 13:56:45 2017
New Revision: 1799445

URL: http://svn.apache.org/viewvc?rev=1799445&view=rev
Log:
Felix Converter - additional conversions between characters and numbers

Modified:
    felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterImpl.java
    felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java

Modified: felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterImpl.java?rev=1799445&r1=1799444&r2=1799445&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterImpl.java
(original)
+++ felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterImpl.java
Wed Jun 21 13:56:45 2017
@@ -46,9 +46,13 @@ public class ConverterImpl implements In
         }) {});
         cb.rule(new Rule<Calendar,Long>(f -> f.getTime().getTime()) {});
         cb.rule(new Rule<Long,Calendar>(f -> new Calendar.Builder().setInstant(f).build())
{});
+
         cb.rule(new Rule<Character,Boolean>(c -> c.charValue() != 0) {});
         cb.rule(new Rule<Boolean,Character>(b -> b.booleanValue() ? (char) 1 : (char)
0) {});
+        cb.rule(new Rule<Character,Integer>(c -> (int) c.charValue()) {});
+        cb.rule(new Rule<Character,Long>(c -> (long) c.charValue()) {});
         cb.rule(new Rule<String,Character>(f -> f.length() > 0 ? f.charAt(0)
: 0) {});
+
         cb.rule(new Rule<String,Class<?>>(this::loadClassUnchecked) {});
         cb.rule(new Rule<Date,Long>(Date::getTime) {});
         cb.rule(new Rule<Long,Date>(f -> new Date(f)) {});

Modified: felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java?rev=1799445&r1=1799444&r2=1799445&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java
(original)
+++ felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java
Wed Jun 21 13:56:45 2017
@@ -114,10 +114,14 @@ public class ConverterTest {
         assertFalse(converter.convert(null).to(boolean.class));
         assertFalse(converter.convert(Collections.emptyList()).to(boolean.class));
 
-        // Converstions to integer
+        // Conversions to integer
         assertEquals(Integer.valueOf(123), converter.convert("123").to(int.class));
         assertEquals(1, (int) converter.convert(true).to(int.class));
         assertEquals(0, (int) converter.convert(false).to(int.class));
+        assertEquals(65, (int) converter.convert('A').to(int.class));
+
+        // Conversions to long
+        assertEquals(Long.valueOf(65), converter.convert('A').to(Long.class));
 
         // Conversions to Class
         assertEquals(BigDecimal.class, converter.convert("java.math.BigDecimal").to(Class.class));
@@ -129,6 +133,7 @@ public class ConverterTest {
         assertEquals('1', (char) converter.convert("123").to(Character.class));
         assertEquals('Q', (char) converter.convert(null).defaultValue('Q').to(Character.class));
         assertEquals((char) 123, (char) converter.convert(123L).to(Character.class));
+        assertEquals((char) 123, (char) converter.convert(123).to(Character.class));
         assertEquals(Byte.valueOf((byte) 123), converter.convert("123").to(Byte.class));
         assertEquals(Float.valueOf("12.3"), converter.convert("12.3").to(Float.class));
         assertEquals(Double.valueOf("12.3"), converter.convert("12.3").to(Double.class));



Mime
View raw message