commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1153487 - 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/math/ test/java/org/apache/commons/lan...
Date Wed, 03 Aug 2011 13:44:52 GMT
Author: ggregory
Date: Wed Aug  3 13:44:51 2011
New Revision: 1153487

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

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/MutableLong.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/math/NumberUtilsTest.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/mutable/MutableLongTest.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=1153487&r1=1153486&r2=1153487&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:44:51 2011
@@ -30,11 +30,11 @@ import org.apache.commons.lang3.StringUt
 public class NumberUtils {
     
     /** Reusable Long constant for zero. */
-    public static final Long LONG_ZERO = new Long(0L);
+    public static final Long LONG_ZERO = Long.valueOf(0L);
     /** Reusable Long constant for one. */
-    public static final Long LONG_ONE = new Long(1L);
+    public static final Long LONG_ONE = Long.valueOf(1L);
     /** Reusable Long constant for minus one. */
-    public static final Long LONG_MINUS_ONE = new Long(-1L);
+    public static final Long LONG_MINUS_ONE = Long.valueOf(-1L);
     /** Reusable Integer constant for zero. */
     public static final Integer INTEGER_ZERO = Integer.valueOf(0);
     /** Reusable Integer constant for one. */
@@ -398,7 +398,7 @@ public class NumberUtils {
     // Integer.valueOf(String)
     // new Double(String)
     // new Byte(String)
-    // new Long(String)
+    // Long.valueOf(String)
     // Long.getLong(String)
     // Long.getLong(String,int)
     // Long.getLong(String,Integer)

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/mutable/MutableLong.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/mutable/MutableLong.java?rev=1153487&r1=1153486&r2=1153487&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/mutable/MutableLong.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/mutable/MutableLong.java
Wed Aug  3 13:44:51 2011
@@ -82,7 +82,7 @@ public class MutableLong extends Number 
      * @return the value as a Long, never null
      */
     public Long getValue() {
-        return new Long(this.value);
+        return Long.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=1153487&r1=1153486&r2=1153487&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:44:51 2011
@@ -2551,12 +2551,12 @@ public class ArrayUtilsTest extends Test
          
          assertTrue(Arrays.equals(
              new long[] {Long.MIN_VALUE, Long.MAX_VALUE, 9999999},
-             ArrayUtils.toPrimitive(new Long[] {new Long(Long.MIN_VALUE), 
-                 new Long(Long.MAX_VALUE), new Long(9999999)}))
+             ArrayUtils.toPrimitive(new Long[] {Long.valueOf(Long.MIN_VALUE), 
+                 Long.valueOf(Long.MAX_VALUE), Long.valueOf(9999999)}))
          );
 
          try {
-             ArrayUtils.toPrimitive(new Long[] {new Long(Long.MIN_VALUE), null});
+             ArrayUtils.toPrimitive(new Long[] {Long.valueOf(Long.MIN_VALUE), null});
              fail();
          } catch (NullPointerException ex) {}
      }
@@ -2570,13 +2570,13 @@ public class ArrayUtilsTest extends Test
          
          assertTrue(Arrays.equals(
              new long[] {Long.MIN_VALUE, Long.MAX_VALUE, 9999999},
-             ArrayUtils.toPrimitive(new Long[] {new Long(Long.MIN_VALUE), 
-                 new Long(Long.MAX_VALUE), new Long(9999999)},1)));
+             ArrayUtils.toPrimitive(new Long[] {Long.valueOf(Long.MIN_VALUE), 
+                 Long.valueOf(Long.MAX_VALUE), Long.valueOf(9999999)},1)));
          
          assertTrue(Arrays.equals(
              new long[] {Long.MIN_VALUE, Long.MAX_VALUE, 9999999},
-             ArrayUtils.toPrimitive(new Long[] {new Long(Long.MIN_VALUE), 
-                 null, new Long(9999999)}, Long.MAX_VALUE))
+             ArrayUtils.toPrimitive(new Long[] {Long.valueOf(Long.MIN_VALUE), 
+                 null, Long.valueOf(9999999)}, Long.MAX_VALUE))
          );
      }
      
