Use valueOf() to convert primitive to wrapper class

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@830016 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2009-10-26 23:12:05 +00:00
parent bbab0a4b4c
commit 283fa00f77
7 changed files with 26 additions and 11 deletions

View File

@ -80,6 +80,17 @@ public class MutableBoolean implements Mutable<Boolean>, Serializable, Comparabl
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.
*

View File

@ -175,10 +175,10 @@ public class MutableDouble extends Number implements Comparable<MutableDouble>,
/**
* 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());
}
//-----------------------------------------------------------------------

View File

@ -247,10 +247,10 @@ public class MutableFloat extends Number implements Comparable<MutableFloat>, Mu
/**
* 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());
}
//-----------------------------------------------------------------------

View File

@ -231,10 +231,10 @@ public class MutableInt extends Number implements Comparable<MutableInt>, Mutabl
/**
* 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());
}
//-----------------------------------------------------------------------

View File

@ -229,10 +229,10 @@ public class MutableLong extends Number implements Comparable<MutableLong>, Muta
/**
* 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());
}
//-----------------------------------------------------------------------

View File

@ -239,10 +239,10 @@ public class MutableShort extends Number implements Comparable<MutableShort>, Mu
/**
* 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());
}
//-----------------------------------------------------------------------

View File

@ -95,11 +95,15 @@ public class MutableBooleanTest extends TestCase {
}
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);