Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class mil.navy.nps.util.UnsignedInt

java.lang.Object
  |
  +--java.lang.Number
        |
        +--mil.navy.nps.util.UnsignedInt

public class UnsignedInt
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/UnsignedInt.java
Summary:
This class implements a 32-bit unsigned integer, which Java doesn't natively handle.
Explanation:
This is an extension of Number to handle 32-bit unsigned integers. Java doesn't handle unsigned numbers, so we have to promote the unsigned integers to longs 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 comments in UnsignedByte for description of how the mapping between negative values and unsigned positive values 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:
07Oct96 /Don McGregor /New
09Oct96 /Don McGregor /Changed name to UnsignedInt, added testing, added to mil.navy.nps.dis package
10Mar97 /Don McGregor /changes for javadoc

8Dec97 /Ronan Fauglas /changes for documentation templates + complements in documentation
16Dec98 /Don Brutzman /tweak documentation
References:
DIS-Java-VRML Working Group: http://www.stl.nps.navy.mil/dis-java-vrml/
See Also:
SerializationInterface, UnsignedByte, UnsignedShort, Serialized Form

Field Summary
static long MAX_INT_VALUE
           
 
Constructor Summary
UnsignedInt()
          Contructs an UnsignedInt object and intializes its value to 0.
UnsignedInt(int pData)
          Constructs an UnsignedInt object from a signed int, throws an exception if the parameter is out of range.
UnsignedInt(short pData)
          Constructs a UnsignedInt object from a signed short, throws an exception if the paraneter is out of range.
UnsignedInt(long pData)
          Constructs a UnsignedInt 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 UnsignedInt object.
void debugTest()
          Of debugging interest only.
void deSerialize(java.io.DataInputStream pInputStream)
          Reads a UnsignedInt in from DIS format.
double doubleValue()
          Returns the current value of this object as a double float, after conversion.
float floatValue()
          Returns a the current value of this object as a float, after conversion.
int intValue()
          Don't use this !
long longValue()
          Returns the current value of this object as a long, after conversion.
void serialize(java.io.DataOutputStream pOutputStream)
          Writes out a UnsignedInt to an output stream.
java.lang.String toString()
          Returns a String object representing this UnsignedInt 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, notifyAll, notify, toString, wait, wait, wait
 

Field Detail

MAX_INT_VALUE

public static final long MAX_INT_VALUE
Constructor Detail

UnsignedInt

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

UnsignedInt

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

UnsignedInt

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

UnsignedInt

public UnsignedInt(long pData)
Constructs a UnsignedInt object from a signed long, throws an exception if the parameter is out of range.
Parameters:
pData - >=0,<=MAX_INT_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
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()
Don't use this !
Explanation
This is actually a bad thing, since we cannot represent the full range of an unsigned int with an int. One option is to throw an exception only when the int value is beyond the range, eg above 2-billion odd. But it seems better to blow up in place, rather than work sometimes and not other times. (We have to implement the method because it's declared abstract in Number.) Moral of the story: don't try to read the value of an unsigned int with an int.
Throws:
java.lang.RuntimeException - whenever one tries to use this method.
Overrides:
intValue in class java.lang.Number

serialize

public void serialize(java.io.DataOutputStream pOutputStream)
Writes out a UnsignedInt to an output stream.
Specified by:
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 a UnsignedInt in from DIS format.
Specified by:
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 UnsignedInt 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 UnsignedInt object.
Returns:
the cloned object.
Throws:
java.lang.RuntimeException - if cloning fails
Overrides:
clone in class java.lang.Object

debugTest

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

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD