mil.navy.nps.util
Class UnsignedShort

java.lang.Object
  extended byjava.lang.Number
      extended bymil.navy.nps.util.UnsignedShort
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable, SerializationInterface

public class UnsignedShort
extends java.lang.Number
implements SerializationInterface, java.lang.Cloneable

Version:
1.0
Author:
Don McGregor (http://www.npsnet.org/~mcgredo)
Location:
http://www.web3D.org/WorkingGroups/vrtp/mil/navy/nps/dis/UnsignedShort.java
Summary:
This class implements a 16-bit unsigned integer, which Java doesn't natively handle.
Explanation:
This is an extension of Number to handle 16-bit unsigned shorts. Java doesn't do unsigned, so we have to promote the unsigned shorts to ints to be sure we have enough space to handle them.

This implements the SerializationInterface, which means it can be written out to a stream in the standard DIS 32-bit format.

See explanation in UnsignedByte for how the mapping of negative-to-positive numbers works.

This implements the Cloneable interface, which means that when we clone() something we can do a bitwise field copy (shallow copy). This needs to change if we ever have any actual objects contained in this class.

History:
09Oct96 /Don McGregor /New
10Mar97 /Don McGregor /changes for javadoc
8Dec97 /Ronan Fauglas /changes for documentation templates + complements in documentation
References:
DIS-Java-VRML Working Group: http://www.web3D.org/WorkingGroups/vrtp/dis-java-vrml/
See Also:
SerializationInterface, UnsignedByte, UnsignedInt, Serialized Form

Field Summary
static int MAX_SHORT_VALUE
           
 
Constructor Summary
UnsignedShort()
          Contructs an UnsignedShort object and intializes its value to 0.
UnsignedShort(int pData)
          Constructs a an UnsignedShort object from a signed int, throws an exception if the parameter is out of range.
UnsignedShort(long pData)
          Constructs an UnsignedShort object from a signed long, throws an exception if the parameter is out of range.
UnsignedShort(short pData)
          Constructs an UnsignedShort object from a signed short, throws an exception if the parameter is out of range.
 
Method Summary
 java.lang.Object clone()
          Makes a deep copy of the current UnsignedShort object.
 void debugTest()
          Of debugging interest only.
 void deSerialize(java.io.DataInputStream pInputStream)
          Reads an UnsignedByte in from DIS format.
 double doubleValue()
          Returns the current value of this object as a double float, after conversion.
 boolean equals(java.lang.Object obj)
           
 float floatValue()
          Returns a the current value of this object as a float, after conversion.
 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)
          Writes out a UnsignedShort to an output stream.
 java.lang.String toString()
          Returns a String object representing this UnsignedShort value.
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_SHORT_VALUE

public static final int MAX_SHORT_VALUE
See Also:
Constant Field Values
Constructor Detail

UnsignedShort

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


UnsignedShort

public UnsignedShort(int pData)
Constructs a an UnsignedShort object from a signed int, throws an exception if the parameter is out of range.

Parameters:
pData - >=0, <=MAX_SHORT_VALUE
Throws:
java.lang.RuntimeException - if pData is out of range

UnsignedShort

public UnsignedShort(short pData)
Constructs an UnsignedShort object from a signed short, throws an exception if the parameter is out of range.

Parameters:
pData - >=0
Throws:
java.lang.RuntimeException - if pData is out of range

UnsignedShort

public UnsignedShort(long pData)
Constructs an UnsignedShort object from a signed long, throws an exception if the parameter is out of range.

Parameters:
pData - >=0, <=MAX_SHORT_VALUE
Throws:
java.lang.RuntimeException - if pData is out of range
Method Detail

doubleValue

public double doubleValue()
Returns the current value of this object as a double float, after conversion.

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.

Returns:
the current value of this object as a float

longValue

public long longValue()
Returns the current value of this object as a long, after conversion.

Returns:
the current value of this object as a long

intValue

public int intValue()
Returns the current value of this object as an int, after conversion.

Returns:
the current value of this object as an int

serialize

public void serialize(java.io.DataOutputStream pOutputStream)
Writes out a UnsignedShort to an output stream.

Specified by:
serialize in interface SerializationInterface
Throws:
java.lang.RuntimeException - if an IOException occurs.
See Also:
SerializationInterface

deSerialize

public void deSerialize(java.io.DataInputStream pInputStream)
Reads an UnsignedByte in from DIS format.

Specified by:
deSerialize in interface SerializationInterface
Throws:
java.lang.RuntimeException - if an IOException occurs.
See Also:
SerializationInterface

toString

public java.lang.String toString()
Returns a String object representing this UnsignedShort value.

Returns:
a string representation of the value of this object in base 10.

clone

public java.lang.Object clone()
Makes a deep copy of the current UnsignedShort object.

Returns:
the cloned object.
Throws:
java.lang.RuntimeException - if cloning fails

equals

public boolean equals(java.lang.Object obj)

debugTest

public void debugTest()
Of debugging interest only. You shouldn't have to use this method.