org.web3d.vrtp.datatypes
Class UnsignedShort

java.lang.Object
  |
  +--org.web3d.vrtp.datatypes.PrimitiveNumber
        |
        +--org.web3d.vrtp.datatypes.UnsignedShort
All Implemented Interfaces:
ArithmeticIF, java.lang.Cloneable, java.lang.Comparable, Primitive, java.io.Serializable

public class UnsignedShort
extends PrimitiveNumber
implements Primitive, ArithmeticIF

UnsignedShort Represents an unsigned short value (0-65535), which takes up 16 bits of storage. This cannot take on a negative value.

Author:
Don McGregor
See Also:
Serialized Form

Field Summary
(package private) static int MAX_UNSIGNED_SHORT_VALUE
           
static int SHORT_LENGTH
           
 
Constructor Summary
UnsignedShort()
          Contructs a new UnsignedShort object and intializes its value to 0.
UnsignedShort(byte pData)
          Constructs an UnsignedShort object from a signed byte, throws an exception if the paraneter is out of range.
UnsignedShort(int pData)
          Constructs an UnsignedShort object from a short, throws an exception if the parameter is out of range.
UnsignedShort(short pData)
          Constructs an UnsignedShort object from a short, throws an exception if the parameter is out of range.
UnsignedShort(java.lang.String pData)
          Constructor, takes string value
 
Method Summary
 void add(int pValue)
          Add the given amount to the data
 java.lang.Object clone()
          create a copy of the object that shares no data members with the original.
 int compareTo(java.lang.Object obj)
          Used for sorting, like strcmp.
 void decrement()
          subtract one from the value
 double doubleValue()
          Returns the current value of this object as a double float, after conversion.
 boolean equals(java.lang.Object obj)
          Compare for equality.
 float floatValue()
          Returns a the current value of this object as a float, after conversion.
 int getSize()
          size of this instance when serialized to binary format
 int hashCode()
          Hashcode.
 void increment()
          add one to the value
 void initializeWithBinary(byte[] pBinaryData, int offset)
          Initialize an already-existing object with binary data.
 void initializeWithString(java.lang.String pStringData)
          Initialize the object with the string data given.
 int intValue()
          Returns the current value of this object as an int, after conversion.
 long longValue()
          Returns the current value of this object as a long, after conversion.
 void serialize(java.io.DataOutputStream pOutputStream)
          Yeech.
 java.lang.String stringValue()
          return string representation of this value.
 void subtract(int pValue)
          subtract the given amount from the value
 java.lang.String toString()
          Returns a String object representing this UnsignedShort value.
 
Methods inherited from class org.web3d.vrtp.datatypes.PrimitiveNumber
byteValue, shortValue
 
Methods inherited from class java.lang.Object
, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_UNSIGNED_SHORT_VALUE

static final int MAX_UNSIGNED_SHORT_VALUE

SHORT_LENGTH

public static final int SHORT_LENGTH
Constructor Detail

UnsignedShort

public UnsignedShort(java.lang.String pData)
Constructor, takes string value

UnsignedShort

public UnsignedShort()
Contructs a new UnsignedShort object and intializes its value to 0.

UnsignedShort

public UnsignedShort(byte pData)
Constructs an UnsignedShort object from a signed byte, throws an exception if the paraneter is out of range.
Parameters:
pData - >=0
Throws:
java.lang.RuntimeException - if pData is out of range

UnsignedShort

public UnsignedShort(short pData)
Constructs an UnsignedShort object from a short, throws an exception if the parameter is out of range.
Parameters:
pData - >=0, <=MAX_UNSIGNED_SHORT_VALUE
Throws:
java.lang.RuntimeException - if the parameter is out of range

UnsignedShort

public UnsignedShort(int pData)
Constructs an UnsignedShort object from a short, throws an exception if the parameter is out of range.
Parameters:
pData - >=0, <=MAX_UNSIGNED_SHORT_VALUE
Throws:
java.lang.RuntimeException - if the parameter is out of range
Method Detail

getSize

public int getSize()
size of this instance when serialized to binary format
Specified by:
getSize in interface Primitive

stringValue

public java.lang.String stringValue()
return string representation of this value. This has major problems with truncation and needs to be fixed.

initializeWithBinary

public void initializeWithBinary(byte[] pBinaryData,
                                 int offset)
Initialize an already-existing object with binary data. the object must recoginize the binary data starting at the given offset.
Specified by:
initializeWithBinary in interface Primitive

initializeWithString

public void initializeWithString(java.lang.String pStringData)
Initialize the object with the string data given.
Specified by:
initializeWithString in interface Primitive

doubleValue

public double doubleValue()
Returns the current value of this object as a double float, after conversion.
Overrides:
doubleValue in class PrimitiveNumber
Returns:
the current value of this object as a double float

floatValue

public float floatValue()
Returns a the current value of this object as a float, after conversion.
Overrides:
floatValue in class PrimitiveNumber
Returns:
the current value of this object as a float

intValue

public int intValue()
Returns the current value of this object as an int, after conversion.
Overrides:
intValue in class PrimitiveNumber
Returns:
the current value of this object as an int

longValue

public long longValue()
Returns the current value of this object as a long, after conversion.
Overrides:
longValue in class PrimitiveNumber
Returns:
the current value of this object as a long

toString

public java.lang.String toString()
Returns a String object representing this UnsignedShort value.
Specified by:
toString in interface Primitive
Overrides:
toString in class java.lang.Object
Returns:
a string representation of the value of this object in base 10.

serialize

public void serialize(java.io.DataOutputStream pOutputStream)
Yeech. THis needs to be brought into line with javasoft's serialization schemes.
Specified by:
serialize in interface Primitive

compareTo

public int compareTo(java.lang.Object obj)
Used for sorting, like strcmp. The object passed in must be another unsignedShort. Should probably leverage the PrimitiveNumber abstract class here, so we can compare UnsignedShorts, UnsignedBytes, etc. But ths could create some sorting problems with truncations of DoublePrecision and the like--17.compareTo(17.8) would probably evaluate to zero, meaning the two are equal. Punt for now, but this is dangerous and should be fixed--anyone can pass in a random object and a crash will result on the cast failure to UnsignedShort.
Specified by:
compareTo in interface Primitive

hashCode

public int hashCode()
Hashcode. Just return the value.
Specified by:
hashCode in interface Primitive
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Compare for equality. Object being compared must be of type UnsignedByte for the equality to be true, so comparing an UnsignedByte value of 7 to an UnsignedShort value of 7 will return false.
Specified by:
equals in interface Primitive
Overrides:
equals in class PrimitiveNumber

clone

public java.lang.Object clone()
create a copy of the object that shares no data members with the original.
Specified by:
clone in interface Primitive
Overrides:
clone in class PrimitiveNumber

increment

public void increment()
add one to the value
Specified by:
increment in interface ArithmeticIF
Overrides:
increment in class PrimitiveNumber

decrement

public void decrement()
subtract one from the value
Specified by:
decrement in interface ArithmeticIF
Overrides:
decrement in class PrimitiveNumber

add

public void add(int pValue)
Add the given amount to the data
Specified by:
add in interface ArithmeticIF
Overrides:
add in class PrimitiveNumber

subtract

public void subtract(int pValue)
subtract the given amount from the value
Specified by:
subtract in interface ArithmeticIF
Overrides:
subtract in class PrimitiveNumber