Warning: Can't use blame annotator:
svn blame failed on trunk/src/tmcsim/cadmodels/Incident.java: ("Can't find a temporary directory: Internal error", 20014)

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

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

Initial Import of project files

RevLine 
1package tmcsim.cadmodels;
2
3import java.io.Serializable;
4import java.util.TreeMap;
5import java.util.Vector;
6
7import tmcsim.cadmodels.IncidentEvent.EVENT_STATUS;
8import tmcsim.common.ParamicsLocation;
9
10/**
11 * Incident is the container class used to information relating to a
12 * simulation incident.  An incident is identified by a unique integer log
13 * number. Additional descriptive information includes a short description,
14 * an IncidentInquiryHeader containing CAD related data, and a Map of
15 * IncidentLocations used for XMLIncident location referencing.  This object holds
16 * counters to keep track of the simulation time when the incident is scheduled
17 * to occur and to retain the time when it is does occur.  The Incident object
18 * has a list of IncidentEvents that will occur during the simulation. 
19 *
20 * @author Matthew Cechini (mcechini@calpoly.edu)
21 * @version $Date: 2006/06/06 20:46:40 $ $Revision: 1.4 $
22 */
23@SuppressWarnings("serial")
24public class Incident implements Serializable {
25   
26    /** A brief description of the incident that is displayed in the Simulation Manager GUI. */
27    public String description;
28   
29    /** The CHP Incident Log Number assigned to this incident */
30    public Integer logNumber;
31
32    /**  Object containing the IncidentInquiry header information. */
33    public IncidentInquiryHeader header;
34
35    /** 
36     * TreeMap mapping IncidentLocation objects(values) to a String identifier(keys)
37     * read as during script parsing.
38     */
39    public TreeMap<String, ParamicsLocation> locationMap;   
40   
41    /**
42     * The time, in seconds, in a simulation that the incident 'begins.' 
43     * This does not necessarily correspond to first event.
44     */
45    private long startTime;
46   
47    /**
48     * Holds the time (number of seconds) that this incident occured. This may
49     * be different than the scriptIncidentStartTime if the user manually triggers
50     * the incident.
51     */     
52    private long secondsIncidentStarted = 0;
53 
54    /** Boolean flag to designate whether the incident has occured or not. */   
55    private boolean incidentOccured = false;
56   
57    /** The incidents list of IncidentEvents that will occur in successive order. */
58    private Vector<IncidentEvent> eventList = null; 
59   
60       
61    /**
62     * Constructor.  Initialize local lists and Incident identifying data.
63     *
64     * @param log   Unique log number for this incident.
65     * @param desc  Short description of this incident.
66     * @param start Simulation time (in seconds) for this incident to start.
67     */
68    public Incident(/*NetworkID*/ Integer log, String desc, long start)
69    {
70        logNumber   = log;
71        description = desc;
72        startTime   = start;
73        header      = new IncidentInquiryHeader();     
74        locationMap = new TreeMap<String, ParamicsLocation>();
75       
76        eventList    = new Vector<IncidentEvent>();
77       
78    }
79   
80    /**
81     * Method checks if the Incident can be triggered.  If the simulation
82     * time is equal to or greater than this Incident's start time, and the
83     * Incident has not previously been triggered, then trigger the incident.
84     * The start time is recorded and true returned.  Else the Incident is
85     * already started or not ready, return false.
86     *
87     * @param scriptSeconds Current value of simulation time, in seconds.
88     * @return boolean Return true when this incident is first triggered, else return false.
89     */
90    public boolean tick(long scriptSeconds) {
91       
92        if(scriptSeconds >= startTime && !incidentOccured) {           
93            incidentOccured        = true;
94            secondsIncidentStarted = scriptSeconds;
95           
96            return true;
97        }
98        else
99            return false;
100    }   
101   
102    /**
103     * Method iterates through the list of events associated with this incident and returns
104     * a list of those that are ready to be triggered. 
105     *
106     * @param simTime Current simulation time, in seconds.
107     * @return Vector of IncidentEvents that have triggered as a result of this tick().
108     */
109    public Vector<IncidentEvent> getTriggeredEvents(long simTime) {
110       
111        Vector<IncidentEvent> triggered = new Vector<IncidentEvent>();
112       
113        if(incidentOccured) {       
114            for(IncidentEvent evt : eventList) {
115                if(evt.triggerEvent(secondsIncidentStarted, simTime)) {
116                    triggered.add(evt);
117                }   
118            }                               
119        }
120       
121        return triggered;
122    }
123   
124   
125    /**
126     * This method returns a Vector of IncidentEvents which had previously been
127     * triggered and queued while it's associated audio file was being played.
128     * When the audio file has completed, this method will remove that event from
129     * the queuedEvents Vector.
130     *
131     * @return Vector of IncidentEvents which can be inserted into the simulation.
132     */
133    public Vector<IncidentEvent> getCompletedEvents() {
134       
135        Vector<IncidentEvent> completed = new Vector<IncidentEvent>();
136       
137        for(IncidentEvent evt : eventList) {
138            if(evt.eventStatus == EVENT_STATUS.COMPLETED) {             
139                completed.add(evt);
140            }       
141        }
142       
143        return completed;
144    }
145   
146    /**
147     * Get the script log number associated with this incident.
148     *
149     * @return String The script log number.
150     */
151    public Integer getLogNumber() {
152        return logNumber;   
153    }
154   
155
156    /**
157     * Manually trigger this incident.  Sets the variable that keeps track of
158     * when the incident occured to the parameter value, and sets the
159     * incidentOccurred variable to true. 
160     *
161     * @param newtime The time in the script when the incident is being triggered.
162     */
163    public void manualTrigger(long newtime) {
164        secondsIncidentStarted = newtime;   
165        incidentOccured        = true; 
166    }
167   
168    /**
169     * Gets the time (in seconds) that the incident will occur.
170     *
171     * @return long Time(in seconds) that the incident will occur.
172     */
173    public long getSecondsToStart() {
174        return startTime;   
175    }
176   
177    /**
178     * Sets the time( in seconds) that the incident will occur.
179     *
180     * @param  newStartTime Time(in seconds) that the incident will occur.
181     */
182    public void setSecondsToStart(long newStartTime) {
183        startTime = newStartTime;   
184    }   
185   
186   
187    /**
188     * Called to calculate the length of this incident.  The length is the first
189     * event's time subtracted from the last event's time. 
190     *
191     * @return Length of the simulation incident (in seconds).
192     */
193    public Long getIncidentLength() {       
194        return eventList.lastElement().secondsToOccurInIncident -
195            eventList.firstElement().secondsToOccurInIncident;                 
196    }
197   
198    /**
199     * Check to see if incident has occured.
200     * @return true if incident has occured, false if not.
201     */
202    public boolean hasOccured() {
203        return incidentOccured; 
204    }
205
206    /**
207     * Reset the simulation time counters and incidentOccured flag.  Iterate
208     * through the event list and reset each event as well.
209     */
210    public void resetSimulation() {
211        secondsIncidentStarted    = 0;
212        incidentOccured           = false;
213           
214        for(IncidentEvent ie : eventList) 
215            ie.resetSimulation();
216                               
217    }
218   
219    /**
220     * Add an Incident Event to the Incident's list of events.  The new
221     * event will also receive the current header data associated with this
222     * incident.
223     *
224     * @param newEvent The IncidentEvent to be added.
225     */
226    public void addEvent(IncidentEvent newEvent) {
227        newEvent.eventInfo.setHeader(header);
228        eventList.add(newEvent);   
229    }   
230
231}
Note: See TracBrowser for help on using the repository browser.