source: tmcsimulator/trunk/src/atmsdriver/model/Station.java @ 84

Revision 84, 5.4 KB checked in by jtorres, 9 years ago (diff)

FEPSimulator.cpp: FEPSimulator socket server is now receiving full messages, no more partial messages over the TCP socket. General housekeeping on FEPSim.cpp, NetworkReader?.cpp, ATMSDriver.java, NetworkLoader?.java.

Line 
1package atmsdriver.model;
2
3import java.util.List;
4import org.w3c.dom.Document;
5import org.w3c.dom.Element;
6
7/** A Station is a simulation of a station in a traffic network.
8 * 
9 *  A Station (LDS) contains static meta data about the station, and
10  two dynamic attributes, MLTotVol and OppTotVol.
11 
12  A single LDS contains multiple LoopDetectors, which
13  contain data for a single lane on one direction of the freeway. A LDS
14  is specific to a single freeway, direction, and postmile.
15 *
16 * @author John A. Torres
17 * @version 9/10/2017
18 */
19public class Station implements Comparable {
20    /* Static Station meta data */
21    final private int lineNum;
22    final private int ldsID; // double check
23    final private int drop;
24    final private String location;
25    final private List<LoopDetector> loops;
26    final private int freeway;
27    final private double postmile;
28    final private DIRECTION direction;
29   
30    /* Dynamic Station data */
31    private int MLTotVol;
32    private int OppTotVol;
33   
34    /* Constructor */
35    public Station(int lineNum, int ldsID, int drop,
36            String location, List<LoopDetector> loops, int fwy, 
37            DIRECTION direction, double postmile)
38    {
39        this.lineNum = lineNum;
40        this.ldsID = ldsID;
41        this.drop = drop;
42        this.loops = loops;
43        this.location = location;
44        this.postmile = postmile;
45        this.direction = direction;
46        this.freeway = fwy;
47       
48        this.MLTotVol = 0;
49        this.OppTotVol = 0;
50    }
51
52    @Override
53    public int compareTo(Object o) {
54       
55    }
56   
57    private static enum XML_TAGS
58    {
59        STATION("Station"),
60        LDS_ID("LDS_ID"),
61        LINE_NUM("Line_Num"),
62        DROP("Drop"),
63        LOOPS("Loops"),
64        LOCATION("Location"),
65        POST_MILE("Post_Mile"),
66        DIRECTION("Direction"),
67        FREEWAY("Freeway"),
68        ML_TOT_VOL("ML_Tot_Vol"),
69        OPP_TOT_VOL("Opp_Tot_Vol");
70       
71        String tag;
72       
73        private XML_TAGS(String n)
74        {
75            tag = n;
76        }
77    }
78   
79    public void toXML(Element currElem)
80    {
81        Document theDoc = currElem.getOwnerDocument();
82       
83        Element stationElement = theDoc.createElement(XML_TAGS.STATION.tag);
84        currElem.appendChild(stationElement);
85       
86        Element ldsIDElement = theDoc.createElement(XML_TAGS.LDS_ID.tag);
87        ldsIDElement.appendChild(theDoc.createTextNode(String.valueOf(this.ldsID)));
88        stationElement.appendChild(ldsIDElement);
89       
90        Element lineNumElement = theDoc.createElement(XML_TAGS.LINE_NUM.tag);
91        lineNumElement.appendChild(theDoc.createTextNode(String.valueOf(this.lineNum)));
92        stationElement.appendChild(lineNumElement);
93       
94        Element dropElement = theDoc.createElement(XML_TAGS.DROP.tag);
95        dropElement.appendChild(theDoc.createTextNode(String.valueOf(this.drop)));
96        stationElement.appendChild(dropElement);
97       
98        Element locationElement = theDoc.createElement(XML_TAGS.LOCATION.tag);
99        locationElement.appendChild(theDoc.createTextNode(this.location));
100        stationElement.appendChild(locationElement);
101       
102        Element postMileElement = theDoc.createElement(XML_TAGS.POST_MILE.tag);
103        postMileElement.appendChild(theDoc.createTextNode(String.valueOf(this.postmile)));
104        stationElement.appendChild(postMileElement);
105       
106        Element directionElement = theDoc.createElement(XML_TAGS.DIRECTION.tag);
107        directionElement.appendChild(theDoc.createTextNode(this.direction.name));
108        stationElement.appendChild(directionElement);
109       
110        Element freewayElement = theDoc.createElement(XML_TAGS.FREEWAY.tag);
111        freewayElement.appendChild(theDoc.createTextNode(String.valueOf(this.freeway)));
112        stationElement.appendChild(freewayElement);
113       
114        Element mlElement = theDoc.createElement(XML_TAGS.ML_TOT_VOL.tag);
115        mlElement.appendChild(theDoc.createTextNode(String.valueOf(this.MLTotVol)));
116        stationElement.appendChild(mlElement);
117       
118        Element oppElement = theDoc.createElement(XML_TAGS.OPP_TOT_VOL.tag);
119        oppElement.appendChild(theDoc.createTextNode(String.valueOf(this.OppTotVol)));
120        stationElement.appendChild(oppElement);
121       
122        Element loopsElement = theDoc.createElement(XML_TAGS.LOOPS.tag);
123        stationElement.appendChild(loopsElement);
124       
125        for(LoopDetector loop : loops)
126        {
127            loop.toXML(loopsElement);
128        }
129    }
130   
131    /**
132     * Enum for freeway direction.
133     *
134     * @author John A. Torres
135     * @version 9/10/2017
136     */
137    public static enum DIRECTION
138    {
139        NORTH("N"),
140        SOUTH("S"),
141        EAST("E"),
142        WEST("W");
143       
144        String name;
145       
146        DIRECTION(String name)
147        {
148            this.name = name;
149        }
150       
151        /**
152         * Returns the direction enum, given a string value.
153         * @param name str value for enum
154         * @return enum for given str value
155         */
156        public static DIRECTION getEnum(String name)
157        {
158            switch(name)
159            {
160                case "S":
161                    return SOUTH;
162                case "N":
163                    return NORTH;
164                case "E":
165                    return EAST;
166                case "W":
167                    return WEST;
168                default:
169                    return null;
170            }
171        }
172    }
173}
Note: See TracBrowser for help on using the repository browser.