/* 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) * *
Location: *
Web: * http://www.web3d.org/WorkingGroups/vrtp/mil/navy/nps/dis/ClockTime.java * *
or locally: * ~/mil/navy/nps/dis/ClockTime.java * *
Hierarchy Diagram: *
* *
Summary: *
Time measurements that surpass one hour shall be represented by a Clock Time Record. * The time represented shall be either real-world time (UTC) or simulation time. * The simulation time shall be the UTC of the simulation exercise. * *
Note: *
Here we don't implement the Timestamp record. * Yet we don't have the same trouble using it as in ProtocolDataUnit. * You should consult our on-line documentation to see the trouble using time. * *
History: *
16Sep97 /Antonio Alexandre Rua /New *
8Dec97 /Ronan Fauglas /changes for documentation templates + complements in documentation *
11Dec97 /Ronan Fauglas /changed access methods: thisVariable() --> getThisVariable() * *
References: *
DIS-Java-VRML Working Group: http://www.web3d.org/WorkingGroups/vrtp/dis-java-vrml/ *
DIS Data Dictionary :Clock Time Record *
DIS specification : IEEE 1278.1, Section 5.3.8 * *@see ProtocolDataUnit *@see PduElement *@see SerializationInterface *@see SimulationManagementFamily */ public class ClockTime extends PduElement { /** *Hours - This field shall specify the hours since 0000 hours January 1, 1970 UTC. * *
*
Value: *
Expressed in hours *
References: *
DIS Data Dictionary :Hours field *
*/ protected int hour; // 32-bit integer /** *Time Past the Hour - This field shall specify the time past the hour indicated in Hour field. * *
*
Value: *
This field is actually a Timestamp. * See the references below for more information. *
References: *
DIS Data Dictionary :Hours field *
*/ protected UnsignedInt timePastHour; // 32-bit unsigned integer /** *Constant value--size of a Clock Time Record; here :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