source: tmcsimulator/trunk/src/tmcsim/cadmodels/CADRoutedMessage.java @ 2

Revision 2, 3.4 KB checked in by jdalbey, 10 years ago (diff)

Initial Import of project files

Line 
1package tmcsim.cadmodels;
2
3import java.io.Serializable;
4import java.util.Calendar;
5
6/**
7 * CADRoutedMessage is used to contain information for a routed message
8 * between CAD positions.  Message information includes origin and destination
9 * CAD positions, message date and time, message text, and a flag to specify
10 * that this message is a incident update.
11 *
12 * @author Matthew Cechini (mcechini@calpoly.edu)
13 * @version $Date: 2006/06/06 20:46:40 $ $Revision: 1.4 $
14 */
15@SuppressWarnings("serial")
16public class CADRoutedMessage implements Comparable<CADRoutedMessage>, Serializable {
17
18    /** CAD Position that sent this routed message. */
19    public int fromPosition;
20
21    /** CAD Position tha tthis routed message is being sent to. */
22    public int toPosition;
23
24    /** String representation of the current data in format DDMMYYYY. */
25    public String date;
26
27    /** String representation of the current time in format HH:MM:SS */
28    public String time;
29
30    /** Routed message text. */
31    public String message; 
32   
33    /** Flag to designate whether this is a routed IncidentInquiry page */
34    public boolean incidentUpdate;
35   
36    /**
37     * Constructor.  Initializes source, destination, and message from
38     * method parameters.  Initializes date and time to current values.
39     *
40     * @param from CAD position message has been sent from.
41     * @param to CAD Position to route the message to
42     * @param newMessage Routed message that has been entered
43     */
44    public CADRoutedMessage(int from, int to, String newMessage, boolean isIncidentUpdate) {
45        fromPosition = from;
46        toPosition   = to;
47        date         = "";
48        time         = "";
49           
50           
51        Calendar rightNow = Calendar.getInstance();
52       
53        /*** BUILD TIME ***/
54       
55        //String currentTime = "";
56        if(rightNow.get(Calendar.HOUR_OF_DAY) < 10)
57            time += "0";
58       
59        time += (String.valueOf(rightNow.get(Calendar.HOUR_OF_DAY))) + ":";
60       
61        if(rightNow.get(Calendar.MINUTE) < 10)
62            time += "0";
63       
64        time += (String.valueOf(rightNow.get(Calendar.MINUTE))) + ":";     
65       
66       
67        if(rightNow.get(Calendar.SECOND) < 10)
68            time += "0";
69       
70        time += (String.valueOf(rightNow.get(Calendar.SECOND)));
71       
72       
73        /*** BUILD DATE ***/
74       
75        if(rightNow.get(Calendar.MONTH) < 10)
76            date += "0";
77        date += String.valueOf(rightNow.get(Calendar.MONTH));
78       
79        if(rightNow.get(Calendar.DAY_OF_MONTH) < 10)
80            date += "0";
81        date += String.valueOf(rightNow.get(Calendar.DAY_OF_MONTH));
82       
83        date += String.valueOf(rightNow.get(Calendar.YEAR));
84       
85        message        = newMessage;
86        incidentUpdate = isIncidentUpdate;
87    }
88
89   
90
91    /**
92     * Overloaded Comparable.compareTo() method to allow this object to be
93     * added to an order collection.
94     */
95    public int compareTo(CADRoutedMessage o) {
96        return time.compareTo(o.time);
97    }
98   
99    /**
100     * Overloaded equals method, determining equality by checking all data members.
101     */
102    public boolean equals(Object o) {
103        return ((CADRoutedMessage)o).toPosition == toPosition &&
104               ((CADRoutedMessage)o).fromPosition == fromPosition &&
105               ((CADRoutedMessage)o).date.equals(date) &&
106               ((CADRoutedMessage)o).message.equals(message);
107         
108    }
109   
110}
Note: See TracBrowser for help on using the repository browser.