| 1 | package atmsdriver.network.model; |
|---|
| 2 | |
|---|
| 3 | import java.util.List; |
|---|
| 4 | import org.w3c.dom.Document; |
|---|
| 5 | import org.w3c.dom.Element; |
|---|
| 6 | |
|---|
| 7 | /** A LoopDetectorStation is a simulation of a station in a traffic network. |
|---|
| 8 | * |
|---|
| 9 | * A LoopDetectorStation (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 | */ |
|---|
| 19 | public class LoopDetectorStation { |
|---|
| 20 | /* Static LoopDetectorStation 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 LoopDetectorStation data */ |
|---|
| 31 | private int MLTotVol; |
|---|
| 32 | private int OppTotVol; |
|---|
| 33 | |
|---|
| 34 | /* Constructor */ |
|---|
| 35 | public LoopDetectorStation(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 | private static enum XML_TAGS |
|---|
| 53 | { |
|---|
| 54 | STATION("Station"), |
|---|
| 55 | LDS_ID("LDS_ID"), |
|---|
| 56 | LINE_NUM("Line_Num"), |
|---|
| 57 | DROP("Drop"), |
|---|
| 58 | LOOPS("Loops"), |
|---|
| 59 | LOCATION("Location"), |
|---|
| 60 | POST_MILE("Post_Mile"), |
|---|
| 61 | DIRECTION("Direction"), |
|---|
| 62 | FREEWAY("Freeway"), |
|---|
| 63 | ML_TOT_VOL("ML_Tot_Vol"), |
|---|
| 64 | OPP_TOT_VOL("Opp_Tot_Vol"); |
|---|
| 65 | |
|---|
| 66 | String tag; |
|---|
| 67 | |
|---|
| 68 | private XML_TAGS(String n) |
|---|
| 69 | { |
|---|
| 70 | tag = n; |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | public void toXML(Element currElem) |
|---|
| 75 | { |
|---|
| 76 | Document theDoc = currElem.getOwnerDocument(); |
|---|
| 77 | |
|---|
| 78 | Element stationElement = theDoc.createElement(XML_TAGS.STATION.tag); |
|---|
| 79 | currElem.appendChild(stationElement); |
|---|
| 80 | |
|---|
| 81 | Element ldsIDElement = theDoc.createElement(XML_TAGS.LDS_ID.tag); |
|---|
| 82 | ldsIDElement.appendChild(theDoc.createTextNode(String.valueOf(this.ldsID))); |
|---|
| 83 | stationElement.appendChild(ldsIDElement); |
|---|
| 84 | |
|---|
| 85 | Element lineNumElement = theDoc.createElement(XML_TAGS.LINE_NUM.tag); |
|---|
| 86 | lineNumElement.appendChild(theDoc.createTextNode(String.valueOf(this.lineNum))); |
|---|
| 87 | stationElement.appendChild(lineNumElement); |
|---|
| 88 | |
|---|
| 89 | Element dropElement = theDoc.createElement(XML_TAGS.DROP.tag); |
|---|
| 90 | dropElement.appendChild(theDoc.createTextNode(String.valueOf(this.drop))); |
|---|
| 91 | stationElement.appendChild(dropElement); |
|---|
| 92 | |
|---|
| 93 | Element locationElement = theDoc.createElement(XML_TAGS.LOCATION.tag); |
|---|
| 94 | locationElement.appendChild(theDoc.createTextNode(this.location)); |
|---|
| 95 | stationElement.appendChild(locationElement); |
|---|
| 96 | |
|---|
| 97 | Element postMileElement = theDoc.createElement(XML_TAGS.POST_MILE.tag); |
|---|
| 98 | postMileElement.appendChild(theDoc.createTextNode(String.valueOf(this.postmile))); |
|---|
| 99 | stationElement.appendChild(postMileElement); |
|---|
| 100 | |
|---|
| 101 | Element directionElement = theDoc.createElement(XML_TAGS.DIRECTION.tag); |
|---|
| 102 | directionElement.appendChild(theDoc.createTextNode(this.direction.name)); |
|---|
| 103 | stationElement.appendChild(directionElement); |
|---|
| 104 | |
|---|
| 105 | Element freewayElement = theDoc.createElement(XML_TAGS.FREEWAY.tag); |
|---|
| 106 | freewayElement.appendChild(theDoc.createTextNode(String.valueOf(this.freeway))); |
|---|
| 107 | stationElement.appendChild(freewayElement); |
|---|
| 108 | |
|---|
| 109 | Element mlElement = theDoc.createElement(XML_TAGS.ML_TOT_VOL.tag); |
|---|
| 110 | mlElement.appendChild(theDoc.createTextNode(String.valueOf(this.MLTotVol))); |
|---|
| 111 | stationElement.appendChild(mlElement); |
|---|
| 112 | |
|---|
| 113 | Element oppElement = theDoc.createElement(XML_TAGS.OPP_TOT_VOL.tag); |
|---|
| 114 | oppElement.appendChild(theDoc.createTextNode(String.valueOf(this.OppTotVol))); |
|---|
| 115 | stationElement.appendChild(oppElement); |
|---|
| 116 | |
|---|
| 117 | Element loopsElement = theDoc.createElement(XML_TAGS.LOOPS.tag); |
|---|
| 118 | stationElement.appendChild(loopsElement); |
|---|
| 119 | |
|---|
| 120 | for(LoopDetector loop : loops) |
|---|
| 121 | { |
|---|
| 122 | loop.toXML(loopsElement); |
|---|
| 123 | } |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | /** |
|---|
| 127 | * Enum for freeway direction. |
|---|
| 128 | * |
|---|
| 129 | * @author John A. Torres |
|---|
| 130 | * @version 9/10/2017 |
|---|
| 131 | */ |
|---|
| 132 | public static enum DIRECTION |
|---|
| 133 | { |
|---|
| 134 | NORTH("N"), |
|---|
| 135 | SOUTH("S"), |
|---|
| 136 | EAST("E"), |
|---|
| 137 | WEST("W"); |
|---|
| 138 | |
|---|
| 139 | String name; |
|---|
| 140 | |
|---|
| 141 | DIRECTION(String name) |
|---|
| 142 | { |
|---|
| 143 | this.name = name; |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | /** |
|---|
| 147 | * Returns the direction enum, given a string value. |
|---|
| 148 | * @param name str value for enum |
|---|
| 149 | * @return enum for given str value |
|---|
| 150 | */ |
|---|
| 151 | public static DIRECTION getEnum(String name) |
|---|
| 152 | { |
|---|
| 153 | switch(name) |
|---|
| 154 | { |
|---|
| 155 | case "S": |
|---|
| 156 | return SOUTH; |
|---|
| 157 | case "N": |
|---|
| 158 | return NORTH; |
|---|
| 159 | case "E": |
|---|
| 160 | return EAST; |
|---|
| 161 | case "W": |
|---|
| 162 | return WEST; |
|---|
| 163 | default: |
|---|
| 164 | return null; |
|---|
| 165 | } |
|---|
| 166 | } |
|---|
| 167 | } |
|---|
| 168 | } |
|---|