org.apache.torque.om
Class NumberKey

java.lang.Object
  extended by org.apache.torque.om.ObjectKey
      extended by org.apache.torque.om.SimpleKey
          extended by org.apache.torque.om.NumberKey
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable

public class NumberKey
extends SimpleKey

This class can be used as an ObjectKey to uniquely identify an object within an application where the id consists of a single entity such a GUID or the value of a db row's primary key.

Version:
$Id: NumberKey.java 473821 2006-11-11 22:37:25Z tv $
Author:
John McNally, Stephen Haberman, Runako Godfrey
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.torque.om.ObjectKey
key
 
Constructor Summary
NumberKey()
          Creates a NumberKey whose internal representation will be set later, through a set method
NumberKey(java.math.BigDecimal key)
          Creates a NumberKey equivalent to key.
NumberKey(double key)
          Creates a NumberKey equivalent to key.
NumberKey(int key)
          Creates a NumberKey equivalent to key.
NumberKey(long key)
          Creates a NumberKey equivalent to key.
NumberKey(java.lang.Number key)
          Creates a NumberKey equivalent to key.
NumberKey(NumberKey key)
          Creates a NumberKey equivalent to key.
NumberKey(java.lang.String key)
          Creates a NumberKey equivalent to key.
 
Method Summary
 byte byteValue()
          Returns the value of this NumberKey as a byte.
 int compareTo(java.lang.Object o)
          Implements the compareTo method.
 double doubleValue()
          Returns the value of this NumberKey as a double.
 boolean equals(java.lang.Object keyObj)
          Two ObjectKeys that both contain null values are not considered equal.
 float floatValue()
          Returns the value of this NumberKey as a float.
 java.math.BigDecimal getBigDecimal()
          Access the underlying BigDecimal object.
 int hashCode()
          Returns the hashcode of the underlying value (key), if key is not null.
 int intValue()
          Returns the value of this NumberKey as an int.
 long longValue()
          Returns the value of this NumberKey as a long.
 void setValue(java.math.BigDecimal key)
          Sets the underlying object
 void setValue(NumberKey key)
          Sets the internal representation to the same object used by key.
 void setValue(java.lang.String key)
          Sets the internal representation using a String representation of a number
 short shortValue()
          Returns the value of this NumberKey as a short.
 java.lang.String toString()
          Invokes the toString() method on the object.
 
Methods inherited from class org.apache.torque.om.SimpleKey
keyFor, keyFor, keyFor, keyFor, keyFor, keyFor, keyFor, keyFor, keyFor, keyFor
 
Methods inherited from class org.apache.torque.om.ObjectKey
appendTo, getValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NumberKey

public NumberKey()
Creates a NumberKey whose internal representation will be set later, through a set method


NumberKey

public NumberKey(java.lang.String key)
Creates a NumberKey equivalent to key.

Parameters:
key - the key value

NumberKey

public NumberKey(java.math.BigDecimal key)
Creates a NumberKey equivalent to key.

Parameters:
key - the key value

NumberKey

public NumberKey(NumberKey key)
Creates a NumberKey equivalent to key.

Parameters:
key - the key value

NumberKey

public NumberKey(long key)
Creates a NumberKey equivalent to key.

Parameters:
key - the key value

NumberKey

public NumberKey(double key)
Creates a NumberKey equivalent to key.

Parameters:
key - the key value

NumberKey

public NumberKey(int key)
Creates a NumberKey equivalent to key. Convenience only.

Parameters:
key - the key value

NumberKey

public NumberKey(java.lang.Number key)
Creates a NumberKey equivalent to key. Convenience only.

Parameters:
key - the key value
Method Detail

setValue

public void setValue(java.lang.String key)
              throws java.lang.NumberFormatException
Sets the internal representation using a String representation of a number

Specified by:
setValue in class ObjectKey
Parameters:
key - the key value
Throws:
java.lang.NumberFormatException - if key is not a valid number

setValue

public void setValue(java.math.BigDecimal key)
Sets the underlying object

Parameters:
key - the key value

setValue

public void setValue(NumberKey key)
Sets the internal representation to the same object used by key.

Parameters:
key - the key value

getBigDecimal

public java.math.BigDecimal getBigDecimal()
Access the underlying BigDecimal object.

Returns:
a BigDecimal value

equals

public boolean equals(java.lang.Object keyObj)
Two ObjectKeys that both contain null values are not considered equal.

Overrides:
equals in class java.lang.Object
Parameters:
keyObj - the key to compare values to
Returns:
whether the two objects are equal

hashCode

public int hashCode()
Description copied from class: ObjectKey
Returns the hashcode of the underlying value (key), if key is not null. Otherwise calls Object.hashCode()

Overrides:
hashCode in class ObjectKey
Returns:
a hash code based on the value

compareTo

public int compareTo(java.lang.Object o)
Description copied from class: ObjectKey
Implements the compareTo method.

Specified by:
compareTo in interface java.lang.Comparable
Overrides:
compareTo in class ObjectKey
Parameters:
o - the comparison value
Returns:
a numeric comparison of the two values

toString

public java.lang.String toString()
Invokes the toString() method on the object. An empty string is returned is the value is null.

Overrides:
toString in class java.lang.Object
Returns:
a String representation of the key value

byteValue

public byte byteValue()
Returns the value of this NumberKey as a byte. This value is subject to the conversion rules set out in Number.byteValue()

Returns:
the NumberKey converted to a byte

intValue

public int intValue()
Returns the value of this NumberKey as an int. This value is subject to the conversion rules set out in 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.

Returns:
the NumberKey converted to an int

shortValue

public short shortValue()
Returns the value of this NumberKey as a short. This value is subject to the conversion rules set out in 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.

Returns:
the NumberKey converted to a short

longValue

public long longValue()
Returns the value of this NumberKey as a long. This value is subject to the conversion rules set out in BigDecimal.intValue()

Returns:
the NumberKey converted to a long

floatValue

public float floatValue()
Returns the value of this NumberKey as a float. This value is subject to the conversion rules set out in 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.

Returns:
the NumberKey converted to a float

doubleValue

public double doubleValue()
Returns the value of this NumberKey as a double. This value is subject to the conversion rules set out in 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.

Returns:
the NumberKey converted to a double


Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.