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

source: tmcsimulator/trunk/src/atmsdriver/model/FEPLine.java @ 186

Revision 186, 3.5 KB checked in by jtorres, 9 years ago (diff)

Highways.java, FEPLine.java, LoopDetector?.java, Station.java: reconfigured the getHighwaysMeta() function to a toCondensedFormat(boolean MetaDataOnly?) method. By specifying MetaDataOnly? as true, you get the same output as the previous getHighwaysMeta() function. By specifying MetaDataOnly? as false, you get the new condensed format needed to send to the FEPSim over the socket. This allows us to use the same function to get a meta data dump, as well as get the highways data format needed for FEPSim socket. HighwaysParser?.cpp: removed the old tinyxml code, set up skeleton for new parser. NetworkReader?.h: deleted, and added HighwaysParser?.h. LoadSadDotsTest?.java and StationTest?.java: configured to use new toCondensedFormat method instead of getHighwaysMeta.

RevLine 
1package atmsdriver.model;
2
3import java.util.ArrayList;
4import java.util.List;
5import org.w3c.dom.Document;
6import org.w3c.dom.Element;
7
8/**
9 * An FEPLine is a simulated line of communication from the FEP to
10 * Stations in the highways network.
11 *
12 * An FEPLine contains static line meta data and a list of Stations. A
13 * single FEPLine contains multiple Stations.
14 *
15 * @author John A. Torres
16 * @version 09/10/2017
17 */
18final public class FEPLine
19{
20    /* Static FEPLine meta data */
21    final public int lineNum;
22    final public List<Station> stations;
23    final private int count;
24
25    /**
26     * Constructs an FEPLine from given line number, list of stations, and count.
27     *
28     * @param lineNum
29     * @param stations
30     * @param count
31     */
32    FEPLine(int lineNum, ArrayList<Station> stations, int count)
33    {
34        this.lineNum = lineNum;
35        this.stations = stations;
36        this.count = count;
37    }
38   
39    /** Returns a string of highways data. If MetaDataOnly is true, you get a full
40     *  dump of the highways meta data, which does not include dynamic loop values,
41     *  and does include the string location names. If MetaDataOnly is false,
42     *  dynamic loop values are included, and unnecessary information like string
43     *  location values are included.
44     *
45     *  The FEPSimulator takes in the toCondensedFormat() output, with a MetaDataOnly
46     *  value of false, over the socket.
47     *
48     *  The MetaDataOnly flag should be used to get a full dump of the highways
49     *  information. This was used to get the highways_fullmap.txt output.
50     *
51     * @param MetaDataOnly Whether you want meta data, or a full dump for FEPSim
52     * @return String, highways data in condensed format
53     */
54    public String toCondensedFormat(boolean MetaDataOnly)
55    {
56        StringBuilder build = new StringBuilder();
57        build.append(Integer.toString(this.lineNum));
58        build.append(" ");
59        build.append(Integer.toString(this.count));
60        build.append(" ");
61        build.append(Integer.toString(this.stations.size()));
62        build.append("\n");
63        for(Station station : stations)
64        {
65            build.append(station.toCondensedFormat(MetaDataOnly));
66        }
67        return build.toString();
68    }
69   
70    /**
71     * Returns the FEPLine data in XMLFormat
72     *
73     * @param currElem The current XML <Line> element
74     */
75    public void toXML(Element currElem)
76    {
77        Document theDoc = currElem.getOwnerDocument();
78
79        Element lineElement = theDoc.createElement(XML_TAGS.LINE.tag);
80        currElem.appendChild(lineElement);
81
82        Element lineNumElement = theDoc.createElement(XML_TAGS.LINE_NUM.tag);
83        lineNumElement.appendChild(theDoc.createTextNode(String.valueOf(this.lineNum)));
84        lineElement.appendChild(lineNumElement);
85
86        Element countElement = theDoc.createElement(XML_TAGS.COUNT.tag);
87        countElement.appendChild(theDoc.createTextNode(String.valueOf(this.count)));
88        lineElement.appendChild(countElement);
89
90        Element stationsElement = theDoc.createElement(XML_TAGS.STATIONS.tag);
91        lineElement.appendChild(stationsElement);
92        for (Station station : stations)
93        {
94            station.toXML(stationsElement);
95        }
96    }
97   
98    /**
99     * XML Tags used in toXML()
100     */
101    private static enum XML_TAGS
102    {
103
104        LINE("Line"),
105        LINE_NUM("Line_Num"),
106        STATIONS("Stations"),
107        COUNT("Count");
108
109        String tag;
110
111        private XML_TAGS(String n)
112        {
113            tag = n;
114        }
115    }
116}
Note: See TracBrowser for help on using the repository browser.