| 1 | package atmsdriver.model; |
|---|
| 2 | |
|---|
| 3 | import java.util.List; |
|---|
| 4 | import org.w3c.dom.Document; |
|---|
| 5 | import org.w3c.dom.Element; |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | /** An FEPLine is a simulated line of communication from the FEP to |
|---|
| 10 | * LoopDetectorStations in the traffic network. |
|---|
| 11 | * |
|---|
| 12 | * An FEPLine contains static meta data and a list of LoopDetectorStations. |
|---|
| 13 | * A single FEPLine contains multiple LoopDetectorStations. |
|---|
| 14 | * |
|---|
| 15 | * @author John A. Torres |
|---|
| 16 | * @version 09/10/2017 |
|---|
| 17 | */ |
|---|
| 18 | public class FEPLine { |
|---|
| 19 | /* Static FEPLine meta data */ |
|---|
| 20 | final private int lineNum; |
|---|
| 21 | final private List<Station> stations; |
|---|
| 22 | final private int count; |
|---|
| 23 | // NOT SURE IF NEXT IS FINAL |
|---|
| 24 | final private int schedule; |
|---|
| 25 | final private int lineInfo; |
|---|
| 26 | final private long systemKey; |
|---|
| 27 | private long globalSeq; |
|---|
| 28 | private long scheduleSeq; |
|---|
| 29 | |
|---|
| 30 | public FEPLine(int lineNum, List<Station> stations, int count, |
|---|
| 31 | int schedule, int lineInfo, long systemKey, long globalSeq, |
|---|
| 32 | long scheduleSeq) |
|---|
| 33 | { |
|---|
| 34 | this.lineNum = lineNum; |
|---|
| 35 | this.stations = stations; |
|---|
| 36 | this.count = count; |
|---|
| 37 | this.schedule = schedule; |
|---|
| 38 | this.lineInfo = lineInfo; |
|---|
| 39 | this.systemKey = systemKey; |
|---|
| 40 | this.globalSeq = globalSeq; |
|---|
| 41 | this.scheduleSeq = scheduleSeq; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | public int getLineNumber() |
|---|
| 45 | { |
|---|
| 46 | return this.lineNum; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | public List<Station> getStations() |
|---|
| 50 | { |
|---|
| 51 | return this.stations; |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | // NEED TO CHECK NUMBERS? DO WE EVEN NEED THIS? |
|---|
| 55 | public void updateSequences() |
|---|
| 56 | { |
|---|
| 57 | this.scheduleSeq += 1; |
|---|
| 58 | this.globalSeq += 51; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | public String getLineMeta() |
|---|
| 62 | { |
|---|
| 63 | StringBuilder build = new StringBuilder(); |
|---|
| 64 | build.append(Integer.toString(this.lineNum)); |
|---|
| 65 | build.append(" "); |
|---|
| 66 | build.append(Integer.toString(this.count)); |
|---|
| 67 | build.append(" "); |
|---|
| 68 | build.append(Integer.toString(this.stations.size())); |
|---|
| 69 | build.append("\n"); |
|---|
| 70 | for(Station station : stations) |
|---|
| 71 | { |
|---|
| 72 | build.append(station.getStationMeta()); |
|---|
| 73 | } |
|---|
| 74 | return build.toString(); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | public void toXML(Element currElem) |
|---|
| 78 | { |
|---|
| 79 | Document theDoc = currElem.getOwnerDocument(); |
|---|
| 80 | |
|---|
| 81 | Element lineElement = theDoc.createElement(XML_TAGS.LINE.tag); |
|---|
| 82 | currElem.appendChild(lineElement); |
|---|
| 83 | |
|---|
| 84 | Element lineNumElement = theDoc.createElement(XML_TAGS.LINE_NUM.tag); |
|---|
| 85 | lineNumElement.appendChild(theDoc.createTextNode(String.valueOf(this.lineNum))); |
|---|
| 86 | lineElement.appendChild(lineNumElement); |
|---|
| 87 | |
|---|
| 88 | Element countElement = theDoc.createElement(XML_TAGS.COUNT.tag); |
|---|
| 89 | countElement.appendChild(theDoc.createTextNode(String.valueOf(this.count))); |
|---|
| 90 | lineElement.appendChild(countElement); |
|---|
| 91 | |
|---|
| 92 | Element scheduleElement = theDoc.createElement(XML_TAGS.SCHEDULE.tag); |
|---|
| 93 | scheduleElement.appendChild(theDoc.createTextNode(String.valueOf(this.schedule))); |
|---|
| 94 | lineElement.appendChild(scheduleElement); |
|---|
| 95 | |
|---|
| 96 | Element lineInfoElement = theDoc.createElement(XML_TAGS.LINE_INFO.tag); |
|---|
| 97 | lineInfoElement.appendChild(theDoc.createTextNode(String.valueOf(this.lineInfo))); |
|---|
| 98 | lineElement.appendChild(lineInfoElement); |
|---|
| 99 | |
|---|
| 100 | Element systemKeyElement = theDoc.createElement(XML_TAGS.SYSTEM_KEY.tag); |
|---|
| 101 | systemKeyElement.appendChild(theDoc.createTextNode(String.valueOf(this.systemKey))); |
|---|
| 102 | lineElement.appendChild(systemKeyElement); |
|---|
| 103 | |
|---|
| 104 | Element globalSeqElement = theDoc.createElement(XML_TAGS.GLOBAL_SEQ.tag); |
|---|
| 105 | globalSeqElement.appendChild(theDoc.createTextNode(String.valueOf(this.globalSeq))); |
|---|
| 106 | lineElement.appendChild(globalSeqElement); |
|---|
| 107 | |
|---|
| 108 | Element scheduleSeqElement = theDoc.createElement(XML_TAGS.SCHEDULE_SEQ.tag); |
|---|
| 109 | scheduleSeqElement.appendChild(theDoc.createTextNode(String.valueOf(this.scheduleSeq))); |
|---|
| 110 | lineElement.appendChild(scheduleSeqElement); |
|---|
| 111 | |
|---|
| 112 | Element stationsElement = theDoc.createElement(XML_TAGS.STATIONS.tag); |
|---|
| 113 | lineElement.appendChild(stationsElement); |
|---|
| 114 | for(Station station : stations) |
|---|
| 115 | { |
|---|
| 116 | station.toXML(stationsElement); |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | private static enum XML_TAGS |
|---|
| 121 | { |
|---|
| 122 | LINE("Line"), |
|---|
| 123 | LINE_NUM("Line_Num"), |
|---|
| 124 | STATIONS("Stations"), |
|---|
| 125 | COUNT("Count"), |
|---|
| 126 | SCHEDULE("Schedule"), |
|---|
| 127 | LINE_INFO("Line_Info"), |
|---|
| 128 | SYSTEM_KEY("System_Key"), |
|---|
| 129 | GLOBAL_SEQ("Global_Seq"), |
|---|
| 130 | SCHEDULE_SEQ("Schedule_Seq"); |
|---|
| 131 | |
|---|
| 132 | String tag; |
|---|
| 133 | |
|---|
| 134 | private XML_TAGS(String n) |
|---|
| 135 | { |
|---|
| 136 | tag = n; |
|---|
| 137 | } |
|---|
| 138 | } |
|---|
| 139 | } |
|---|