bayard      2004/06/12 23:18:49

  Modified:    lang/src/java/org/apache/commons/lang/mutable
                        MutableByte.java MutableDouble.java
                        MutableFloat.java MutableInteger.java
                        MutableLong.java MutableNumber.java
                        MutableShort.java
  Log:
  simplified code by moving a chunk of the functionality up into the superclass, 
MutableNumber. Still important that setValue turns the Number into the correct type 
however, so that method may not go up into the superclass
  
  Revision  Changes    Path
  1.2       +4 -28     
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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MutableByte.java  11 Jun 2004 02:26:32 -0000      1.1
  +++ MutableByte.java  13 Jun 2004 06:18:49 -0000      1.2
  @@ -24,44 +24,20 @@
   public class MutableByte extends MutableNumber {
   
       /**
  -     * Internal value.
  -     */
  -    private byte value;
  -    
  -    /**
        * Instantiates with the specified value
        * @param value a value.
        */
       public MutableByte(byte value) {
           super();
  -        this.value = value;
  +        setValue(new Byte(value));
       }
   
       public void setValue(byte value) {
  -        this.value = value;
  -    }
  -
  -    public long longValue() {
  -        return this.value;
  -    }
  -
  -    public double doubleValue() {
  -        return this.value;
  -    }
  -
  -    public int intValue() {
  -        return this.value;
  -    }
  -
  -    /**
  -     * @return a <code>Byte</code>
  -     */
  -    public Object getValue() {
  -        return new Byte(this.value);
  +        setValue(new Byte(value));
       }
   
       /**
  -     * @param value a <code>Byte</code>
  +     * @param value a <code>Number</code>
        */
       public void setValue(Object value) {
           setValue(((Number)value).byteValue());
  
  
  
  1.2       +7 -25     
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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MutableDouble.java        11 Jun 2004 02:26:32 -0000      1.1
  +++ MutableDouble.java        13 Jun 2004 06:18:49 -0000      1.2
  @@ -16,7 +16,7 @@
   package org.apache.commons.lang.mutable;
   
   /**
  - * A mutable <code>Double</code>
  + * A mutable <code>Double</code>.
    * 
    * @since 2.1
    * @version $Id$
  @@ -24,39 +24,21 @@
   public class MutableDouble extends MutableNumber {
   
       /**
  -     * Internal value.
  -     */
  -    private double value;
  -
  -    /**
        * Instantiates with the specified value
        * @param value a value.
        */
       public MutableDouble(double value) {
           super();
  -        this.value = value;
  +        setValue(new Double(value));
       }
   
       public void setValue(double value) {
  -        this.value = value;
  -    }
  -
  -    public double doubleValue() {
  -        return this.value;
  -    }
  -
  -    public long longValue() {
  -        return (long)this.value;
  -    }
  -
  -    public int intValue() {
  -        return (int)this.value;
  -    }
  -
  -    public Object getValue() {
  -        return new Double(this.value);
  +        setValue(new Double(value));
       }
   
  +    /**
  +     * @param value a <code>Number</code>
  +     */
       public void setValue(Object value) {
           setValue(((Number)value).doubleValue());
       }
  
  
  
  1.2       +7 -26     
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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MutableFloat.java 11 Jun 2004 02:26:32 -0000      1.1
  +++ MutableFloat.java 13 Jun 2004 06:18:49 -0000      1.2
  @@ -16,7 +16,7 @@
   package org.apache.commons.lang.mutable;
   
   /**
  - * A mutable <code>Float</code>
  + * A mutable <code>Float</code>.
    * 
    * @since 2.1
    * @version $Id$
  @@ -24,40 +24,21 @@
   public class MutableFloat extends MutableNumber {
   
       /**
  -     * Internal value.
  -     */
  -    private float value;
  -
  -    /**
        * Instantiates with the specified value
  -     * 
        * @param value a value.
        */
       public MutableFloat(float value) {
           super();
  -        this.value = value;
  +        setValue(new Float(value));
       }
   
       public void setValue(float value) {
  -        this.value = value;
  -    }
  -
  -    public double doubleValue() {
  -        return this.value;
  -    }
  -
  -    public int intValue() {
  -        return (int)this.value;
  -    }
  -
  -    public long longValue() {
  -        return (long)this.value;
  -    }
  -
  -    public Object getValue() {
  -        return new Float(this.value);
  +        setValue(new Float(value));
       }
   
  +    /**
  +     * @param value a <code>Number</code>
  +     */
       public void setValue(Object value) {
           setValue(((Number)value).floatValue());
       }
  
  
  
  1.2       +6 -25     
jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableInteger.java
  
  Index: MutableInteger.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableInteger.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MutableInteger.java       11 Jun 2004 02:26:32 -0000      1.1
  +++ MutableInteger.java       13 Jun 2004 06:18:49 -0000      1.2
  @@ -24,40 +24,21 @@
   public class MutableInteger extends MutableNumber {
   
       /**
  -     * Internal value.
  -     */
  -    private int value;
  -
  -    /**
        * Instantiates with the specified value
  -     * 
        * @param value a value.
        */
       public MutableInteger(int value) {
           super();
  -        this.value = value;
  +        setValue(new Integer(value));
       }
   
       public void setValue(int value) {
  -        this.value = value;
  -    }
  -
  -    public double doubleValue() {
  -        return this.value;
  -    }
  -
  -    public long longValue() {
  -        return this.value;
  -    }
  -
  -    public int intValue() {
  -        return this.value;
  -    }
  -
  -    public Object getValue() {
  -        return new Float(this.value);
  +        setValue(new Integer(value));
       }
   
  +    /**
  +     * @param value a <code>Number</code>
  +     */
       public void setValue(Object value) {
           setValue(((Number)value).intValue());
       }
  
  
  
  1.2       +7 -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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MutableLong.java  11 Jun 2004 02:26:32 -0000      1.1
  +++ MutableLong.java  13 Jun 2004 06:18:49 -0000      1.2
  @@ -16,7 +16,7 @@
   package org.apache.commons.lang.mutable;
   
   /**
  - * A mutable <code>Long</code>
  + * A mutable <code>Long</code>.
    * 
    * @since 2.1
    * @version $Id$
  @@ -24,39 +24,21 @@
   public class MutableLong extends MutableNumber {
   
       /**
  -     * Internal value.
  -     */
  -    private long value;
  -
  -    /**
        * Instantiates with the specified value
        * @param value a value.
        */
       public MutableLong(long value) {
           super();
  -        setValue(value);
  +        setValue(new Long(value));
       }
   
       public void setValue(long value) {
  -        this.value = value;
  -    }
  -
  -    public double doubleValue() {
  -        return this.value;
  -    }
  -
  -    public long longValue() {
  -        return this.value;
  -    }
  -
  -    public int intValue() {
  -        return (int)this.value;
  -    }
  -
  -    public Object getValue() {
  -        return new Long(this.value);
  +        setValue(new Long(value));
       }
   
  +    /**
  +     * @param value a <code>Number</code>
  +     */
       public void setValue(Object value) {
           setValue(((Number)value).longValue());
       }
  
  
  
  1.2       +36 -5     
jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableNumber.java
  
  Index: MutableNumber.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableNumber.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MutableNumber.java        11 Jun 2004 02:26:32 -0000      1.1
  +++ MutableNumber.java        13 Jun 2004 06:18:49 -0000      1.2
  @@ -28,18 +28,49 @@
       extends Number
       implements Comparable, Mutable, Serializable {
   
  -    MutableNumber() {
  +    private Number value;
  +
  +    public MutableNumber() {
           super();
       }
   
  +    /**
  +     * @param a <code>Number</code>
  +     */
  +    protected void setValue(Number value) {
  +        this.value = value;
  +    }
  +
       // ----------------------------------------------------------------
       // Number overrides
       // ----------------------------------------------------------------
   
       public float floatValue() {
  -        return (float)doubleValue();
  +        return this.value.floatValue();
       }
       
  +    public long longValue() {
  +        return this.value.longValue();
  +    }
  +
  +    public double doubleValue() {
  +        return this.value.doubleValue();
  +    }
  +
  +    public int intValue() {
  +        return this.value.intValue();
  +    }
  +
  +    // ----------------------------------------------------------------
  +    // Mutable overrides
  +    // ----------------------------------------------------------------
  +
  +    /**
  +     * @return a <code>Number</code>
  +     */
  +    public Object getValue() {
  +        return this.value;
  +    }
       // ----------------------------------------------------------------
       // Object overrides
       // ----------------------------------------------------------------
  @@ -49,7 +80,7 @@
       }
   
       public int hashCode() {
  -        return super.hashCode();
  +        return this.value.hashCode();
       }
   
       /**
  @@ -61,7 +92,7 @@
        * @see #compareTo(Object)
        */
       public boolean equals(Object obj) {
  -        return super.equals(obj);
  +        return this.value.equals(obj);
       }
   
       // ----------------------------------------------------------------
  
  
  
  1.2       +7 -25     
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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MutableShort.java 11 Jun 2004 02:26:32 -0000      1.1
  +++ MutableShort.java 13 Jun 2004 06:18:49 -0000      1.2
  @@ -16,7 +16,7 @@
   package org.apache.commons.lang.mutable;
   
   /**
  - * A mutable <code>Short</code>
  + * A mutable <code>Short</code>.
    * 
    * @since 2.1
    * @version $Id$
  @@ -24,39 +24,21 @@
   public class MutableShort extends MutableNumber {
   
       /**
  -     * Internal value.
  -     */
  -    private short value;
  -
  -    /**
        * Instantiates with the specified value
        * @param value a value.
        */
       public MutableShort(short value) {
           super();
  -        this.value = value;
  +        setValue(new Short(value));
       }
   
       public void setValue(short value) {
  -        this.value = value;
  -    }
  -
  -    public double doubleValue() {
  -        return this.value;
  -    }
  -
  -    public int intValue() {
  -        return this.value;
  -    }
  -
  -    public long longValue() {
  -        return this.value;
  -    }
  -
  -    public Object getValue() {
  -        return new Short(this.value);
  +        setValue(new Short(value));
       }
   
  +    /**
  +     * @param value a <code>Number</code>
  +     */
       public void setValue(Object value) {
           setValue(((Number)value).shortValue());
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to