commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang/mutable package.html MutableFloat.java MutableByte.java MutableShort.java MutableObject.java MutableLong.java MutableInt.java MutableDouble.java Mutable.java
Date Fri, 08 Oct 2004 19:45:46 GMT
ggregory    2004/10/08 12:45:46

  Modified:    lang/src/java/org/apache/commons/lang/mutable
                        MutableFloat.java MutableByte.java
                        MutableShort.java MutableObject.java
                        MutableLong.java MutableInt.java MutableDouble.java
                        Mutable.java
  Added:       lang/src/java/org/apache/commons/lang/mutable package.html
  Log:
  - 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).
  
  Revision  Changes    Path
  1.6       +74 -29    jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableFloat.java
  
  Index: MutableFloat.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableFloat.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MutableFloat.java	1 Oct 2004 17:12:29 -0000	1.5
  +++ MutableFloat.java	8 Oct 2004 19:45:46 -0000	1.6
  @@ -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 <code>float</code>.
  + * A mutable <code>float</code> wrapper.
    * 
  + * @see Float
    * @since 2.1
    * @version $Id$
    */
  -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 @@
       /**
        * 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 @@
       /**
        * 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 @@
       /**
        * 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 @@
       /**
        * 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 @@
   
       /**
        * Checks whether the float value is the special NaN value.
  -     *
  +     * 
        * @return true if NaN
        */
       public boolean isNaN() {
  @@ -120,33 +126,71 @@
   
       /**
        * 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 <code>true</code>
if and only if the argument is
  +     * not <code>null</code> and is a <code>Float</code> object
that represents a <code>float</code> that has the
  +     * identical bit pattern to the bit pattern of the <code>float</code> 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.
  +     * <p>
  +     * Note that in most cases, for two instances of class <code>Float</code>,<code>f1</code>
and <code>f2</code>,
  +     * the value of <code>f1.equals(f2)</code> is <code>true</code>
if and only if <blockquote>
  +     * 
  +     * <pre>
  +     *   f1.floatValue() == f2.floatValue()
  +     * </pre>
  +     * 
  +     * </blockquote>
  +     * <p>
  +     * also has the value <code>true</code>. However, there are two exceptions:
  +     * <ul>
  +     * <li>If <code>f1</code> and <code>f2</code> both represent
<code>Float.NaN</code>, then the
  +     * <code>equals</code> method returns <code>true</code>, even
though <code>Float.NaN==Float.NaN</code> has
  +     * the value <code>false</code>.
  +     * <li>If <code>f1</code> represents <code>+0.0f</code>
while <code>f2</code> represents <code>-0.0f</code>,
  +     * or vice versa, the <code>equal</code> test has the value <code>false</code>,
even though
  +     * <code>0.0f==-0.0f</code> has the value <code>true</code>.
  +     * </ul>
  +     * This definition allows hashtables to operate properly.
  +     * 
  +     * @param obj
  +     *            the object to be compared
  +     * @return <code>true</code> if the objects are the same; <code>false</code>
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.
        * <p>
        * 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 @@
   
       /**
        * 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 @@
   
       /**
        * Returns the String value of this mutable.
  -     *
  +     * 
        * @return the mutable value as a string
        */
       public String toString() {
  
  
  
  1.6       +33 -24    jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableByte.java
  
  Index: MutableByte.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableByte.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MutableByte.java	1 Oct 2004 17:12:29 -0000	1.5
  +++ MutableByte.java	8 Oct 2004 19:45:46 -0000	1.6
  @@ -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;
  +package org.apache.commons.lang.mutable;
   
   /**
  - * A mutable <code>byte</code>.
  + * A mutable <code>byte</code> wrapper.
    * 
  + * @see Byte
    * @since 2.1
    * @version $Id$
    */
  -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 @@
       /**
        * 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 @@
       /**
        * 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 @@
       /**
        * 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 @@
       /**
        * 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 @@
   
       //-----------------------------------------------------------------------
       /**
  -     * Checks if this object equals the specified object.
  -     * <p>
  -     * 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 <code>true</code>
if and only if the argument
  +     * is not <code>null</code> and is a <code>MutableByte</code>
object that contains the same <code>byte</code>
  +     * value as this object.
  +     * 
  +     * @param obj
  +     *            the object to compare with.
  +     * @return <code>true</code> if the objects are the same; <code>false</code>
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 @@
   
       /**
        * 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 @@
   
       /**
        * Returns the String value of this mutable.
  -     *
  +     * 
        * @return the mutable value as a string
        */
       public String toString() {
  
  
  
  1.6       +33 -24    jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableShort.java
  
  Index: MutableShort.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableShort.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MutableShort.java	1 Oct 2004 17:12:29 -0000	1.5
  +++ MutableShort.java	8 Oct 2004 19:45:46 -0000	1.6
  @@ -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;
  +package org.apache.commons.lang.mutable;
   
   /**
  - * A mutable <code>short</code>.
  + * A mutable <code>short</code> wrapper.
    * 
  + * @see Short
    * @since 2.1
    * @version $Id$
    */
  -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 @@
       /**
        * 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 @@
       /**
        * 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 @@
       /**
        * 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 @@
       /**
        * 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 @@
   
       //-----------------------------------------------------------------------
       /**
  -     * Checks if this object equals the specified object.
  -     * <p>
  -     * 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 <code>true</code>
if and only if the argument
  +     * is not <code>null</code> and is a <code>MutableShort</code>
object that contains the same <code>short</code>
  +     * value as this object.
  +     * 
  +     * @param obj
  +     *                  the object to compare with.
  +     * @return <code>true</code> if the objects are the same; <code>false</code>
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 @@
   
       /**
        * 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 @@
   
       /**
        * Returns the String value of this mutable.
  -     *
  +     * 
        * @return the mutable value as a string
        */
       public String toString() {
  
  
  
  1.3       +18 -14    jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableObject.java
  
  Index: MutableObject.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableObject.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MutableObject.java	1 Sep 2004 17:42:56 -0000	1.2
  +++ MutableObject.java	8 Oct 2004 19:45:46 -0000	1.3
  @@ -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 <code>Object</code>.
  + * A mutable <code>Object</code> wrapper.
    * 
    * @since 2.1
    * @version $Id$
    */
  -public class MutableObject
  -        implements Mutable, Serializable {
  +public class MutableObject implements Mutable, Serializable {
   
       /** Serialization lock. */
       private static final long serialVersionUID = 86241875189L;
  @@ -42,7 +42,8 @@
       /**
        * 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 @@
       /**
        * 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 @@
   
       //-----------------------------------------------------------------------
       /**
  -     * Checks if this object equals the specified object.
  -     * <p>
  -     * 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 <code>true</code>
if and only if the argument
  +     * is not <code>null</code> and is a <code>MutableObject</code>
object that contains the same <code>Object</code>
  +     * value as this object.
  +     * 
  +     * @param obj
  +     *            the object to compare with.
  +     * @return <code>true</code> if the objects are the same; <code>false</code>
otherwise.
  +     * @throws ClassCastException if the argument is not a MutableObject
        */
       public boolean equals(Object obj) {
           if (obj instanceof MutableObject) {
  @@ -87,7 +91,7 @@
   
       /**
        * Returns a suitable hashcode for this mutable.
  -     *
  +     * 
        * @return a suitable hashcode
        */
       public int hashCode() {
  @@ -96,7 +100,7 @@
   
       /**
        * Returns the String value of this mutable.
  -     *
  +     * 
        * @return the mutable value as a string
        */
       public String toString() {
  
  
  
  1.6       +34 -25    jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableLong.java
  
  Index: MutableLong.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableLong.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MutableLong.java	1 Oct 2004 17:12:29 -0000	1.5
  +++ MutableLong.java	8 Oct 2004 19:45:46 -0000	1.6
  @@ -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;
  +package org.apache.commons.lang.mutable;
   
   /**
  - * A mutable <code>long</code>.
  + * A mutable <code>long</code> wrapper.
    * 
  + * @see Long
    * @since 2.1
    * @version $Id$
    */
  -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 @@
       /**
        * 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 @@
       /**
        * 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 @@
       /**
        * 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 @@
       /**
        * 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 @@
   
       //-----------------------------------------------------------------------
       /**
  -     * Checks if this object equals the specified object.
  -     * <p>
  -     * 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 <code>true</code>
if and only if the argument
  +     * is not <code>null</code> and is a <code>MutableLong</code>
object that contains the same <code>long</code>
  +     * value as this object.
  +     * 
  +     * @param obj
  +     *            the object to compare with.
  +     * @return <code>true</code> if the objects are the same; <code>false</code>
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 @@
   
       /**
        * Returns the String value of this mutable.
  -     *
  +     * 
        * @return the mutable value as a string
        */
       public String toString() {
  
  
  
  1.4       +33 -24    jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableInt.java
  
  Index: MutableInt.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableInt.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MutableInt.java	1 Oct 2004 17:12:29 -0000	1.3
  +++ MutableInt.java	8 Oct 2004 19:45:46 -0000	1.4
  @@ -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;
  +package org.apache.commons.lang.mutable;
   
   /**
  - * A mutable <code>int</code>.
  + * A mutable <code>int</code> wrapper.
    * 
  + * @see Integer
    * @since 2.1
    * @version $Id$
    */
  -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 @@
       /**
        * 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 @@
       /**
        * 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 @@
       /**
        * 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 @@
       /**
        * 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 @@
   
       //-----------------------------------------------------------------------
       /**
  -     * Checks if this object equals the specified object.
  -     * <p>
  -     * 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 <code>true</code>
if and only if the argument is
  +     * not <code>null</code> and is an <code>MutableInt</code>
object that contains the same <code>int</code> value
  +     * as this object.
  +     * 
  +     * @param obj
  +     *                  the object to compare with.
  +     * @return <code>true</code> if the objects are the same; <code>false</code>
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 @@
   
       /**
        * 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 @@
   
       /**
        * Returns the String value of this mutable.
  -     *
  +     * 
        * @return the mutable value as a string
        */
       public String toString() {
  
  
  
  1.5       +57 -30    jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableDouble.java
  
  Index: MutableDouble.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableDouble.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MutableDouble.java	7 Jul 2004 23:50:28 -0000	1.4
  +++ MutableDouble.java	8 Oct 2004 19:45:46 -0000	1.5
  @@ -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 <code>double</code>.
  + * A mutable <code>double</code> wrapper.
    * 
  + * @see Double
    * @since 2.1
    * @version $Id$
    */
  -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 @@
       /**
        * 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 @@
       /**
        * 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 @@
       /**
        * 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 @@
       /**
        * 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 @@
   
       /**
        * Checks whether the double value is the special NaN value.
  -     *
  +     * 
        * @return true if NaN
        */
       public boolean isNaN() {
  @@ -120,7 +126,7 @@
   
       /**
        * Checks whether the double value is infinite.
  -     *
  +     * 
        * @return true if infinite
        */
       public boolean isInfinite() {
  @@ -129,36 +135,57 @@
   
       //-----------------------------------------------------------------------
       /**
  -     * Checks if this object equals the specified object.
  +     * Compares this object against the specified object. The result is <code>true</code>
if and only if the argument
  +     * is not <code>null</code> and is a <code>Double</code> 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
  +     * <code>double</code> 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.
        * <p>
  -     * 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 <code>Double</code>,<code>d1</code>
and <code>d2</code>,
  +     * the value of <code>d1.equals(d2)</code> is <code>true</code>
if and only if <blockquote>
  +     * 
  +     * <pre>
  +     *   d1.doubleValue()&nbsp;== d2.doubleValue()
  +     * </pre>
  +     * 
  +     * </blockquote>
  +     * <p>
  +     * also has the value <code>true</code>. However, there are two exceptions:
  +     * <ul>
  +     * <li>If <code>d1</code> and <code>d2</code> both represent
<code>Double.NaN</code>, then the
  +     * <code>equals</code> method returns <code>true</code>, even
though <code>Double.NaN==Double.NaN</code> has
  +     * the value <code>false</code>.
  +     * <li>If <code>d1</code> represents <code>+0.0</code>
while <code>d2</code> represents <code>-0.0</code>,
  +     * or vice versa, the <code>equal</code> test has the value <code>false</code>,
even though
  +     * <code>+0.0==-0.0</code> has the value <code>true</code>.
This allows hashtables to operate properly.
  +     * </ul>
  +     * 
  +     * @param obj
  +     *            the object to compare with.
  +     * @return <code>true</code> if the objects are the same; <code>false</code>
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 @@
   
       /**
        * Returns the String value of this mutable.
  -     *
  +     * 
        * @return the mutable value as a string
        */
       public String toString() {
  
  
  
  1.3       +16 -15    jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/Mutable.java
  
  Index: Mutable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/Mutable.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Mutable.java	5 Jul 2004 22:12:22 -0000	1.2
  +++ Mutable.java	8 Oct 2004 19:45:46 -0000	1.3
  @@ -13,20 +13,18 @@
    * 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.
    * <p>
  - * <code>Mutable</code> is used as a generic interface to the implementations
  - * in this package.
  + * <code>Mutable</code> is used as a generic interface to the implementations
in this package.
    * <p>
  - * 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$
  @@ -35,17 +33,20 @@
   
       /**
        * 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);
   
  
  
  
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/package.html
  
  Index: package.html
  ===================================================================
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <html>
  <head>
  <!--
  
  Copyright 2002-2004 The Apache Software Foundation.
  
   
  
  Licensed under the Apache License, Version 2.0 (the "License");
  
  you may not use this file except in compliance with the License.
  
  You may obtain a copy of the License at
  
  
  
       http://www.apache.org/licenses/LICENSE-2.0
  
  
  
  Unless required by applicable law or agreed to in writing, software
  
  distributed under the License is distributed on an "AS IS" BASIS,
  
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  
  See the License for the specific language governing permissions and
  
  limitations under the License.
  
  -->
    <title></title>
  </head>
  <body>
  Provides typed mutable wrappers to primitive values and Object.
  @since 2.1
  </body>
  </html>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message