commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r905156 - in /commons/proper/lang/branches/LANG_2_X/src: main/java/org/apache/commons/lang/mutable/ test/java/org/apache/commons/lang/mutable/
Date Mon, 01 Feb 2010 00:29:33 GMT
Author: niallp
Date: Mon Feb  1 00:29:32 2010
New Revision: 905156

URL: http://svn.apache.org/viewvc?rev=905156&view=rev
Log:
Port LANG-522 to 2.x branch - add string constructors to mutable numbers

Modified:
    commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableByte.java
    commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableDouble.java
    commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableFloat.java
    commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableInt.java
    commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableLong.java
    commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableShort.java
    commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableByteTest.java
    commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableDoubleTest.java
    commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableFloatTest.java
    commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableIntTest.java
    commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableLongTest.java
    commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableShortTest.java

Modified: commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableByte.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableByte.java?rev=905156&r1=905155&r2=905156&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableByte.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableByte.java
Mon Feb  1 00:29:32 2010
@@ -63,6 +63,17 @@
         this.value = value.byteValue();
     }
 
+    /**
+     * Constructs a new MutableByte parsing the given string.
+     * 
+     * @param value  the string to parse, not null
+     * @throws NumberFormatException if the string cannot be parsed into a byte
+     */
+    public MutableByte(String value) throws NumberFormatException {
+        super();
+        this.value = Byte.parseByte(value);
+    }
+
     //-----------------------------------------------------------------------
     /**
      * Gets the value as a Byte instance.

Modified: commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableDouble.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableDouble.java?rev=905156&r1=905155&r2=905156&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableDouble.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableDouble.java
Mon Feb  1 00:29:32 2010
@@ -65,6 +65,17 @@
         this.value = value.doubleValue();
     }
 
+    /**
+     * Constructs a new MutableDouble parsing the given string.
+     * 
+     * @param value  the string to parse, not null
+     * @throws NumberFormatException if the string cannot be parsed into a double
+     */
+    public MutableDouble(String value) throws NumberFormatException {
+        super();
+        this.value = Double.parseDouble(value);
+    }
+
     //-----------------------------------------------------------------------
     /**
      * Gets the value as a Double instance.

Modified: commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableFloat.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableFloat.java?rev=905156&r1=905155&r2=905156&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableFloat.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableFloat.java
Mon Feb  1 00:29:32 2010
@@ -65,6 +65,17 @@
         this.value = value.floatValue();
     }
 
+    /**
+     * Constructs a new MutableFloat parsing the given string.
+     * 
+     * @param value  the string to parse, not null
+     * @throws NumberFormatException if the string cannot be parsed into a float
+     */
+    public MutableFloat(String value) throws NumberFormatException {
+        super();
+        this.value = Float.parseFloat(value);
+    }
+
     //-----------------------------------------------------------------------
     /**
      * Gets the value as a Float instance.

Modified: commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableInt.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableInt.java?rev=905156&r1=905155&r2=905156&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableInt.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableInt.java
Mon Feb  1 00:29:32 2010
@@ -63,6 +63,17 @@
         this.value = value.intValue();
     }
 
+    /**
+     * Constructs a new MutableInt parsing the given string.
+     * 
+     * @param value  the string to parse, not null
+     * @throws NumberFormatException if the string cannot be parsed into an int
+     */
+    public MutableInt(String value) throws NumberFormatException {
+        super();
+        this.value = Integer.parseInt(value);
+    }
+
     //-----------------------------------------------------------------------
     /**
      * Gets the value as a Integer instance.

Modified: commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableLong.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableLong.java?rev=905156&r1=905155&r2=905156&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableLong.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableLong.java
Mon Feb  1 00:29:32 2010
@@ -63,6 +63,17 @@
         this.value = value.longValue();
     }
 
+    /**
+     * Constructs a new MutableLong parsing the given string.
+     * 
+     * @param value  the string to parse, not null
+     * @throws NumberFormatException if the string cannot be parsed into a long
+     */
+    public MutableLong(String value) throws NumberFormatException {
+        super();
+        this.value = Long.parseLong(value);
+    }
+
     //-----------------------------------------------------------------------
     /**
      * Gets the value as a Long instance.

Modified: commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableShort.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableShort.java?rev=905156&r1=905155&r2=905156&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableShort.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/mutable/MutableShort.java
Mon Feb  1 00:29:32 2010
@@ -63,6 +63,17 @@
         this.value = value.shortValue();
     }
 
+    /**
+     * Constructs a new MutableShort parsing the given string.
+     * 
+     * @param value  the string to parse, not null
+     * @throws NumberFormatException if the string cannot be parsed into a short
+     */
+    public MutableShort(String value) throws NumberFormatException {
+        super();
+        this.value = Short.parseShort(value);
+    }
+
     //-----------------------------------------------------------------------
     /**
      * Gets the value as a Short instance.

Modified: commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableByteTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableByteTest.java?rev=905156&r1=905155&r2=905156&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableByteTest.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableByteTest.java
Mon Feb  1 00:29:32 2010
@@ -49,8 +49,11 @@
         
         assertEquals((byte) 2, new MutableByte(new Byte((byte) 2)).byteValue());
         assertEquals((byte) 3, new MutableByte(new MutableByte((byte) 3)).byteValue());
+
+        assertEquals((byte) 2, new MutableByte("2").byteValue());
+
         try {
-            new MutableByte(null);
+            new MutableByte((Number)null);
             fail();
         } catch (NullPointerException ex) {}
     }

Modified: commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableDoubleTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableDoubleTest.java?rev=905156&r1=905155&r2=905156&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableDoubleTest.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableDoubleTest.java
Mon Feb  1 00:29:32 2010
@@ -49,8 +49,11 @@
         
         assertEquals(2d, new MutableDouble(new Double(2d)).doubleValue(), 0.0001d);
         assertEquals(3d, new MutableDouble(new MutableDouble(3d)).doubleValue(), 0.0001d);
+        
+        assertEquals(2d, new MutableDouble("2.0").doubleValue(), 0.0001d);
+
         try {
-            new MutableDouble(null);
+            new MutableDouble((Number)null);
             fail();
         } catch (NullPointerException ex) {}
     }

Modified: commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableFloatTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableFloatTest.java?rev=905156&r1=905155&r2=905156&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableFloatTest.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableFloatTest.java
Mon Feb  1 00:29:32 2010
@@ -49,8 +49,11 @@
         
         assertEquals(2f, new MutableFloat(new Float(2f)).floatValue(), 0.0001f);
         assertEquals(3f, new MutableFloat(new MutableFloat(3f)).floatValue(), 0.0001f);
+
+        assertEquals(2f, new MutableDouble("2.0").floatValue(), 0.0001f);
+
         try {
-            new MutableFloat(null);
+            new MutableFloat((Number)null);
             fail();
         } catch (NullPointerException ex) {}
     }

Modified: commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableIntTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableIntTest.java?rev=905156&r1=905155&r2=905156&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableIntTest.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableIntTest.java
Mon Feb  1 00:29:32 2010
@@ -49,8 +49,11 @@
         
         assertEquals(2, new MutableInt(new Integer(2)).intValue());
         assertEquals(3, new MutableInt(new MutableLong(3)).intValue());
+
+        assertEquals(2, new MutableInt("2").intValue());
+
         try {
-            new MutableInt(null);
+            new MutableInt((Number)null);
             fail();
         } catch (NullPointerException ex) {}
     }

Modified: commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableLongTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableLongTest.java?rev=905156&r1=905155&r2=905156&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableLongTest.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableLongTest.java
Mon Feb  1 00:29:32 2010
@@ -49,8 +49,11 @@
         
         assertEquals(2, new MutableLong(new Long(2)).longValue());
         assertEquals(3, new MutableLong(new MutableLong(3)).longValue());
+
+        assertEquals(2, new MutableLong("2").longValue());
+
         try {
-            new MutableLong(null);
+            new MutableLong((Number)null);
             fail();
         } catch (NullPointerException ex) {}
     }

Modified: commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableShortTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableShortTest.java?rev=905156&r1=905155&r2=905156&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableShortTest.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/mutable/MutableShortTest.java
Mon Feb  1 00:29:32 2010
@@ -49,8 +49,11 @@
         
         assertEquals((short) 2, new MutableShort(new Short((short) 2)).shortValue());
         assertEquals((short) 3, new MutableShort(new MutableShort((short) 3)).shortValue());
+
+        assertEquals((short) 2, new MutableShort("2").shortValue());
+
         try {
-            new MutableShort(null);
+            new MutableShort((Number)null);
             fail();
         } catch (NullPointerException ex) {}
     }



Mime
View raw message