jmcnally    2002/09/23 21:50:08

  Modified:    src/java/org/apache/torque/om NumberKey.java
  Log:
  patch by J. Russell Smyth Issue# TRQ44
  
  add a NumberKey(Number key) constructor and
  added the following convenience methods
  
  public byte byteValue()
  public int intValue()
  public long longValue()
  public float floatValue()
  public double doubleValue()
  
  Revision  Changes    Path
  1.12      +97 -1     
jakarta-turbine-torque/src/java/org/apache/torque/om/NumberKey.java
  
  Index: NumberKey.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/om/NumberKey.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- NumberKey.java    31 Jul 2002 02:04:21 -0000      1.11
  +++ NumberKey.java    24 Sep 2002 04:50:08 -0000      1.12
  @@ -118,6 +118,15 @@
       }
   
       /**
  +     * Creates a NumberKey equivalent to <code>key</code>.
  +     * Convenience only. 
  +     */
  +    public NumberKey(Number key)
  +    {
  +        this.key = new BigDecimal(key.toString());
  +    }
  +
  +    /**
        * Sets the internal representation using a String representation
        * of a number
        */
  @@ -224,5 +233,92 @@
               return key.toString();
           }
           return "";
  +    }
  +
  +    /** 
  +     * Returns the value of this NumberKey as a long. This value is subject
  +     * to the conversion rules set out in 
  +     * {@link java.math.BigDecimal.intValue()}
  +     *
  +     * @return the NumberKey converted to a long
  +     */
  +    public byte byteValue()
  +    {
  +        return getBigDecimal().byteValue();
  +    }
  +
  +    /** 
  +     * Returns the value of this NumberKey as an int. This value is subject
  +     * to the conversion rules set out in 
  +     * {@link java.math.BigDecimal.intValue()}, importantly any fractional part
  +     * will be discarded and if the underlying value is too big to fit in an 
  +     * int, only the low-order 32 bits are returned. Note that this 
  +     * conversion can lose information about the overall magnitude and 
  +     * precision of the NumberKey value as well as return a result with the 
  +     * opposite sign.
  +     * @return the NumberKey converted to an int
  +     */
  +    public int intValue()
  +    {
  +        return getBigDecimal().intValue();
  +    }
  +
  +    /** 
  +     * Returns the value of this NumberKey as a short. This value is subject
  +     * to the conversion rules set out in 
  +     * {@link java.math.BigDecimal.intValue()}, importantly any fractional part
  +     *  will be discarded and if the underlying value is too big to fit 
  +     * in a long, only the low-order 64 bits are returned. Note that this 
  +     * conversion can lose information about the overall magnitude and 
  +     * precision of the NumberKey value as well as return a result with the 
  +     * opposite sign.
  +     *
  +     * @return the NumberKey converted to a short
  +     */
  +    public short shortValue()
  +    {
  +        return getBigDecimal().shortValue();
  +    }
  +
  +    /** 
  +     * Returns the value of this NumberKey as a long. This value is subject
  +     * to the conversion rules set out in 
  +     * {@link java.math.BigDecimal.intValue()}
  +     *
  +     * @return the NumberKey converted to a long
  +     */
  +    public long longValue()
  +    {
  +        return getBigDecimal().longValue();
  +    }
  +
  +    /** 
  +     * Returns the value of this NumberKey as a float. This value is subject to
  +     * the conversion rules set out in 
  +     * {@link java.math.BigDecimal.floatValue()}, most importantly if the 
  +     * underlying value has too great a magnitude to represent as a 
  +     * float, it will be converted to Float.NEGATIVE_INFINITY 
  +     * or Float.POSITIVE_INFINITY as appropriate.
  +     *
  +     * @return the NumberKey converted to a float
  +     */
  +    public float floatValue()
  +    {
  +        return getBigDecimal().floatValue();
  +    }
  +
  +    /** 
  +     * Returns the value of this NumberKey as a double. This value is subject
  +     * to the conversion rules set out in 
  +     * {@link java.math.BigDecimal.doubleValue()}, most importantly if the 
  +     * underlying value has too great a magnitude to represent as a 
  +     * double, it will be converted to Double.NEGATIVE_INFINITY 
  +     * or Double.POSITIVE_INFINITY as appropriate.
  +     *
  +     * @return the NumberKey converted to a double
  +     */
  +    public double doubleValue()
  +    {
  +        return getBigDecimal().doubleValue();
       }
   }
  
  
  

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

Reply via email to