commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r754804 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang/ java/org/apache/commons/lang/mutable/ test/org/apache/commons/lang/ test/org/apache/commons/lang/math/ test/org/apache/commons/lang/mutable/
Date Mon, 16 Mar 2009 02:06:19 GMT
Author: sebb
Date: Mon Mar 16 02:06:18 2009
New Revision: 754804

URL: http://svn.apache.org/viewvc?rev=754804&view=rev
Log:
Byte.valueOf() is definitely faster than new Byte()

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/ArrayUtils.java
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableByte.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/ArrayUtilsTest.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/RangeTest.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableByteTest.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/ArrayUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/ArrayUtils.java?rev=754804&r1=754803&r2=754804&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/ArrayUtils.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/ArrayUtils.java Mon Mar 16
02:06:18 2009
@@ -2603,7 +2603,7 @@
         }
         final Byte[] result = new Byte[array.length];
         for (int i = 0; i < array.length; i++) {
-            result[i] = new Byte(array[i]);
+            result[i] = Byte.valueOf(array[i]);
         }
         return result;
     }  
@@ -3601,7 +3601,7 @@
      * (index < 0 || index > array.length).
      */
     public static byte[] add(byte[] array, int index, byte element) {
-        return (byte[]) add(array, index, new Byte(element), Byte.TYPE);
+        return (byte[]) add(array, index, Byte.valueOf(element), Byte.TYPE);
     }
     
     /**

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableByte.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableByte.java?rev=754804&r1=754803&r2=754804&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableByte.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableByte.java Mon
Mar 16 02:06:18 2009
@@ -73,7 +73,7 @@
      * @return the value as a Byte
      */
     public Object getValue() {
-        return new Byte(this.value);
+        return Byte.valueOf(this.value);
     }
 
     /**
@@ -159,7 +159,7 @@
      * @return a Byte instance containing the value from this mutable
      */
     public Byte toByte() {
-        return new Byte(byteValue());
+        return Byte.valueOf(byteValue());
     }
 
     //-----------------------------------------------------------------------

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/ArrayUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/ArrayUtilsTest.java?rev=754804&r1=754803&r2=754804&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/ArrayUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/ArrayUtilsTest.java Mon Mar
16 02:06:18 2009
@@ -2108,12 +2108,12 @@
         
         assertTrue(Arrays.equals(
             new byte[] {Byte.MIN_VALUE, Byte.MAX_VALUE, (byte)9999999},
-            ArrayUtils.toPrimitive(new Byte[] {new Byte(Byte.MIN_VALUE), 
-                new Byte(Byte.MAX_VALUE), new Byte((byte)9999999)}))
+            ArrayUtils.toPrimitive(new Byte[] {Byte.valueOf(Byte.MIN_VALUE), 
+                Byte.valueOf(Byte.MAX_VALUE), Byte.valueOf((byte)9999999)}))
         );
 
         try {
-            ArrayUtils.toPrimitive(new Byte[] {new Byte(Byte.MIN_VALUE), null});
+            ArrayUtils.toPrimitive(new Byte[] {Byte.valueOf(Byte.MIN_VALUE), null});
             fail();
         } catch (NullPointerException ex) {}
     }
@@ -2127,15 +2127,15 @@
         
         assertTrue(Arrays.equals(
             new byte[] {Byte.MIN_VALUE, Byte.MAX_VALUE, (byte)9999999},
-            ArrayUtils.toPrimitive(new Byte[] {new Byte(Byte.MIN_VALUE), 
-                new Byte(Byte.MAX_VALUE), new Byte((byte)9999999)}, 
+            ArrayUtils.toPrimitive(new Byte[] {Byte.valueOf(Byte.MIN_VALUE), 
+                Byte.valueOf(Byte.MAX_VALUE), Byte.valueOf((byte)9999999)}, 
                 Byte.MIN_VALUE))
         );
         
         assertTrue(Arrays.equals(
             new byte[] {Byte.MIN_VALUE, Byte.MAX_VALUE, (byte)9999999},
-            ArrayUtils.toPrimitive(new Byte[] {new Byte(Byte.MIN_VALUE), null, 
-                new Byte((byte)9999999)}, Byte.MAX_VALUE))
+            ArrayUtils.toPrimitive(new Byte[] {Byte.valueOf(Byte.MIN_VALUE), null, 
+                Byte.valueOf((byte)9999999)}, Byte.MAX_VALUE))
         );
     }
 
