Changeset 87 in tmcsimulator for trunk/src/atmsdriver/model/Station.java
- Timestamp:
- 10/10/2017 01:09:50 AM (9 years ago)
- File:
-
- 1 edited
-
trunk/src/atmsdriver/model/Station.java (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/atmsdriver/model/Station.java
r84 r87 5 5 import org.w3c.dom.Element; 6 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, and10 two dynamic attributes, MLTotVol and OppTotVol.11 12 A single LDS contains multiple LoopDetectors, which13 contain data for a single lane on one direction of the freeway. A LDS14 is specific to a single freeway,direction, and postmile.7 /** 8 * A Station is a simulation of a station in a traffic network. 9 * 10 * A Station (LDS) contains static meta data about the station, and two dynamic 11 * attributes, MLTotVol and OppTotVol. * 12 * A single LDS contains multiple LoopDetectors, which contain data for a single 13 * lane on one direction of the freeway. A LDS is specific to a single freeway, 14 * direction, and postmile. 15 15 * 16 16 * @author John A. Torres … … 19 19 public class Station implements Comparable { 20 20 /* Static Station meta data */ 21 21 22 final private int lineNum; 22 23 final private int ldsID; // double check … … 27 28 final private double postmile; 28 29 final private DIRECTION direction; 29 30 30 31 /* Dynamic Station data */ 31 32 private int MLTotVol; 32 33 private int OppTotVol; 33 34 34 35 /* Constructor */ 35 36 public Station(int lineNum, int ldsID, int drop, 36 String location, List<LoopDetector> loops, int fwy, 37 DIRECTION direction, double postmile) 38 { 37 String location, List<LoopDetector> loops, int fwy, 38 DIRECTION direction, double postmile) { 39 39 this.lineNum = lineNum; 40 40 this.ldsID = ldsID; … … 45 45 this.direction = direction; 46 46 this.freeway = fwy; 47 47 48 48 this.MLTotVol = 0; 49 49 this.OppTotVol = 0; 50 50 } 51 51 52 /** 53 * Returns the station metadata in condensed form. This is just a quick 54 * script function to make a proper highway metadata configuration file, so 55 * that we can read the network faster. 56 * 57 * @return station metadata 58 */ 59 public String getStationMeta() { 60 StringBuilder build = new StringBuilder(); 61 build.append(Integer.toString(this.ldsID)); 62 build.append(" "); 63 build.append(Integer.toString(this.drop)); 64 build.append(" "); 65 build.append(Integer.toString(this.freeway)); 66 build.append(" "); 67 build.append(this.direction.name); 68 build.append(" "); 69 build.append(Double.toString(this.postmile)); 70 build.append(" "); 71 build.append(Integer.toString(loops.size())); 72 build.append(" "); 73 build.append(this.location); 74 build.append("\n"); 75 for (LoopDetector loop : loops) { 76 build.append(loop.getLoopMeta()); 77 } 78 return build.toString(); 79 } 80 81 public double getPostmile() { 82 return postmile; 83 } 84 52 85 @Override 53 public int compareTo(Object o) { 54 55 } 56 57 private static enum XML_TAGS 58 { 86 public int compareTo(Object otherStation) { 87 // check that Object is of type Station, if not throw exception 88 if (!(otherStation instanceof Station)) { 89 throw new ClassCastException("A Station object expected."); 90 } 91 92 // get difference of values 93 double otherStationPostmile = ((Station) otherStation).getPostmile(); 94 double val = this.postmile - otherStationPostmile; 95 96 // set appropriate comparable return value 97 int retval = 0; 98 if (val > 0) { 99 retval = 1; 100 } else if (val < 0) { 101 retval = -1; 102 } 103 104 return retval; 105 } 106 107 private static enum XML_TAGS { 108 59 109 STATION("Station"), 60 110 LDS_ID("LDS_ID"), … … 68 118 ML_TOT_VOL("ML_Tot_Vol"), 69 119 OPP_TOT_VOL("Opp_Tot_Vol"); 70 120 71 121 String tag; 72 73 private XML_TAGS(String n) 74 { 122 123 private XML_TAGS(String n) { 75 124 tag = n; 76 125 } 77 126 } 78 79 public void toXML(Element currElem) 80 { 127 128 public void toXML(Element currElem) { 81 129 Document theDoc = currElem.getOwnerDocument(); 82 130 83 131 Element stationElement = theDoc.createElement(XML_TAGS.STATION.tag); 84 132 currElem.appendChild(stationElement); 85 133 86 134 Element ldsIDElement = theDoc.createElement(XML_TAGS.LDS_ID.tag); 87 135 ldsIDElement.appendChild(theDoc.createTextNode(String.valueOf(this.ldsID))); 88 136 stationElement.appendChild(ldsIDElement); 89 137 90 138 Element lineNumElement = theDoc.createElement(XML_TAGS.LINE_NUM.tag); 91 139 lineNumElement.appendChild(theDoc.createTextNode(String.valueOf(this.lineNum))); 92 140 stationElement.appendChild(lineNumElement); 93 141 94 142 Element dropElement = theDoc.createElement(XML_TAGS.DROP.tag); 95 143 dropElement.appendChild(theDoc.createTextNode(String.valueOf(this.drop))); 96 144 stationElement.appendChild(dropElement); 97 145 98 146 Element locationElement = theDoc.createElement(XML_TAGS.LOCATION.tag); 99 147 locationElement.appendChild(theDoc.createTextNode(this.location)); 100 148 stationElement.appendChild(locationElement); 101 149 102 150 Element postMileElement = theDoc.createElement(XML_TAGS.POST_MILE.tag); 103 151 postMileElement.appendChild(theDoc.createTextNode(String.valueOf(this.postmile))); 104 152 stationElement.appendChild(postMileElement); 105 153 106 154 Element directionElement = theDoc.createElement(XML_TAGS.DIRECTION.tag); 107 155 directionElement.appendChild(theDoc.createTextNode(this.direction.name)); 108 156 stationElement.appendChild(directionElement); 109 157 110 158 Element freewayElement = theDoc.createElement(XML_TAGS.FREEWAY.tag); 111 159 freewayElement.appendChild(theDoc.createTextNode(String.valueOf(this.freeway))); 112 160 stationElement.appendChild(freewayElement); 113 161 114 162 Element mlElement = theDoc.createElement(XML_TAGS.ML_TOT_VOL.tag); 115 163 mlElement.appendChild(theDoc.createTextNode(String.valueOf(this.MLTotVol))); 116 164 stationElement.appendChild(mlElement); 117 165 118 166 Element oppElement = theDoc.createElement(XML_TAGS.OPP_TOT_VOL.tag); 119 167 oppElement.appendChild(theDoc.createTextNode(String.valueOf(this.OppTotVol))); 120 168 stationElement.appendChild(oppElement); 121 169 122 170 Element loopsElement = theDoc.createElement(XML_TAGS.LOOPS.tag); 123 171 stationElement.appendChild(loopsElement); 124 125 for(LoopDetector loop : loops) 126 { 172 173 for (LoopDetector loop : loops) { 127 174 loop.toXML(loopsElement); 128 175 } 129 176 } 130 177 131 178 /** 132 179 * Enum for freeway direction. 133 * 180 * 134 181 * @author John A. Torres 135 182 * @version 9/10/2017 136 183 */ 137 public static enum DIRECTION 138 { 184 public static enum DIRECTION { 185 139 186 NORTH("N"), 140 187 SOUTH("S"), 141 188 EAST("E"), 142 189 WEST("W"); 143 190 144 191 String name; 145 146 DIRECTION(String name) 147 { 192 193 DIRECTION(String name) { 148 194 this.name = name; 149 195 } 150 196 151 197 /** 152 198 * Returns the direction enum, given a string value. 199 * 153 200 * @param name str value for enum 154 201 * @return enum for given str value 155 202 */ 156 public static DIRECTION getEnum(String name) 157 { 158 switch(name) 159 { 203 public static DIRECTION getEnum(String name) { 204 switch (name) { 160 205 case "S": 161 206 return SOUTH;
Note: See TracChangeset
for help on using the changeset viewer.
