You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gn...@apache.org on 2017/09/08 09:23:10 UTC
svn commit: r1807697 - in /felix/trunk/utils/src:
main/java/org/apache/felix/utils/properties/ConfigurationHandler.java
test/java/org/apache/felix/utils/properties/TypedPropertiesTest.java
Author: gnodet
Date: Fri Sep 8 09:23:09 2017
New Revision: 1807697
URL: http://svn.apache.org/viewvc?rev=1807697&view=rev
Log:
[FELIX-5306] User friendly syntax for floats and doubles in FileInstall
Modified:
felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/ConfigurationHandler.java
felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/TypedPropertiesTest.java
Modified: felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/ConfigurationHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/ConfigurationHandler.java?rev=1807697&r1=1807696&r2=1807697&view=diff
==============================================================================
--- felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/ConfigurationHandler.java (original)
+++ felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/ConfigurationHandler.java Fri Sep 8 09:23:09 2017
@@ -479,13 +479,19 @@ public class ConfigurationHandler
case TOKEN_SIMPLE_FLOAT:
case TOKEN_PRIMITIVE_FLOAT:
- int fBits = Integer.parseInt( readQuoted( pr ) );
- return new Float( Float.intBitsToFloat( fBits ) );
+ String fString = readQuoted( pr );
+ if ( fString.indexOf('.') >= 0 )
+ return Float.valueOf( fString );
+ else
+ return Float.intBitsToFloat( Integer.parseInt( fString ) );
case TOKEN_SIMPLE_DOUBLE:
case TOKEN_PRIMITIVE_DOUBLE:
- long dBits = Long.parseLong( readQuoted( pr ) );
- return new Double( Double.longBitsToDouble( dBits ) );
+ String dString = readQuoted( pr );
+ if (dString.indexOf('.') >= 0 )
+ return Double.valueOf( dString );
+ else
+ return Double.longBitsToDouble( Long.parseLong( dString ) );
case TOKEN_SIMPLE_BYTE:
case TOKEN_PRIMITIVE_BYTE:
@@ -801,17 +807,6 @@ public class ConfigurationHandler
private static void writeSimple( Writer out, Object value ) throws IOException
{
- if ( value instanceof Double )
- {
- double dVal = ( ( Double ) value ).doubleValue();
- value = new Long( Double.doubleToRawLongBits( dVal ) );
- }
- else if ( value instanceof Float )
- {
- float fVal = ( ( Float ) value ).floatValue();
- value = new Integer( Float.floatToRawIntBits( fVal ) );
- }
-
out.write( TOKEN_VAL_OPEN );
writeQuoted( out, String.valueOf( value ) );
out.write( TOKEN_VAL_CLOS );
Modified: felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/TypedPropertiesTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/TypedPropertiesTest.java?rev=1807697&r1=1807696&r2=1807697&view=diff
==============================================================================
--- felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/TypedPropertiesTest.java (original)
+++ felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/TypedPropertiesTest.java Fri Sep 8 09:23:09 2017
@@ -94,10 +94,20 @@ public class TypedPropertiesTest extends
public void testWriteTypedPropsFloat() throws IOException
{
TypedProperties properties = new TypedProperties();
+ properties.load(new StringReader("key = F\"1137191584\"\n"));
+ assertEquals(400.333f, properties.get("key"));
+ }
+
+ public void testWriteTypedPropsFloat2() throws IOException
+ {
+ TypedProperties properties = new TypedProperties();
properties.put("key", 400.333f);
StringWriter sw = new StringWriter();
properties.save(sw);
- assertEquals("key = F\"1137191584\"\n", sw.toString());
+ assertEquals("key = F\"400.333\"\n", sw.toString());
+ properties = new TypedProperties();
+ properties.load(new StringReader(sw.toString()));
+ assertEquals(400.333f, properties.get("key"));
}
public void testSubstitution() throws IOException