You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by sc...@apache.org on 2009/10/27 00:12:06 UTC
svn commit: r830016 - in /commons/proper/lang/trunk/src:
java/org/apache/commons/lang/mutable/ test/org/apache/commons/lang/mutable/
Author: scolebourne
Date: Mon Oct 26 23:12:05 2009
New Revision: 830016
URL: http://svn.apache.org/viewvc?rev=830016&view=rev
Log:
Use valueOf() to convert primitive to wrapper class
Modified:
commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableBoolean.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableDouble.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableFloat.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableInt.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableLong.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableShort.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableBooleanTest.java
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableBoolean.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableBoolean.java?rev=830016&r1=830015&r2=830016&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableBoolean.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableBoolean.java Mon Oct 26 23:12:05 2009
@@ -80,6 +80,17 @@
return value;
}
+ //-----------------------------------------------------------------------
+ /**
+ * Gets this mutable as an instance of Boolean.
+ *
+ * @return a Boolean instance containing the value from this mutable, never null
+ */
+ public Boolean toBoolean() {
+ return Boolean.valueOf(booleanValue());
+ }
+
+ //-----------------------------------------------------------------------
/**
* Compares this mutable to another in ascending order.
*
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableDouble.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableDouble.java?rev=830016&r1=830015&r2=830016&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableDouble.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableDouble.java Mon Oct 26 23:12:05 2009
@@ -175,10 +175,10 @@
/**
* Gets this mutable as an instance of Double.
*
- * @return a Double instance containing the value from this mutable
+ * @return a Double instance containing the value from this mutable, never null
*/
public Double toDouble() {
- return new Double(doubleValue());
+ return Double.valueOf(doubleValue());
}
//-----------------------------------------------------------------------
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableFloat.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableFloat.java?rev=830016&r1=830015&r2=830016&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableFloat.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableFloat.java Mon Oct 26 23:12:05 2009
@@ -247,10 +247,10 @@
/**
* Gets this mutable as an instance of Float.
*
- * @return a Float instance containing the value from this mutable
+ * @return a Float instance containing the value from this mutable, never null
*/
public Float toFloat() {
- return new Float(floatValue());
+ return Float.valueOf(floatValue());
}
//-----------------------------------------------------------------------
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableInt.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableInt.java?rev=830016&r1=830015&r2=830016&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableInt.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableInt.java Mon Oct 26 23:12:05 2009
@@ -231,10 +231,10 @@
/**
* Gets this mutable as an instance of Integer.
*
- * @return a Integer instance containing the value from this mutable
+ * @return a Integer instance containing the value from this mutable, never null
*/
public Integer toInteger() {
- return new Integer(intValue());
+ return Integer.valueOf(intValue());
}
//-----------------------------------------------------------------------
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableLong.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableLong.java?rev=830016&r1=830015&r2=830016&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableLong.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableLong.java Mon Oct 26 23:12:05 2009
@@ -229,10 +229,10 @@
/**
* Gets this mutable as an instance of Long.
*
- * @return a Long instance containing the value from this mutable
+ * @return a Long instance containing the value from this mutable, never null
*/
public Long toLong() {
- return new Long(longValue());
+ return Long.valueOf(longValue());
}
//-----------------------------------------------------------------------
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableShort.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableShort.java?rev=830016&r1=830015&r2=830016&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableShort.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableShort.java Mon Oct 26 23:12:05 2009
@@ -239,10 +239,10 @@
/**
* Gets this mutable as an instance of Short.
*
- * @return a Short instance containing the value from this mutable
+ * @return a Short instance containing the value from this mutable, never null
*/
public Short toShort() {
- return new Short(shortValue());
+ return Short.valueOf(shortValue());
}
//-----------------------------------------------------------------------
Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableBooleanTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableBooleanTest.java?rev=830016&r1=830015&r2=830016&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableBooleanTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableBooleanTest.java Mon Oct 26 23:12:05 2009
@@ -95,11 +95,15 @@
}
public void testGetSet() {
- final MutableBoolean mutBool = new MutableBoolean(false);
assertEquals(false, new MutableBoolean().booleanValue());
assertEquals(Boolean.FALSE, new MutableBoolean().getValue());
+
+ final MutableBoolean mutBool = new MutableBoolean(false);
+ assertEquals(Boolean.FALSE, mutBool.toBoolean());
+ assertEquals(false, mutBool.booleanValue());
mutBool.setValue(Boolean.TRUE);
+ assertEquals(Boolean.TRUE, mutBool.toBoolean());
assertEquals(true, mutBool.booleanValue());
mutBool.setValue(false);
Re: svn commit: r830016 - in /commons/proper/lang/trunk/src:
java/org/apache/commons/lang/mutable/ test/org/apache/commons/lang/mutable/
Posted by Henri Yandell <fl...@gmail.com>.
Findbugs was big on this being done, but when I tested I found that
new Xxx was generally faster than Xxx.valueOf (outside of the cache
range) which went against FindBugs and "For values outside the
constant range the performance of both styles is the same. ". My
laptop, JDK 1.5, OS X so hardly a conclusive test but it made me doubt
this accepted wisdom.
Anyway - I guess it's okay even if this is a slowdown as it means less
objects and often that's a preferred trade off. Wanted to comment as
the previous investigation was also on this list.
Hen
On Mon, Oct 26, 2009 at 4:12 PM, <sc...@apache.org> wrote:
> Author: scolebourne
> Date: Mon Oct 26 23:12:05 2009
> New Revision: 830016
>
> URL: http://svn.apache.org/viewvc?rev=830016&view=rev
> Log:
> Use valueOf() to convert primitive to wrapper class
>
> Modified:
> commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableBoolean.java
> commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableDouble.java
> commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableFloat.java
> commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableInt.java
> commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableLong.java
> commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableShort.java
> commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableBooleanTest.java
>
> Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableBoolean.java
> URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableBoolean.java?rev=830016&r1=830015&r2=830016&view=diff
> ==============================================================================
> --- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableBoolean.java (original)
> +++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableBoolean.java Mon Oct 26 23:12:05 2009
> @@ -80,6 +80,17 @@
> return value;
> }
>
> + //-----------------------------------------------------------------------
> + /**
> + * Gets this mutable as an instance of Boolean.
> + *
> + * @return a Boolean instance containing the value from this mutable, never null
> + */
> + public Boolean toBoolean() {
> + return Boolean.valueOf(booleanValue());
> + }
> +
> + //-----------------------------------------------------------------------
> /**
> * Compares this mutable to another in ascending order.
> *
>
> Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableDouble.java
> URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableDouble.java?rev=830016&r1=830015&r2=830016&view=diff
> ==============================================================================
> --- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableDouble.java (original)
> +++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableDouble.java Mon Oct 26 23:12:05 2009
> @@ -175,10 +175,10 @@
> /**
> * Gets this mutable as an instance of Double.
> *
> - * @return a Double instance containing the value from this mutable
> + * @return a Double instance containing the value from this mutable, never null
> */
> public Double toDouble() {
> - return new Double(doubleValue());
> + return Double.valueOf(doubleValue());
> }
>
> //-----------------------------------------------------------------------
>
> Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableFloat.java
> URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableFloat.java?rev=830016&r1=830015&r2=830016&view=diff
> ==============================================================================
> --- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableFloat.java (original)
> +++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableFloat.java Mon Oct 26 23:12:05 2009
> @@ -247,10 +247,10 @@
> /**
> * Gets this mutable as an instance of Float.
> *
> - * @return a Float instance containing the value from this mutable
> + * @return a Float instance containing the value from this mutable, never null
> */
> public Float toFloat() {
> - return new Float(floatValue());
> + return Float.valueOf(floatValue());
> }
>
> //-----------------------------------------------------------------------
>
> Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableInt.java
> URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableInt.java?rev=830016&r1=830015&r2=830016&view=diff
> ==============================================================================
> --- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableInt.java (original)
> +++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableInt.java Mon Oct 26 23:12:05 2009
> @@ -231,10 +231,10 @@
> /**
> * Gets this mutable as an instance of Integer.
> *
> - * @return a Integer instance containing the value from this mutable
> + * @return a Integer instance containing the value from this mutable, never null
> */
> public Integer toInteger() {
> - return new Integer(intValue());
> + return Integer.valueOf(intValue());
> }
>
> //-----------------------------------------------------------------------
>
> Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableLong.java
> URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableLong.java?rev=830016&r1=830015&r2=830016&view=diff
> ==============================================================================
> --- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableLong.java (original)
> +++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableLong.java Mon Oct 26 23:12:05 2009
> @@ -229,10 +229,10 @@
> /**
> * Gets this mutable as an instance of Long.
> *
> - * @return a Long instance containing the value from this mutable
> + * @return a Long instance containing the value from this mutable, never null
> */
> public Long toLong() {
> - return new Long(longValue());
> + return Long.valueOf(longValue());
> }
>
> //-----------------------------------------------------------------------
>
> Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableShort.java
> URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableShort.java?rev=830016&r1=830015&r2=830016&view=diff
> ==============================================================================
> --- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableShort.java (original)
> +++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableShort.java Mon Oct 26 23:12:05 2009
> @@ -239,10 +239,10 @@
> /**
> * Gets this mutable as an instance of Short.
> *
> - * @return a Short instance containing the value from this mutable
> + * @return a Short instance containing the value from this mutable, never null
> */
> public Short toShort() {
> - return new Short(shortValue());
> + return Short.valueOf(shortValue());
> }
>
> //-----------------------------------------------------------------------
>
> Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableBooleanTest.java
> URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableBooleanTest.java?rev=830016&r1=830015&r2=830016&view=diff
> ==============================================================================
> --- commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableBooleanTest.java (original)
> +++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableBooleanTest.java Mon Oct 26 23:12:05 2009
> @@ -95,11 +95,15 @@
> }
>
> public void testGetSet() {
> - final MutableBoolean mutBool = new MutableBoolean(false);
> assertEquals(false, new MutableBoolean().booleanValue());
> assertEquals(Boolean.FALSE, new MutableBoolean().getValue());
> +
> + final MutableBoolean mutBool = new MutableBoolean(false);
> + assertEquals(Boolean.FALSE, mutBool.toBoolean());
> + assertEquals(false, mutBool.booleanValue());
>
> mutBool.setValue(Boolean.TRUE);
> + assertEquals(Boolean.TRUE, mutBool.toBoolean());
> assertEquals(true, mutBool.booleanValue());
>
> mutBool.setValue(false);
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org