@@ -2147,8 +2147,8 @@
             ArrayUtils.toObject(new byte[0]));
         
         assertTrue(Arrays.equals(
-            new Byte[] {new Byte(Byte.MIN_VALUE), 
-                new Byte(Byte.MAX_VALUE), new Byte((byte)9999999)},
+            new Byte[] {Byte.valueOf(Byte.MIN_VALUE), 
+                Byte.valueOf(Byte.MAX_VALUE), Byte.valueOf((byte)9999999)},
                 ArrayUtils.toObject(new byte[] {Byte.MIN_VALUE, Byte.MAX_VALUE, 
                 (byte)9999999}))
         );

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/RangeTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/RangeTest.java?rev=754804&r1=754803&r2=754804&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/RangeTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/RangeTest.java Mon Mar
16 02:06:18 2009
@@ -52,12 +52,12 @@
 
         @Override
         public Number getMaximumNumber() {
-            return new Byte(max);
+            return Byte.valueOf(max);
         }
 
         @Override
         public Number getMinimumNumber() {
-            return new Byte(min);
+            return Byte.valueOf(min);
         }
     }
 

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableByteTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableByteTest.java?rev=754804&r1=754803&r2=754804&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableByteTest.java
(original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableByteTest.java
Mon Mar 16 02:06:18 2009
@@ -47,7 +47,7 @@
         
         assertEquals((byte) 1, new MutableByte((byte) 1).byteValue());
         
-        assertEquals((byte) 2, new MutableByte(new Byte((byte) 2)).byteValue());
+        assertEquals((byte) 2, new MutableByte(Byte.valueOf((byte) 2)).byteValue());
         assertEquals((byte) 3, new MutableByte(new MutableByte((byte) 3)).byteValue());
         try {
             new MutableByte(null);
@@ -58,19 +58,19 @@
     public void testGetSet() {
         final MutableByte mutNum = new MutableByte((byte) 0);
         assertEquals((byte) 0, new MutableByte().byteValue());
-        assertEquals(new Byte((byte) 0), new MutableByte().getValue());
+        assertEquals(Byte.valueOf((byte) 0), new MutableByte().getValue());
         
         mutNum.setValue((byte) 1);
         assertEquals((byte) 1, mutNum.byteValue());
-        assertEquals(new Byte((byte) 1), mutNum.getValue());
+        assertEquals(Byte.valueOf((byte) 1), mutNum.getValue());
         
-        mutNum.setValue(new Byte((byte) 2));
+        mutNum.setValue(Byte.valueOf((byte) 2));
         assertEquals((byte) 2, mutNum.byteValue());
-        assertEquals(new Byte((byte) 2), mutNum.getValue());
+        assertEquals(Byte.valueOf((byte) 2), mutNum.getValue());
         
         mutNum.setValue(new MutableByte((byte) 3));
         assertEquals((byte) 3, mutNum.byteValue());
-        assertEquals(new Byte((byte) 3), mutNum.getValue());
+        assertEquals(Byte.valueOf((byte) 3), mutNum.getValue());
         try {
             mutNum.setValue(null);
             fail();
@@ -94,7 +94,7 @@
         assertEquals(false, mutNumB.equals(mutNumC));
         assertEquals(true, mutNumC.equals(mutNumC));
         assertEquals(false, mutNumA.equals(null));
-        assertEquals(false, mutNumA.equals(new Byte((byte) 0)));
+        assertEquals(false, mutNumA.equals(Byte.valueOf((byte) 0)));
         assertEquals(false, mutNumA.equals("0"));
     }
 
@@ -106,7 +106,7 @@
         assertEquals(true, mutNumA.hashCode() == mutNumA.hashCode());
         assertEquals(true, mutNumA.hashCode() == mutNumB.hashCode());
         assertEquals(false, mutNumA.hashCode() == mutNumC.hashCode());
-        assertEquals(true, mutNumA.hashCode() == new Byte((byte) 0).hashCode());
+        assertEquals(true, mutNumA.hashCode() == Byte.valueOf((byte) 0).hashCode());
     }
 
     public void testCompareTo() {
@@ -120,7 +120,7 @@
             fail();
         } catch (NullPointerException ex) {}
         try {
-            mutNum.compareTo(new Byte((byte) 0));
+            mutNum.compareTo(Byte.valueOf((byte) 0));
             fail();
         } catch (ClassCastException ex) {}
         try {
@@ -141,8 +141,8 @@
     }
 
     public void testToByte() {
-        assertEquals(new Byte((byte) 0), new MutableByte((byte) 0).toByte());
-        assertEquals(new Byte((byte) 123), new MutableByte((byte) 123).toByte());
+        assertEquals(Byte.valueOf((byte) 0), new MutableByte((byte) 0).toByte());
+        assertEquals(Byte.valueOf((byte) 123), new MutableByte((byte) 123).toByte());
     }
 
     public void testIncrement() {



Mime
View raw message