- Timestamp:
- 10/30/2017 01:35:05 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
src/atmsdriver/model/Highways.java (modified) (3 diffs)
-
src/atmsdriver/model/Station.java (modified) (1 diff)
-
test/atmsdriver/model/HighwaysTest.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/atmsdriver/model/Highways.java
r190 r191 198 198 { 199 199 Scanner sc = new Scanner(new File(highwaysMapFileName)); 200 // first line of file contains number of FEP Lines 200 201 String firstLine = sc.nextLine(); 201 202 202 Scanner linesc = new Scanner(firstLine); 203 203 int numLines = linesc.nextInt(); 204 204 linesc.close(); 205 205 // FOR each FEP Line 206 206 for (int i = 0; i < numLines; i++) 207 207 { … … 227 227 String line = sc.nextLine(); 228 228 Scanner scline = new Scanner(line); 229 229 // Get the attribute of this FEP Line 230 230 int lineNum = scline.nextInt(); 231 231 int count = scline.nextInt(); 232 232 int numStations = scline.nextInt(); 233 233 ArrayList<Station> stations = new ArrayList<>(); 234 // Read all the stations for thie FEP Line 234 235 for (int i = 0; i < numStations; i++) 235 236 { … … 473 474 } 474 475 476 /** Return a string representation of the Highways */ 477 public String toString() 478 { 479 StringBuilder result = new StringBuilder(); 480 for (Highway hwy: highways) 481 { 482 result.append(""+String.format("%3s ",hwy.routeNumber)); 483 for (Station stat: hwy.stations) 484 { 485 result.append(stat.getColorByDirection(stat.direction)); 486 } 487 result.append("\n"); 488 } 489 return result.toString(); 490 } 475 491 /** 476 492 * XML tags used in writeToXML() -
trunk/src/atmsdriver/model/Station.java
r190 r191 195 195 196 196 /** 197 * Return the color for the lanes in a given direction. 198 * @param direction 199 * @return character representing color of lanes in given direction 200 * '@' = red, '+' = yellow, '-' = green 201 */ 202 public char getColorByDirection(DIRECTION direction) 203 { 204 /* For now just use the color of the first lane. 205 * TODO: Average the color in all the lanes for the given direction */ 206 207 String laneDir = "OS"; 208 if(direction.equals(this.direction)) 209 { 210 laneDir = "ML"; 211 } 212 // Examine all the lanes in a given direction 213 for(LoopDetector loop : loops) 214 { 215 if(loop.loopLocation.startsWith(laneDir)) 216 { 217 // Return color according to loop volume 218 if (loop.vol == 1) return '@'; 219 if (loop.vol == 3) return '+'; 220 } 221 } 222 // Default case 223 return '-'; 224 225 } 226 227 /** 197 228 * Output for updateByDirection. Logs the update to the console. 198 229 * -
trunk/test/atmsdriver/model/HighwaysTest.java
r185 r191 43 43 44 44 /** 45 * Test of toXML method, of class Network. 45 * Test of toString method 46 */ 47 public void testToString() { 48 System.out.println("toString"); 49 Highways highways = new Highways( 50 "config/vds_data/highways_fullmap.txt", 51 "localhost", 8080); 52 highways.getHighwayByRouteNumber(5).stations.get(0).loops.get(0).vol = 1; 53 String result = highways.toString(); 54 System.out.println(result); 55 assertEquals(expString, result); 56 } 57 String expString = 58 "241 ------------------------------------------------------------\n" 59 +" 5 @-------------------------------------------------------------------------------------------------------------------------------------------\n" 60 +"405 --------------------------------------------------------------------------------\n" 61 +"133 ----------------\n" 62 +"261 -----------------\n" 63 +" 22 ----------------------------------\n" 64 +" 55 ------------------------------------------\n" 65 +" 73 -----------------------------------------------------\n" 66 +" 57 ------------------------------------------\n" 67 +" 91 --------------------------------------------------------------\n" 68 +"605 ---\n"; 69 70 /** 71 * Test of toXML method 46 72 */ 47 73 public void testToXML() { 48 74 System.out.println("toXML"); 49 75 Highways highways = new Highways( 50 "config/vds_data/highways Meta.txt",76 "config/vds_data/highways_fullmap.txt", 51 77 "localhost", 8080); 52 78 String result = highways.toXML();
Note: See TracChangeset
for help on using the changeset viewer.
