commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1153488 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/math/ main/java/org/apache/commons/lang3/mutable/ test/java/org/apache/commons/lang3/ test/java/org/apache/commons/lang3/mutable/
Date Wed, 03 Aug 2011 13:47:50 GMT
Author: ggregory
Date: Wed Aug  3 13:47:49 2011
New Revision: 1153488

URL: http://svn.apache.org/viewvc?rev=1153488&view=rev
Log:
Use more efficient Short cache: Use "Short.valueOf(int)" instead of "new Short(short)"

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/mutable/MutableShort.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/mutable/MutableShortTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java?rev=1153488&r1=1153487&r2=1153488&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
Wed Aug  3 13:47:49 2011
@@ -42,11 +42,11 @@ public class NumberUtils {
     /** Reusable Integer constant for minus one. */
     public static final Integer INTEGER_MINUS_ONE = Integer.valueOf(-1);
     /** Reusable Short constant for zero. */
-    public static final Short SHORT_ZERO = new Short((short) 0);
+    public static final Short SHORT_ZERO = Short.valueOf((short) 0);
     /** Reusable Short constant for one. */
-    public static final Short SHORT_ONE = new Short((short) 1);
+    public static final Short SHORT_ONE = Short.valueOf((short) 1);
     /** Reusable Short constant for minus one. */
-    public static final Short SHORT_MINUS_ONE = new Short((short) -1);
+    public static final Short SHORT_MINUS_ONE = Short.valueOf((short) -1);
     /** Reusable Byte constant for zero. */
     public static final Byte BYTE_ZERO = Byte.valueOf((byte) 0);
     /** Reusable Byte constant for one. */
@@ -404,7 +404,7 @@ public class NumberUtils {
     // Long.getLong(String,Integer)
     // Long.valueOf(String,int)
     // Long.valueOf(String)
-    // new Short(String)
+    // Short.valueOf(String)
     // Short.decode(String)
     // Short.valueOf(String,int)
     // Short.valueOf(String)

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/mutable/MutableShort.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/mutable/MutableShort.java?rev=1153488&r1=1153487&r2=1153488&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/mutable/MutableShort.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/mutable/MutableShort.java
Wed Aug  3 13:47:49 2011
@@ -82,7 +82,7 @@ public class MutableShort extends Number
      * @return the value as a Short, never null
      */
     public Short getValue() {
-        return new Short(this.value);
+        return Short.valueOf(this.value);
     }
 
     /**

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java?rev=1153488&r1=1153487&r2=1153488&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java Wed
Aug  3 13:47:49 2011
@@ -2438,12 +2438,12 @@ public class ArrayUtilsTest extends Test
         
         assertTrue(Arrays.equals(
             new short[] {Short.MIN_VALUE, Short.MAX_VALUE, (short)9999999},
-            ArrayUtils.toPrimitive(new Short[] {new Short(Short.MIN_VALUE), 
-                new Short(Short.MAX_VALUE), new Short((short)9999999)}))
+            ArrayUtils.toPrimitive(new Short[] {Short.valueOf(Short.MIN_VALUE), 
+                Short.valueOf(Short.MAX_VALUE), Short.valueOf((short)9999999)}))
         );
 
         try {
-            ArrayUtils.toPrimitive(new Short[] {new Short(Short.MIN_VALUE), null});
+            ArrayUtils.toPrimitive(new Short[] {Short.valueOf(Short.MIN_VALUE), null});
             fail();
         } catch (NullPointerException ex) {}
     }
@@ -2457,14 +2457,14 @@ public class ArrayUtilsTest extends Test
         
         assertTrue(Arrays.equals(
             new short[] {Short.MIN_VALUE, Short.MAX_VALUE, (short)9999999},
-            ArrayUtils.toPrimitive(new Short[] {new Short(Short.MIN_VALUE), 
-                new Short(Short.MAX_VALUE), new Short((short)9999999)}, Short.MIN_VALUE))
+            ArrayUtils.toPrimitive(new Short[] {Short.valueOf(Short.MIN_VALUE), 
+                Short.valueOf(Short.MAX_VALUE), Short.valueOf((short)9999999)}, Short.MIN_VALUE))
         );
         
         assertTrue(Arrays.equals(
             new short[] {Short.MIN_VALUE, Short.MAX_VALUE, (short)9999999},
-            ArrayUtils.toPrimitive(new Short[] {new Short(Short.MIN_VALUE), null, 
-                new Short((short)9999999)}, Short.MAX_VALUE))
+            ArrayUtils.toPrimitive(new Short[] {Short.valueOf(Short.MIN_VALUE), null, 
+                Short.valueOf((short)9999999)}, Short.MAX_VALUE))
         );
     }
 
@@ -2476,8 +2476,8 @@ public class ArrayUtilsTest extends Test
         ArrayUtils.toObject(new short[0]));
         
         assertTrue(Arrays.equals(
-            new Short[] {new Short(Short.MIN_VALUE), new Short(Short.MAX_VALUE), 
-                new Short((short)9999999)},
+            new Short[] {Short.valueOf(Short.MIN_VALUE), Short.valueOf(Short.MAX_VALUE),

+                Short.valueOf((short)9999999)},
             ArrayUtils.toObject(new short[] {Short.MIN_VALUE, Short.MAX_VALUE, 
                 (short)9999999}))
         );

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/mutable/MutableShortTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/mutable/MutableShortTest.java?rev=1153488&r1=1153487&r2=1153488&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/mutable/MutableShortTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/mutable/MutableShortTest.java
Wed Aug  3 13:47:49 2011
@@ -36,7 +36,7 @@ public class MutableShortTest extends Te
         
         assertEquals((short) 1, new MutableShort((short) 1).shortValue());
         
-        assertEquals((short) 2, new MutableShort(new Short((short) 2)).shortValue());
+        assertEquals((short) 2, new MutableShort(Short.valueOf((short) 2)).shortValue());
         assertEquals((short) 3, new MutableShort(new MutableShort((short) 3)).shortValue());
 
         assertEquals((short) 2, new MutableShort("2").shortValue());
@@ -50,19 +50,19 @@ public class MutableShortTest extends Te
     public void testGetSet() {
         final MutableShort mutNum = new MutableShort((short) 0);
         assertEquals((short) 0, new MutableShort().shortValue());
-        assertEquals(new Short((short) 0), new MutableShort().getValue());
+        assertEquals(Short.valueOf((short) 0), new MutableShort().getValue());
         
         mutNum.setValue((short) 1);
         assertEquals((short) 1, mutNum.shortValue());
-        assertEquals(new Short((short) 1), mutNum.getValue());
+        assertEquals(Short.valueOf((short) 1), mutNum.getValue());
         
-        mutNum.setValue(new Short((short) 2));
+        mutNum.setValue(Short.valueOf((short) 2));
         assertEquals((short) 2, mutNum.shortValue());
-        assertEquals(new Short((short) 2), mutNum.getValue());
+        assertEquals(Short.valueOf((short) 2), mutNum.getValue());
         
         mutNum.setValue(new MutableShort((short) 3));
         assertEquals((short) 3, mutNum.shortValue());
-        assertEquals(new Short((short) 3), mutNum.getValue());
+        assertEquals(Short.valueOf((short) 3), mutNum.getValue());
         try {
             mutNum.setValue(null);
             fail();
@@ -82,7 +82,7 @@ public class MutableShortTest extends Te
         assertEquals(false, mutNumB.equals(mutNumC));
         assertEquals(true, mutNumC.equals(mutNumC));
         assertEquals(false, mutNumA.equals(null));
-        assertEquals(false, mutNumA.equals(new Short((short) 0)));
+        assertEquals(false, mutNumA.equals(Short.valueOf((short) 0)));
         assertEquals(false, mutNumA.equals("0"));
     }
 
@@ -94,7 +94,7 @@ public class MutableShortTest extends Te
         assertEquals(true, mutNumA.hashCode() == mutNumA.hashCode());
         assertEquals(true, mutNumA.hashCode() == mutNumB.hashCode());
         assertEquals(false, mutNumA.hashCode() == mutNumC.hashCode());
-        assertEquals(true, mutNumA.hashCode() == new Short((short) 0).hashCode());
+        assertEquals(true, mutNumA.hashCode() == Short.valueOf((short) 0).hashCode());
     }
 
     public void testCompareTo() {
@@ -121,8 +121,8 @@ public class MutableShortTest extends Te
     }
 
     public void testToShort() {
-        assertEquals(new Short((short) 0), new MutableShort((short) 0).toShort());
-        assertEquals(new Short((short) 123), new MutableShort((short) 123).toShort());
+        assertEquals(Short.valueOf((short) 0), new MutableShort((short) 0).toShort());
+        assertEquals(Short.valueOf((short) 123), new MutableShort((short) 123).toShort());
     }
 
     public void testIncrement() {
@@ -150,7 +150,7 @@ public class MutableShortTest extends Te
 
     public void testAddValueObject() {
         MutableShort mutNum = new MutableShort((short) 1);
-        mutNum.add(new Short((short) 1));
+        mutNum.add(Short.valueOf((short) 1));
         
         assertEquals((short) 2, mutNum.shortValue());
     }
@@ -164,7 +164,7 @@ public class MutableShortTest extends Te
 
     public void testSubtractValueObject() {
         MutableShort mutNum = new MutableShort((short) 1);
-        mutNum.subtract(new Short((short) 1));
+        mutNum.subtract(Short.valueOf((short) 1));
         
         assertEquals((short) 0, mutNum.shortValue());
     }



Mime
View raw message