Class mil.navy.nps.util.UnsignedShort
java.lang.Object
|
+----java.lang.Number
|
+----mil.navy.nps.util.UnsignedShort
- public class UnsignedShort
- extends java.lang.Number
- implements SerializationInterface, java.lang.Cloneable
- Version:
- 1.0
- Author:
- Don McGregor (http://www.stl.nps.navy.mil/~mcgredo)
- Location:
-
http://www.stl.nps.navy.mil/dis-java-vrml/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.stl.nps.navy.mil/dis-java-vrml/
- See Also:
- SerializationInterface, UnsignedByte, UnsignedInt
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(short pData)
Constructs an UnsignedShort object from a signed short,
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.
|
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, doubleValue, floatValue, intValue, longValue, shortValue |
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MAX_SHORT_VALUE
public static final int MAX_SHORT_VALUE
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
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
- Overrides:
- doubleValue in class java.lang.Number
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
- Overrides:
- floatValue in class java.lang.Number
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
- Overrides:
- longValue in class java.lang.Number
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
- Overrides:
- intValue in class java.lang.Number
serialize
public void serialize(java.io.DataOutputStream pOutputStream)
- Writes out a UnsignedShort to an output stream.
- Implements:
- serialize in interface SerializationInterface
- Parameters:
outputstream
- the targetted output stream for this object
- 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.
- Implements:
- deSerialize in interface SerializationInterface
- Parameters:
inputstream
- the input stream that builds the object.
- 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.
- Overrides:
- toString in class java.lang.Object
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
- Overrides:
- clone in class java.lang.Object
equals
public boolean equals(java.lang.Object obj)
- Overrides:
- equals in class java.lang.Object
debugTest
public void debugTest()
- Of debugging interest only. You shouldn't have to use this method.