From 49e1f137ebba86fe01e73614202345ce57056e89 Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Fri, 8 Oct 2004 19:45:46 +0000 Subject: [PATCH] - Added javadoc package.html - Removed all "implements java.io.Serializable" since java.lang.Number already declares it. - New Javadoc for equals(Object) methods to match Number subclasses, in particular to provide more details for Float and Double. - equals(Object) methods now use /type/Value() calls instead of ".value" direct references (similar impl to Number subclasses). git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137961 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/lang/mutable/Mutable.java | 31 +++--- .../commons/lang/mutable/MutableByte.java | 57 ++++++---- .../commons/lang/mutable/MutableDouble.java | 87 ++++++++++----- .../commons/lang/mutable/MutableFloat.java | 103 +++++++++++++----- .../commons/lang/mutable/MutableInt.java | 57 ++++++---- .../commons/lang/mutable/MutableLong.java | 59 +++++----- .../commons/lang/mutable/MutableObject.java | 32 +++--- .../commons/lang/mutable/MutableShort.java | 57 ++++++---- .../apache/commons/lang/mutable/package.html | 39 +++++++ 9 files changed, 337 insertions(+), 185 deletions(-) create mode 100644 src/java/org/apache/commons/lang/mutable/package.html diff --git a/src/java/org/apache/commons/lang/mutable/Mutable.java b/src/java/org/apache/commons/lang/mutable/Mutable.java index f8944d1dc..2470e070e 100755 --- a/src/java/org/apache/commons/lang/mutable/Mutable.java +++ b/src/java/org/apache/commons/lang/mutable/Mutable.java @@ -13,39 +13,40 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.commons.lang.mutable; /** - * Defines an object that allows mutable access to a value. + * Provides mutable access to a value. *

- * Mutable is used as a generic interface to the implementations - * in this package. + * Mutable is used as a generic interface to the implementations in this package. *

- * A typical use case would be to enable a primitive or string to be passed - * to a method and allow that method to effectively change the value of the - * primitive/string. Another use case is to store a frequently changing - * primitive in a collection (for example a total in a map) without needing - * to create new Integer/Long wrapper objects. - * + * A typical use case would be to enable a primitive or string to be passed to a method and allow that method to + * effectively change the value of the primitive/string. Another use case is to store a frequently changing primitive in + * a collection (for example a total in a map) without needing to create new Integer/Long wrapper objects. + * * @author Matthew Hawthorne * @since 2.1 - * @version $Id: Mutable.java,v 1.2 2004/07/05 22:12:22 scolebourne Exp $ + * @version $Id: Mutable.java,v 1.3 2004/10/08 19:45:46 ggregory Exp $ */ public interface Mutable { /** * Gets the value of this mutable. - * + * * @return the stored value */ Object getValue(); /** * Sets the value of this mutable. - * - * @param value the value to store - * @throws NullPointerException if the object is null and null is invalid - * @throws ClassCastException if the type is invalid + * + * @param value + * the value to store + * @throws NullPointerException + * if the object is null and null is invalid + * @throws ClassCastException + * if the type is invalid */ void setValue(Object value); diff --git a/src/java/org/apache/commons/lang/mutable/MutableByte.java b/src/java/org/apache/commons/lang/mutable/MutableByte.java index 510536fd2..0dba0167e 100755 --- a/src/java/org/apache/commons/lang/mutable/MutableByte.java +++ b/src/java/org/apache/commons/lang/mutable/MutableByte.java @@ -13,18 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.commons.lang.mutable; -import java.io.Serializable; - /** - * A mutable byte. + * A mutable byte wrapper. * + * @see Byte * @since 2.1 - * @version $Id: MutableByte.java,v 1.5 2004/10/01 17:12:29 ggregory Exp $ + * @version $Id: MutableByte.java,v 1.6 2004/10/08 19:45:46 ggregory Exp $ */ -public class MutableByte extends Number - implements Comparable, Mutable, Serializable { +public class MutableByte extends Number implements Comparable, Mutable { /** Serialization lock. */ private static final long serialVersionUID = -1585823265L; @@ -42,7 +41,8 @@ public MutableByte() { /** * Constructs a new MutableByte with the specified value. * - * @param value a value. + * @param value + * a value. */ public MutableByte(byte value) { super(); @@ -52,8 +52,10 @@ public MutableByte(byte value) { /** * Constructs a new MutableByte with the specified value. * - * @param value a value. - * @throws NullPointerException if the object is null + * @param value + * a value. + * @throws NullPointerException + * if the object is null */ public MutableByte(Number value) { super(); @@ -73,7 +75,8 @@ public Object getValue() { /** * Sets the value. * - * @param value the value to set + * @param value + * the value to set */ public void setValue(byte value) { this.value = value; @@ -82,9 +85,12 @@ public void setValue(byte value) { /** * Sets the value from any Number instance. * - * @param value the value to set - * @throws NullPointerException if the object is null - * @throws ClassCastException if the type is invalid + * @param value + * the value to set + * @throws NullPointerException + * if the object is null + * @throws ClassCastException + * if the type is not a {@link Number} */ public void setValue(Object value) { setValue(((Number) value).byteValue()); @@ -113,23 +119,24 @@ public double doubleValue() { //----------------------------------------------------------------------- /** - * Checks if this object equals the specified object. - *

- * The object must be a MutableByte with the same value to be equal. - * - * @param obj the object to compare to - * @return true if equal + * Compares this object against the specified object. The result is true if and only if the argument + * is not null and is a MutableByte object that contains the same byte + * value as this object. + * + * @param obj + * the object to compare with. + * @return true if the objects are the same; false otherwise. */ public boolean equals(Object obj) { if (obj instanceof MutableByte) { - return (value == ((MutableByte) obj).value); + return value == ((MutableByte) obj).byteValue(); } return false; } /** * Returns a suitable hashcode for this mutable. - * + * * @return a suitable hashcode */ public int hashCode() { @@ -138,9 +145,11 @@ public int hashCode() { /** * Compares this mutable to another in ascending order. - * - * @param obj the mutable to compare to + * + * @param obj + * the mutable to compare to * @return negative if this is less, zero if equal, positive if greater + * @throws ClassCastException if the argument is not a MutableByte */ public int compareTo(Object obj) { MutableByte other = (MutableByte) obj; @@ -150,7 +159,7 @@ public int compareTo(Object obj) { /** * Returns the String value of this mutable. - * + * * @return the mutable value as a string */ public String toString() { diff --git a/src/java/org/apache/commons/lang/mutable/MutableDouble.java b/src/java/org/apache/commons/lang/mutable/MutableDouble.java index 3ec68c559..0bf7d5bf3 100755 --- a/src/java/org/apache/commons/lang/mutable/MutableDouble.java +++ b/src/java/org/apache/commons/lang/mutable/MutableDouble.java @@ -13,20 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.commons.lang.mutable; -import java.io.Serializable; +package org.apache.commons.lang.mutable; import org.apache.commons.lang.math.NumberUtils; /** - * A mutable double. + * A mutable double wrapper. * + * @see Double * @since 2.1 - * @version $Id: MutableDouble.java,v 1.4 2004/07/07 23:50:28 scolebourne Exp $ + * @version $Id: MutableDouble.java,v 1.5 2004/10/08 19:45:46 ggregory Exp $ */ -public class MutableDouble extends Number - implements Comparable, Mutable, Serializable { +public class MutableDouble extends Number implements Comparable, Mutable { /** Serialization lock. */ private static final long serialVersionUID = 1587163916L; @@ -44,7 +43,8 @@ public MutableDouble() { /** * Constructs a new MutableDouble with the specified value. * - * @param value a value. + * @param value + * a value. */ public MutableDouble(double value) { super(); @@ -54,8 +54,10 @@ public MutableDouble(double value) { /** * Constructs a new MutableDouble with the specified value. * - * @param value a value. - * @throws NullPointerException if the object is null + * @param value + * a value. + * @throws NullPointerException + * if the object is null */ public MutableDouble(Number value) { super(); @@ -75,7 +77,8 @@ public Object getValue() { /** * Sets the value. * - * @param value the value to set + * @param value + * the value to set */ public void setValue(double value) { this.value = value; @@ -84,9 +87,12 @@ public void setValue(double value) { /** * Sets the value from any Number instance. * - * @param value the value to set - * @throws NullPointerException if the object is null - * @throws ClassCastException if the type is invalid + * @param value + * the value to set + * @throws NullPointerException + * if the object is null + * @throws ClassCastException + * if the type is not a {@link Number} */ public void setValue(Object value) { setValue(((Number) value).doubleValue()); @@ -111,7 +117,7 @@ public double doubleValue() { /** * Checks whether the double value is the special NaN value. - * + * * @return true if NaN */ public boolean isNaN() { @@ -120,7 +126,7 @@ public boolean isNaN() { /** * Checks whether the double value is infinite. - * + * * @return true if infinite */ public boolean isInfinite() { @@ -129,36 +135,57 @@ public boolean isInfinite() { //----------------------------------------------------------------------- /** - * Checks if this object equals the specified object. + * Compares this object against the specified object. The result is true if and only if the argument + * is not null and is a Double object that represents a double that has the identical + * bit pattern to the bit pattern of the double represented by this object. For this purpose, two + * double values are considered to be the same if and only if the method + * {@link Double#doubleToLongBits(double)}returns the same long value when applied to each. *

- * The object must be a MutableDouble with the same value to be equal. - * - * @param obj the object to compare to - * @return true if equal + * Note that in most cases, for two instances of class Double,d1 and d2, + * the value of d1.equals(d2) is true if and only if

+ * + *
+     *   d1.doubleValue() == d2.doubleValue()
+     * 
+ * + *
+ *

+ * also has the value true. However, there are two exceptions: + *

+ * + * @param obj + * the object to compare with. + * @return true if the objects are the same; false otherwise. */ public boolean equals(Object obj) { - if (obj instanceof MutableDouble) { - double other = ((MutableDouble) obj).value; - return (Double.doubleToLongBits(other) == Double.doubleToLongBits(value)); - } - return false; + return (obj instanceof MutableDouble) + && (Double.doubleToLongBits(((MutableDouble) obj).value) == Double.doubleToLongBits(value)); } /** * Returns a suitable hashcode for this mutable. - * + * * @return a suitable hashcode */ public int hashCode() { long bits = Double.doubleToLongBits(value); - return (int)(bits ^ (bits >>> 32)); + return (int) (bits ^ (bits >>> 32)); } /** * Compares this mutable to another in ascending order. - * - * @param obj the mutable to compare to + * + * @param obj + * the mutable to compare to * @return negative if this is less, zero if equal, positive if greater + * @throws ClassCastException if the argument is not a MutableDouble */ public int compareTo(Object obj) { MutableDouble other = (MutableDouble) obj; @@ -168,7 +195,7 @@ public int compareTo(Object obj) { /** * Returns the String value of this mutable. - * + * * @return the mutable value as a string */ public String toString() { diff --git a/src/java/org/apache/commons/lang/mutable/MutableFloat.java b/src/java/org/apache/commons/lang/mutable/MutableFloat.java index 8c6cbb140..369dcdb64 100755 --- a/src/java/org/apache/commons/lang/mutable/MutableFloat.java +++ b/src/java/org/apache/commons/lang/mutable/MutableFloat.java @@ -13,20 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.commons.lang.mutable; -import java.io.Serializable; +package org.apache.commons.lang.mutable; import org.apache.commons.lang.math.NumberUtils; /** - * A mutable float. + * A mutable float wrapper. * + * @see Float * @since 2.1 - * @version $Id: MutableFloat.java,v 1.5 2004/10/01 17:12:29 ggregory Exp $ + * @version $Id: MutableFloat.java,v 1.6 2004/10/08 19:45:46 ggregory Exp $ */ -public class MutableFloat extends Number - implements Comparable, Mutable, Serializable { +public class MutableFloat extends Number implements Comparable, Mutable { /** Serialization lock. */ private static final long serialVersionUID = 5787169186L; @@ -44,7 +43,8 @@ public MutableFloat() { /** * Constructs a new MutableFloat with the specified value. * - * @param value a value. + * @param value + * a value. */ public MutableFloat(float value) { super(); @@ -54,8 +54,10 @@ public MutableFloat(float value) { /** * Constructs a new MutableFloat with the specified value. * - * @param value a value. - * @throws NullPointerException if the object is null + * @param value + * a value. + * @throws NullPointerException + * if the object is null */ public MutableFloat(Number value) { super(); @@ -75,7 +77,8 @@ public Object getValue() { /** * Sets the value. * - * @param value the value to set + * @param value + * the value to set */ public void setValue(float value) { this.value = value; @@ -84,9 +87,12 @@ public void setValue(float value) { /** * Sets the value from any Number instance. * - * @param value the value to set - * @throws NullPointerException if the object is null - * @throws ClassCastException if the type is invalid + * @param value + * the value to set + * @throws NullPointerException + * if the object is null + * @throws ClassCastException + * if the type is not a {@link Number} */ public void setValue(Object value) { setValue(((Number) value).floatValue()); @@ -111,7 +117,7 @@ public double doubleValue() { /** * Checks whether the float value is the special NaN value. - * + * * @return true if NaN */ public boolean isNaN() { @@ -120,33 +126,71 @@ public boolean isNaN() { /** * Checks whether the float value is infinite. - * + * * @return true if infinite */ public boolean isInfinite() { return Float.isInfinite(value); } + /** + * Compares this object against some other object. The result is true if and only if the argument is + * not null and is a Float object that represents a float that has the + * identical bit pattern to the bit pattern of the float represented by this object. For this + * purpose, two float values are considered to be the same if and only if the method + * {@link Float#floatToIntBits(float)}returns the same int value when applied to each. + *

+ * Note that in most cases, for two instances of class Float,f1 and f2, + * the value of f1.equals(f2) is true if and only if

+ * + *
+     *   f1.floatValue() == f2.floatValue()
+     * 
+ * + *
+ *

+ * also has the value true. However, there are two exceptions: + *

+ * This definition allows hashtables to operate properly. + * + * @param obj + * the object to be compared + * @return true if the objects are the same; false otherwise. + * @throws ClassCastException if the argument is not a MutableFloat + * @see java.lang.Float#floatToIntBits(float) + */ + public boolean equals(Object obj) { + return (obj instanceof MutableFloat) + && (Float.floatToIntBits(((MutableFloat) obj).value) == Float.floatToIntBits(value)); + } + //----------------------------------------------------------------------- /** * Checks if this object equals the specified object. *

* The object must be a MutableFloat with the same value to be equal. - * - * @param obj the object to compare to + * + * @param obj + * the object to compare to * @return true if equal */ - public boolean equals(Object obj) { - if (obj instanceof MutableFloat) { - float other = ((MutableFloat) obj).value; - return (Float.floatToIntBits(other) == Float.floatToIntBits(value)); - } - return false; - } - + // public boolean equals(Object obj) { + // if (obj instanceof MutableFloat) { + // float other = ((MutableFloat) obj).value; + // return (Float.floatToIntBits(other) == Float.floatToIntBits(value)); + // } + // return false; + // } /** * Returns a suitable hashcode for this mutable. - * + * * @return a suitable hashcode */ public int hashCode() { @@ -155,8 +199,9 @@ public int hashCode() { /** * Compares this mutable to another in ascending order. - * - * @param obj the mutable to compare to + * + * @param obj + * the mutable to compare to * @return negative if this is less, zero if equal, positive if greater */ public int compareTo(Object obj) { @@ -167,7 +212,7 @@ public int compareTo(Object obj) { /** * Returns the String value of this mutable. - * + * * @return the mutable value as a string */ public String toString() { diff --git a/src/java/org/apache/commons/lang/mutable/MutableInt.java b/src/java/org/apache/commons/lang/mutable/MutableInt.java index 1056cb919..ae94f831a 100644 --- a/src/java/org/apache/commons/lang/mutable/MutableInt.java +++ b/src/java/org/apache/commons/lang/mutable/MutableInt.java @@ -13,18 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.commons.lang.mutable; -import java.io.Serializable; - /** - * A mutable int. + * A mutable int wrapper. * + * @see Integer * @since 2.1 - * @version $Id: MutableInt.java,v 1.3 2004/10/01 17:12:29 ggregory Exp $ + * @version $Id: MutableInt.java,v 1.4 2004/10/08 19:45:46 ggregory Exp $ */ -public class MutableInt extends Number - implements Comparable, Mutable, Serializable { +public class MutableInt extends Number implements Comparable, Mutable { /** Serialization lock. */ private static final long serialVersionUID = 512176391864L; @@ -42,7 +41,8 @@ public MutableInt() { /** * Constructs a new MutableInt with the specified value. * - * @param value a value. + * @param value + * a value. */ public MutableInt(int value) { super(); @@ -52,8 +52,10 @@ public MutableInt(int value) { /** * Constructs a new MutableInt with the specified value. * - * @param value a value. - * @throws NullPointerException if the object is null + * @param value + * a value. + * @throws NullPointerException + * if the object is null */ public MutableInt(Number value) { super(); @@ -73,7 +75,8 @@ public Object getValue() { /** * Sets the value. * - * @param value the value to set + * @param value + * the value to set */ public void setValue(int value) { this.value = value; @@ -82,9 +85,12 @@ public void setValue(int value) { /** * Sets the value from any Number instance. * - * @param value the value to set - * @throws NullPointerException if the object is null - * @throws ClassCastException if the type is invalid + * @param value + * the value to set + * @throws NullPointerException + * if the object is null + * @throws ClassCastException + * if the type is not a {@link Number} */ public void setValue(Object value) { setValue(((Number) value).intValue()); @@ -109,23 +115,24 @@ public double doubleValue() { //----------------------------------------------------------------------- /** - * Checks if this object equals the specified object. - *

- * The object must be a MutableInt with the same value to be equal. - * - * @param obj the object to compare to - * @return true if equal + * Compares this object to the specified object. The result is true if and only if the argument is + * not null and is an MutableInt object that contains the same int value + * as this object. + * + * @param obj + * the object to compare with. + * @return true if the objects are the same; false otherwise. */ public boolean equals(Object obj) { if (obj instanceof MutableInt) { - return (value == ((MutableInt) obj).value); + return (value == ((MutableInt) obj).intValue()); } return false; } /** * Returns a suitable hashcode for this mutable. - * + * * @return a suitable hashcode */ public int hashCode() { @@ -134,9 +141,11 @@ public int hashCode() { /** * Compares this mutable to another in ascending order. - * - * @param obj the mutable to compare to + * + * @param obj + * the mutable to compare to * @return negative if this is less, zero if equal, positive if greater + * @throws ClassCastException if the argument is not a MutableInt */ public int compareTo(Object obj) { MutableInt other = (MutableInt) obj; @@ -146,7 +155,7 @@ public int compareTo(Object obj) { /** * Returns the String value of this mutable. - * + * * @return the mutable value as a string */ public String toString() { diff --git a/src/java/org/apache/commons/lang/mutable/MutableLong.java b/src/java/org/apache/commons/lang/mutable/MutableLong.java index 20676ab0e..ff7c5e4c0 100755 --- a/src/java/org/apache/commons/lang/mutable/MutableLong.java +++ b/src/java/org/apache/commons/lang/mutable/MutableLong.java @@ -13,18 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.commons.lang.mutable; -import java.io.Serializable; - /** - * A mutable long. + * A mutable long wrapper. * + * @see Long * @since 2.1 - * @version $Id: MutableLong.java,v 1.5 2004/10/01 17:12:29 ggregory Exp $ + * @version $Id: MutableLong.java,v 1.6 2004/10/08 19:45:46 ggregory Exp $ */ -public class MutableLong extends Number - implements Comparable, Mutable, Serializable { +public class MutableLong extends Number implements Comparable, Mutable { /** Serialization lock. */ private static final long serialVersionUID = 62986528375L; @@ -42,7 +41,8 @@ public MutableLong() { /** * Constructs a new MutableLong with the specified value. * - * @param value a value. + * @param value + * a value. */ public MutableLong(long value) { super(); @@ -52,8 +52,10 @@ public MutableLong(long value) { /** * Constructs a new MutableLong with the specified value. * - * @param value a value. - * @throws NullPointerException if the object is null + * @param value + * a value. + * @throws NullPointerException + * if the object is null */ public MutableLong(Number value) { super(); @@ -73,7 +75,8 @@ public Object getValue() { /** * Sets the value. * - * @param value the value to set + * @param value + * the value to set */ public void setValue(long value) { this.value = value; @@ -82,9 +85,12 @@ public void setValue(long value) { /** * Sets the value from any Number instance. * - * @param value the value to set - * @throws NullPointerException if the object is null - * @throws ClassCastException if the type is invalid + * @param value + * the value to set + * @throws NullPointerException + * if the object is null + * @throws ClassCastException + * if the type is not a {@link Number} */ public void setValue(Object value) { setValue(((Number) value).longValue()); @@ -109,34 +115,37 @@ public double doubleValue() { //----------------------------------------------------------------------- /** - * Checks if this object equals the specified object. - *

- * The object must be a MutableLong with the same value to be equal. - * - * @param obj the object to compare to - * @return true if equal + * Compares this object against the specified object. The result is true if and only if the argument + * is not null and is a MutableLong object that contains the same long + * value as this object. + * + * @param obj + * the object to compare with. + * @return true if the objects are the same; false otherwise. */ public boolean equals(Object obj) { if (obj instanceof MutableLong) { - return (value == ((MutableLong) obj).value); + return value == ((MutableLong) obj).longValue(); } return false; } /** * Returns a suitable hashcode for this mutable. - * + * * @return a suitable hashcode */ public int hashCode() { - return (int)(value ^ (value >>> 32)); + return (int) (value ^ (value >>> 32)); } /** * Compares this mutable to another in ascending order. - * - * @param obj the mutable to compare to + * + * @param obj + * the mutable to compare to * @return negative if this is less, zero if equal, positive if greater + * @throws ClassCastException if the argument is not a MutableLong */ public int compareTo(Object obj) { MutableLong other = (MutableLong) obj; @@ -146,7 +155,7 @@ public int compareTo(Object obj) { /** * Returns the String value of this mutable. - * + * * @return the mutable value as a string */ public String toString() { diff --git a/src/java/org/apache/commons/lang/mutable/MutableObject.java b/src/java/org/apache/commons/lang/mutable/MutableObject.java index f2b0b0cfb..016328e3c 100644 --- a/src/java/org/apache/commons/lang/mutable/MutableObject.java +++ b/src/java/org/apache/commons/lang/mutable/MutableObject.java @@ -13,18 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.commons.lang.mutable; import java.io.Serializable; /** - * A mutable Object. + * A mutable Object wrapper. * * @since 2.1 - * @version $Id: MutableObject.java,v 1.2 2004/09/01 17:42:56 ggregory Exp $ + * @version $Id: MutableObject.java,v 1.3 2004/10/08 19:45:46 ggregory Exp $ */ -public class MutableObject - implements Mutable, Serializable { +public class MutableObject implements Mutable, Serializable { /** Serialization lock. */ private static final long serialVersionUID = 86241875189L; @@ -42,7 +42,8 @@ public MutableObject() { /** * Constructs a new MutableObject with the specified value. * - * @param value a value. + * @param value + * a value. */ public MutableObject(Object value) { super(); @@ -62,7 +63,8 @@ public Object getValue() { /** * Sets the value. * - * @param value the value to set + * @param value + * the value to set */ public void setValue(Object value) { this.value = value; @@ -70,12 +72,14 @@ public void setValue(Object value) { //----------------------------------------------------------------------- /** - * Checks if this object equals the specified object. - *

- * The object must be a MutableObject with an equal value to be equal. - * - * @param obj the object to compare to - * @return true if equal + * Compares this object against the specified object. The result is true if and only if the argument + * is not null and is a MutableObject object that contains the same Object + * value as this object. + * + * @param obj + * the object to compare with. + * @return true if the objects are the same; false otherwise. + * @throws ClassCastException if the argument is not a MutableObject */ public boolean equals(Object obj) { if (obj instanceof MutableObject) { @@ -87,7 +91,7 @@ public boolean equals(Object obj) { /** * Returns a suitable hashcode for this mutable. - * + * * @return a suitable hashcode */ public int hashCode() { @@ -96,7 +100,7 @@ public int hashCode() { /** * Returns the String value of this mutable. - * + * * @return the mutable value as a string */ public String toString() { diff --git a/src/java/org/apache/commons/lang/mutable/MutableShort.java b/src/java/org/apache/commons/lang/mutable/MutableShort.java index c3d5234a7..1e6460af9 100755 --- a/src/java/org/apache/commons/lang/mutable/MutableShort.java +++ b/src/java/org/apache/commons/lang/mutable/MutableShort.java @@ -13,18 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.commons.lang.mutable; -import java.io.Serializable; - /** - * A mutable short. + * A mutable short wrapper. * + * @see Short * @since 2.1 - * @version $Id: MutableShort.java,v 1.5 2004/10/01 17:12:29 ggregory Exp $ + * @version $Id: MutableShort.java,v 1.6 2004/10/08 19:45:46 ggregory Exp $ */ -public class MutableShort extends Number - implements Comparable, Mutable, Serializable { +public class MutableShort extends Number implements Comparable, Mutable { /** Serialization lock. */ private static final long serialVersionUID = -2135791679L; @@ -42,7 +41,8 @@ public MutableShort() { /** * Constructs a new MutableShort with the specified value. * - * @param value a value. + * @param value + * a value. */ public MutableShort(short value) { super(); @@ -52,8 +52,10 @@ public MutableShort(short value) { /** * Constructs a new MutableShort with the specified value. * - * @param value a value. - * @throws NullPointerException if the object is null + * @param value + * a value. + * @throws NullPointerException + * if the object is null */ public MutableShort(Number value) { super(); @@ -73,7 +75,8 @@ public Object getValue() { /** * Sets the value. * - * @param value the value to set + * @param value + * the value to set */ public void setValue(short value) { this.value = value; @@ -82,9 +85,12 @@ public void setValue(short value) { /** * Sets the value from any Number instance. * - * @param value the value to set - * @throws NullPointerException if the object is null - * @throws ClassCastException if the type is invalid + * @param value + * the value to set + * @throws NullPointerException + * if the object is null + * @throws ClassCastException + * if the type is not a {@link Number} */ public void setValue(Object value) { setValue(((Number) value).shortValue()); @@ -113,23 +119,24 @@ public double doubleValue() { //----------------------------------------------------------------------- /** - * Checks if this object equals the specified object. - *

- * The object must be a MutableShort with the same value to be equal. - * - * @param obj the object to compare to - * @return true if equal + * Compares this object against the specified object. The result is true if and only if the argument + * is not null and is a MutableShort object that contains the same short + * value as this object. + * + * @param obj + * the object to compare with. + * @return true if the objects are the same; false otherwise. */ public boolean equals(Object obj) { if (obj instanceof MutableShort) { - return (value == ((MutableShort) obj).value); + return (value == ((MutableShort) obj).shortValue()); } return false; } /** * Returns a suitable hashcode for this mutable. - * + * * @return a suitable hashcode */ public int hashCode() { @@ -138,9 +145,11 @@ public int hashCode() { /** * Compares this mutable to another in ascending order. - * - * @param obj the mutable to compare to + * + * @param obj + * the mutable to compare to * @return negative if this is less, zero if equal, positive if greater + * @throws ClassCastException if the argument is not a MutableShort */ public int compareTo(Object obj) { MutableShort other = (MutableShort) obj; @@ -150,7 +159,7 @@ public int compareTo(Object obj) { /** * Returns the String value of this mutable. - * + * * @return the mutable value as a string */ public String toString() { diff --git a/src/java/org/apache/commons/lang/mutable/package.html b/src/java/org/apache/commons/lang/mutable/package.html new file mode 100644 index 000000000..9d18928df --- /dev/null +++ b/src/java/org/apache/commons/lang/mutable/package.html @@ -0,0 +1,39 @@ + + + + + + + +Provides typed mutable wrappers to primitive values and Object. +@since 2.1 + +