@@ -2591,9 +2591,9 @@ public class ArrayUtilsTest extends Test
         assertTrue(
             Arrays.equals(
                 new Long[] {
-                    new Long(Long.MIN_VALUE),
-                    new Long(Long.MAX_VALUE),
-                    new Long(9999999)},
+                    Long.valueOf(Long.MIN_VALUE),
+                    Long.valueOf(Long.MAX_VALUE),
+                    Long.valueOf(9999999)},
             ArrayUtils.toObject(
                 new long[] { Long.MIN_VALUE, Long.MAX_VALUE, 9999999 })));
     }

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java?rev=1153487&r1=1153486&r2=1153487&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
Wed Aug  3 13:44:51 2011
@@ -187,10 +187,10 @@ public class NumberUtilsTest {
         assertEquals("createNumber(String) 3 failed", new Double("1234.5"), NumberUtils.createNumber("1234.5d"));
         assertEquals("createNumber(String) 4 failed", new Float("1234.5"), NumberUtils.createNumber("1234.5F"));
         assertEquals("createNumber(String) 4 failed", new Float("1234.5"), NumberUtils.createNumber("1234.5f"));
-        assertEquals("createNumber(String) 5 failed", new Long(Integer.MAX_VALUE + 1L), NumberUtils.createNumber(""
+        assertEquals("createNumber(String) 5 failed", Long.valueOf(Integer.MAX_VALUE + 1L),
NumberUtils.createNumber(""
             + (Integer.MAX_VALUE + 1L)));
-        assertEquals("createNumber(String) 6 failed", new Long(12345), NumberUtils.createNumber("12345L"));
-        assertEquals("createNumber(String) 6 failed", new Long(12345), NumberUtils.createNumber("12345l"));
+        assertEquals("createNumber(String) 6 failed", Long.valueOf(12345), NumberUtils.createNumber("12345L"));
+        assertEquals("createNumber(String) 6 failed", Long.valueOf(12345), NumberUtils.createNumber("12345l"));
         assertEquals("createNumber(String) 7 failed", new Float("-1234.5"), NumberUtils.createNumber("-1234.5"));
         assertEquals("createNumber(String) 8 failed", Integer.valueOf("-12345"), NumberUtils.createNumber("-12345"));
         assertTrue("createNumber(String) 9 failed", 0xFADE == NumberUtils.createNumber("0xFADE").intValue());
@@ -208,9 +208,9 @@ public class NumberUtilsTest {
             assertEquals("createNumber(String) 15 failed", new BigDecimal("1.1E-700"), NumberUtils
                     .createNumber("1.1E-700F"));
         }
-        assertEquals("createNumber(String) 16 failed", new Long("10" + Integer.MAX_VALUE),
NumberUtils
+        assertEquals("createNumber(String) 16 failed", Long.valueOf("10" + Integer.MAX_VALUE),
NumberUtils
                 .createNumber("10" + Integer.MAX_VALUE + "L"));
-        assertEquals("createNumber(String) 17 failed", new Long("10" + Integer.MAX_VALUE),
NumberUtils
+        assertEquals("createNumber(String) 17 failed", Long.valueOf("10" + Integer.MAX_VALUE),
NumberUtils
                 .createNumber("10" + Integer.MAX_VALUE));
         assertEquals("createNumber(String) 18 failed", new BigInteger("10" + Long.MAX_VALUE),
NumberUtils
                 .createNumber("10" + Long.MAX_VALUE));
@@ -288,7 +288,7 @@ public class NumberUtilsTest {
 
     @Test
     public void testCreateLong() {
-        assertEquals("createLong(String) failed", new Long("12345"), NumberUtils.createLong("12345"));
+        assertEquals("createLong(String) failed", Long.valueOf("12345"), NumberUtils.createLong("12345"));
         assertEquals("createLong(null) failed", null, NumberUtils.createLong(null));
         this.testCreateLongFailure("");
         this.testCreateLongFailure(" ");

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/mutable/MutableLongTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/mutable/MutableLongTest.java?rev=1153487&r1=1153486&r2=1153487&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/mutable/MutableLongTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/mutable/MutableLongTest.java
Wed Aug  3 13:44:51 2011
@@ -36,7 +36,7 @@ public class MutableLongTest extends Tes
         
         assertEquals(1, new MutableLong(1).longValue());
         
-        assertEquals(2, new MutableLong(new Long(2)).longValue());
+        assertEquals(2, new MutableLong(Long.valueOf(2)).longValue());
         assertEquals(3, new MutableLong(new MutableLong(3)).longValue());
 
         assertEquals(2, new MutableLong("2").longValue());
@@ -50,19 +50,19 @@ public class MutableLongTest extends Tes
     public void testGetSet() {
         final MutableLong mutNum = new MutableLong(0);
         assertEquals(0, new MutableLong().longValue());
-        assertEquals(new Long(0), new MutableLong().getValue());
+        assertEquals(Long.valueOf(0), new MutableLong().getValue());
         
         mutNum.setValue(1);
         assertEquals(1, mutNum.longValue());
-        assertEquals(new Long(1), mutNum.getValue());
+        assertEquals(Long.valueOf(1), mutNum.getValue());
         
-        mutNum.setValue(new Long(2));
+        mutNum.setValue(Long.valueOf(2));
         assertEquals(2, mutNum.longValue());
-        assertEquals(new Long(2), mutNum.getValue());
+        assertEquals(Long.valueOf(2), mutNum.getValue());
         
         mutNum.setValue(new MutableLong(3));
         assertEquals(3, mutNum.longValue());
-        assertEquals(new Long(3), mutNum.getValue());
+        assertEquals(Long.valueOf(3), mutNum.getValue());
         try {
             mutNum.setValue(null);
             fail();
@@ -82,7 +82,7 @@ public class MutableLongTest extends Tes
         assertEquals(false, mutNumB.equals(mutNumC));
         assertEquals(true, mutNumC.equals(mutNumC));
         assertEquals(false, mutNumA.equals(null));
-        assertEquals(false, mutNumA.equals(new Long(0)));
+        assertEquals(false, mutNumA.equals(Long.valueOf(0)));
         assertEquals(false, mutNumA.equals("0"));
     }
 
@@ -94,7 +94,7 @@ public class MutableLongTest extends Tes
         assertEquals(true, mutNumA.hashCode() == mutNumA.hashCode());
         assertEquals(true, mutNumA.hashCode() == mutNumB.hashCode());
         assertEquals(false, mutNumA.hashCode() == mutNumC.hashCode());
-        assertEquals(true, mutNumA.hashCode() == new Long(0).hashCode());
+        assertEquals(true, mutNumA.hashCode() == Long.valueOf(0).hashCode());
     }
 
     public void testCompareTo() {
@@ -121,8 +121,8 @@ public class MutableLongTest extends Tes
     }
 
     public void testToLong() {
-        assertEquals(new Long(0L), new MutableLong(0L).toLong());
-        assertEquals(new Long(123L), new MutableLong(123L).toLong());
+        assertEquals(Long.valueOf(0L), new MutableLong(0L).toLong());
+        assertEquals(Long.valueOf(123L), new MutableLong(123L).toLong());
     }
 
     public void testIncrement() {
@@ -151,7 +151,7 @@ public class MutableLongTest extends Tes
 
     public void testAddValueObject() {
         MutableLong mutNum = new MutableLong(1);
-        mutNum.add(new Long(1));
+        mutNum.add(Long.valueOf(1));
         
         assertEquals(2, mutNum.intValue());
         assertEquals(2L, mutNum.longValue());
@@ -167,7 +167,7 @@ public class MutableLongTest extends Tes
 
     public void testSubtractValueObject() {
         MutableLong mutNum = new MutableLong(1);
-        mutNum.subtract(new Long(1));
+        mutNum.subtract(Long.valueOf(1));
         
         assertEquals(0, mutNum.intValue());
         assertEquals(0L, mutNum.longValue());



Mime
View raw message