Changeset 92 in tmcsimulator
- Timestamp:
- 10/11/2017 11:46:35 AM (9 years ago)
- File:
-
- 1 edited
-
trunk/src/atmsdriver/model/Station.java (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/atmsdriver/model/Station.java
r90 r92 9 9 * 10 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. 11 * attributes, MLTotVol and OppTotVol. * A single LDS contains multiple 12 * LoopDetectors, which contain data for a single lane on one direction of the 13 * freeway. A LDS is specific to a single freeway, direction, and postmile. 15 14 * 16 15 * @author John A. Torres 17 16 * @version 9/10/2017 18 17 */ 19 public class Station implements Comparable { 18 public class Station implements Comparable 19 { 20 20 21 /* Static Station meta data */ 21 22 22 final private int lineNum; 23 23 final private int ldsID; // double check … … 36 36 public Station(int lineNum, int ldsID, int drop, 37 37 String location, List<LoopDetector> loops, int hwy, 38 DIRECTION direction, double postmile) { 38 DIRECTION direction, double postmile) 39 { 39 40 this.lineNum = lineNum; 40 41 this.ldsID = ldsID; … … 54 55 return this.highwayNum; 55 56 } 56 57 57 58 public DIRECTION getDirection() 58 59 { 59 60 return this.direction; 60 61 } 61 62 62 63 /** 63 64 * Returns the station metadata in condensed form. This is just a quick … … 67 68 * @return station metadata 68 69 */ 69 public String getStationMeta() { 70 public String getStationMeta() 71 { 70 72 StringBuilder build = new StringBuilder(); 71 73 build.append(Integer.toString(this.ldsID)); … … 83 85 build.append(this.location); 84 86 build.append("\n"); 85 for (LoopDetector loop : loops) { 87 for (LoopDetector loop : loops) 88 { 86 89 build.append(loop.getLoopMeta()); 87 90 } … … 89 92 } 90 93 91 public double getPostmile() { 94 public double getPostmile() 95 { 92 96 return postmile; 93 97 } 94 98 95 /** Compare this Station to another by postmile. 96 * Note: This might be better as a Comparator since it checks only one field. 99 /** 100 * Compare this Station to another by postmile. Note: This might be better 101 * as a Comparator since it checks only one field. 97 102 */ 98 103 @Override 99 public int compareTo(Object otherStation) { 104 public int compareTo(Object otherStation) 105 { 100 106 // check for identity 101 if (this == otherStation) return 0; 107 if (this == otherStation) 108 { 109 return 0; 110 } 102 111 // check that Object is of type Station, if not throw exception 103 if (!(otherStation instanceof Station)) { 112 if (!(otherStation instanceof Station)) 113 { 104 114 throw new ClassCastException("A Station object expected."); 105 115 } … … 111 121 // set appropriate comparable return value 112 122 int retval = 0; 113 if (val > 0) { 123 if (val > 0) 124 { 114 125 retval = 1; 115 } else if (val < 0) { 126 } 127 else if (val < 0) 128 { 116 129 retval = -1; 117 130 } … … 120 133 } 121 134 122 private static enum XML_TAGS { 135 private static enum XML_TAGS 136 { 123 137 124 138 STATION("Station"), … … 136 150 String tag; 137 151 138 private XML_TAGS(String n) { 152 private XML_TAGS(String n) 153 { 139 154 tag = n; 140 155 } 141 156 } 142 157 143 public void toXML(Element currElem) { 158 public void toXML(Element currElem) 159 { 144 160 Document theDoc = currElem.getOwnerDocument(); 145 161 … … 168 184 169 185 Element directionElement = theDoc.createElement(XML_TAGS.DIRECTION.tag); 170 directionElement.appendChild(theDoc.createTextNode("" +this.direction.getLetter()));186 directionElement.appendChild(theDoc.createTextNode("" + this.direction.getLetter())); 171 187 stationElement.appendChild(directionElement); 172 188 … … 186 202 stationElement.appendChild(loopsElement); 187 203 188 for (LoopDetector loop : loops) { 204 for (LoopDetector loop : loops) 205 { 189 206 loop.toXML(loopsElement); 190 207 } … … 197 214 * @version 9/10/2017 198 215 */ 199 public static enum DIRECTION { 216 public static enum DIRECTION 217 { 200 218 201 219 NORTH, … … 207 225 private static String allLetters = "NSEW"; 208 226 209 /** Return the first letter of this enum. 210 * 227 /** 228 * Return the first letter of this enum. 229 * 211 230 * @return String first letter of this enum. 212 231 */ 213 232 public String getLetter() 214 233 { 215 return this.toString().substring(0, 1);216 } 217 234 return this.toString().substring(0, 1); 235 } 236 218 237 /** 219 238 * Returns a direction given its first character. … … 227 246 return values()[allLetters.indexOf(letter.charAt(0))]; 228 247 } 229 248 230 249 } 231 250 }
Note: See TracChangeset
for help on using the changeset viewer.
