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

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

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

Initial Import of project files

RevLine 
1package tmcsim.cadmodels;
2
3import java.io.Serializable;
4
5import org.w3c.dom.Document;
6import org.w3c.dom.Element;
7
8/**
9 * CMSDiversion is a container class used to hold information for a single
10 * diversion that may be applied at a changeable message sign.  This
11 * information includes the original path, new diversion path, paramics
12 * diversion string, maximum diversion percentage, applied diversion
13 * percentage, and simulation time the diversion was applied.  The updated
14 * and cleared flags are used to specify whether the diversion has been
15 * recently changed or is cleared.
16 *
17 * @author  Matthew Cechini
18 * @version
19 */
20@SuppressWarnings("serial")
21public class CMSDiversion implements Serializable {
22
23    /**
24     * Enumeration with XML tag names.
25     * @author Matthew Cechini
26     */
27    private static enum XML_TAGS {
28        /** Diversion path. */
29        DIVERSION_PATH ("Diversion_path"),
30        /** Diversion percentage. */
31        PERCENTAGE     ("Percentage"),
32        /** Diversion identifier. */
33        IDENTIFIER     ("Identifier");
34       
35        public String tag;
36       
37        private XML_TAGS(String t) {
38            tag = t;
39        }
40    }
41   
42    /** Boolean flag to designate whether the diversion percentage has changed.*/
43    private boolean updated;
44   
45    /** Boolean flag to designate whether the diversion percentage is 0.  */
46    private boolean cleared;   
47   
48    /** Original path of traffic. */
49    public String  originalPath;
50
51    /** New path traffic will be diverted to. */
52    public String  newPath;
53
54    /** Paramics diversion path. */
55    public String  diversionPath;
56
57    /** Maximum diversion percentage. */
58    public Integer maxDiversionPercent;
59
60    /** Current diversion percentage. */
61    private Integer currDiversionPercent;
62
63    /** Time the current diversion percentage was applied. */
64    public Long timeApplied;
65
66   
67    /**
68     * Constructor.
69     *
70     * @param oPath Original path traffic would take.
71     * @param nPath New path traffic will take.
72     * @param dPath Paramics diversion path.
73     * @param maxPerc Maximum diversion percentage.
74     */
75    public CMSDiversion(String oPath, String nPath, String dPath, Integer maxPerc) {
76
77        originalPath         = oPath;
78        newPath              = nPath;
79        diversionPath        = dPath;
80        maxDiversionPercent  = maxPerc;
81        currDiversionPercent = new Integer(0);
82        timeApplied          = new Long(0);
83       
84        updated = false;
85        cleared = (currDiversionPercent == 0);             
86    }
87   
88    /**
89     * Get the current diversion percentage.
90     *
91     * @return Integer value of current diversion percentage.
92     */
93    public int getCurrDiv() { 
94        return currDiversionPercent.intValue();
95    }
96   
97    /**
98     * Set the cleared flag to true if the new diversion is zero, false
99     * if not.  Set the updated flag if the new diversion percentage is
100     * differenct than the previous applied diversion, false if not. 
101     * Set the current diversion percentage to the parameter value.
102     *
103     * @param newDiv New applied diversion percentage.
104     */
105    public void setCurrDiv(int newDiv) {
106       
107        cleared = (newDiv == 0);
108        updated = (newDiv != currDiversionPercent);
109           
110        currDiversionPercent = newDiv;         
111    }
112   
113    /**
114     * Determine whether this diversion has been updated in its last use.
115     *
116     * @return True if diversion has been updated, false if not.
117     */
118    public boolean isUpdated() { return updated;}
119   
120    /**
121     * Determine if the current diversion has been cleared.
122     *
123     * @return True if diversion is zero, false if not.
124     */
125    public boolean isCleared() { return cleared;}       
126   
127    /**
128     * Reset this diversion by ...
129     */
130    public void reset() {
131        currDiversionPercent = 0;
132       
133        updated = false;
134        cleared = (currDiversionPercent == 0);     
135    }
136   
137    /**
138     * Write the XML output for the diversion information
139     * represented in this object.  THe format is as follows:
140     * <Diversion_path>
141     *    <Identifier/>
142     *    <Percentage/>
143     * <Diversion_path>
144     *
145     * @param xmlOut XMLWriter used for XML creation.
146     */
147    public void toXML(Element currElem) {
148       
149        Document theDoc = currElem.getOwnerDocument();
150       
151        Element divPathElem = theDoc.createElement(XML_TAGS.DIVERSION_PATH.tag);
152        currElem.appendChild(divPathElem);
153       
154        Element idElem = theDoc.createElement(XML_TAGS.IDENTIFIER.tag);
155        idElem.appendChild(theDoc.createTextNode(diversionPath));
156        divPathElem.appendChild(idElem);
157
158        Element pctElem = theDoc.createElement(XML_TAGS.PERCENTAGE.tag);
159        pctElem.appendChild(theDoc.createTextNode(String.valueOf(currDiversionPercent)));
160        divPathElem.appendChild(pctElem);
161       
162    }
163}   
Note: See TracBrowser for help on using the repository browser.