/* File: ClockTime.java CVS Info: $Id: ClockTime.java,v 1.2 1998/01/27 18:43:57 mcgredo Exp $ Compiler: jdk 1.3 */ package mil.navy.nps.dis; import mil.navy.nps.util.*; // General-purpose utilities import mil.navy.nps.disEnumerations.*; // Enumerations for DIS import java.io.*; // input/output library import java.util.*; // utilities /** * Special clock time reporting class. * *@version 1.0 *@author Antonio Alexandre Rua (http://www.garfield.fe.up.pt/~alexrua) * *
sizeOf = 8 bytes
.
*/
public static final int sizeOf = 8; // size, in bytes, of a serialized ClockTime
/**
*Default constructor--fills with zeros for all values.
*/
public ClockTime() // constructor
{
hour = 0;
timePastHour = new UnsignedInt();
}
/**
*Constructs a new ClockTime object whose values are passed in parameters.
*
*@param pHour the passed hours since 0000 hours January 1, 1970 UTC
*@param pTimePastHour the Timestamp of the new object
*
*/
public ClockTime(long pHour, long pTimePastHour) // constructor
{
hour = (int)pHour;
timePastHour = new UnsignedInt(pTimePastHour);
}
public Object clone()
{
// make a copy of the object. We don't have any objects here, so we can
// just do a straight copy.
ClockTime newClockTime = new ClockTime();
newClockTime.setHour(hour);
newClockTime.setTimePastHour(this.getTimePastHour());
return newClockTime;
}
/**
*@exception RuntimeException when an IO Error occurs.
*/
public void serialize(DataOutputStream outputStream)
{
try
{
outputStream.writeInt(hour);
timePastHour.serialize(outputStream);
}
catch(IOException ioException) // catch-all for all IO exceptions in the above code
{
throw new
RuntimeException("Exception in ClockTime. Error serializing unit.");
}
return;
}
/**
*@exception RuntimeException when an IO Error occurs.
*/
public void deSerialize(DataInputStream inputStream)
{
// no need to call super, since there are no ivars in the superclass.
try
{
hour = inputStream.readInt();
timePastHour.deSerialize(inputStream);
}
catch(IOException ioException) // catch-all for all IO exceptions in the above code
{
throw new
RuntimeException("Exception in ClockTime. Error deSerializing unit.");
}
return;
}
public int length()
{
return sizeOf; // 8 bytes long
}
public void printValues(int indentLevel, PrintStream printStream)
{
// print the values of the object out, with correct level of
// indentation on the page.
char[] indent = new char[indentLevel];
int idx = 0;
String spacing;
for(idx = 0; idx < indentLevel; idx++)
indent[idx] = ' ';
spacing = new String(indent);
printStream.println(indent + "Hour: " + hour);
printStream.println(indent + "Time Past Hour: "+timePastHour.longValue());
return;
}
// accessor methods
public int getHour()
{ return hour;
}
public void setHour(int pHour)
{ hour = pHour;
}
public void setHour(long pHour)
{ hour = (int)pHour;
}
public int getTimePastHour()
{ return ((UnsignedInt)timePastHour.clone()).intValue();
}
public void setTimePastHour(UnsignedInt pTimePastHour)
{ timePastHour = pTimePastHour;
}
public void setTimePastHour(long pTimePastHour)
{ timePastHour = new UnsignedInt(pTimePastHour);
}
public void setValues(long pHour,long pTimePastHour)
{ hour = (int)pHour;
timePastHour = new UnsignedInt(pTimePastHour);
}
} // end of class ClockTime