From 283fa00f77e4ae9db40e52d9115b4ef17959f319 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 26 Oct 2009 23:12:05 +0000 Subject: [PATCH] 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 --- .../apache/commons/lang/mutable/MutableBoolean.java | 11 +++++++++++ .../apache/commons/lang/mutable/MutableDouble.java | 4 ++-- .../org/apache/commons/lang/mutable/MutableFloat.java | 4 ++-- .../org/apache/commons/lang/mutable/MutableInt.java | 4 ++-- .../org/apache/commons/lang/mutable/MutableLong.java | 4 ++-- .../org/apache/commons/lang/mutable/MutableShort.java | 4 ++-- .../commons/lang/mutable/MutableBooleanTest.java | 6 +++++- 7 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/java/org/apache/commons/lang/mutable/MutableBoolean.java b/src/java/org/apache/commons/lang/mutable/MutableBoolean.java index fdf396a6d..3710582ff 100644 --- a/src/java/org/apache/commons/lang/mutable/MutableBoolean.java +++ b/src/java/org/apache/commons/lang/mutable/MutableBoolean.java @@ -80,6 +80,17 @@ public boolean booleanValue() { 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. * diff --git a/src/java/org/apache/commons/lang/mutable/MutableDouble.java b/src/java/org/apache/commons/lang/mutable/MutableDouble.java index c6b9d373e..5d73336ca 100644 --- a/src/java/org/apache/commons/lang/mutable/MutableDouble.java +++ b/src/java/org/apache/commons/lang/mutable/MutableDouble.java @@ -175,10 +175,10 @@ public boolean isInfinite() { /** * 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()); } //----------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/lang/mutable/MutableFloat.java b/src/java/org/apache/commons/lang/mutable/MutableFloat.java index c528301ea..26a953328 100644 --- a/src/java/org/apache/commons/lang/mutable/MutableFloat.java +++ b/src/java/org/apache/commons/lang/mutable/MutableFloat.java @@ -247,10 +247,10 @@ public boolean isInfinite() { /** * 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()); } //----------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/lang/mutable/MutableInt.java b/src/java/org/apache/commons/lang/mutable/MutableInt.java index 0599dc2ea..456821f18 100644 --- a/src/java/org/apache/commons/lang/mutable/MutableInt.java +++ b/src/java/org/apache/commons/lang/mutable/MutableInt.java @@ -231,10 +231,10 @@ public double doubleValue() { /** * 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()); } //----------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/lang/mutable/MutableLong.java b/src/java/org/apache/commons/lang/mutable/MutableLong.java index f89f1e14b..e945718d1 100644 --- a/src/java/org/apache/commons/lang/mutable/MutableLong.java +++ b/src/java/org/apache/commons/lang/mutable/MutableLong.java @@ -229,10 +229,10 @@ public double doubleValue() { /** * 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()); } //----------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/lang/mutable/MutableShort.java b/src/java/org/apache/commons/lang/mutable/MutableShort.java index b653a3ed6..82e14dbb7 100644 --- a/src/java/org/apache/commons/lang/mutable/MutableShort.java +++ b/src/java/org/apache/commons/lang/mutable/MutableShort.java @@ -239,10 +239,10 @@ public double doubleValue() { /** * 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()); } //----------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/lang/mutable/MutableBooleanTest.java b/src/test/org/apache/commons/lang/mutable/MutableBooleanTest.java index 852e52d51..9bb8cff71 100644 --- a/src/test/org/apache/commons/lang/mutable/MutableBooleanTest.java +++ b/src/test/org/apache/commons/lang/mutable/MutableBooleanTest.java @@ -95,11 +95,15 @@ public void testEquals() { } 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);