| 1 | |
|---|
| 2 | package extendlds; |
|---|
| 3 | |
|---|
| 4 | import java.io.File; |
|---|
| 5 | import java.io.FileNotFoundException; |
|---|
| 6 | import java.io.FileWriter; |
|---|
| 7 | import java.io.IOException; |
|---|
| 8 | import java.io.PrintWriter; |
|---|
| 9 | import java.util.Scanner; |
|---|
| 10 | import java.util.logging.Level; |
|---|
| 11 | import java.util.logging.Logger; |
|---|
| 12 | |
|---|
| 13 | /** |
|---|
| 14 | * |
|---|
| 15 | * @author jtorres |
|---|
| 16 | */ |
|---|
| 17 | public class ExtendLDS |
|---|
| 18 | { |
|---|
| 19 | final private String ldsFileName = "newlds.txt"; |
|---|
| 20 | final private String loopFileName = "newloop.txt"; |
|---|
| 21 | |
|---|
| 22 | // Returns the loction given the whole line from the lookup file |
|---|
| 23 | private String getLDSName(String line) |
|---|
| 24 | { |
|---|
| 25 | Scanner lineScanner = new Scanner(line); |
|---|
| 26 | |
|---|
| 27 | lineScanner.nextInt(); |
|---|
| 28 | lineScanner.nextInt(); |
|---|
| 29 | lineScanner.nextInt(); |
|---|
| 30 | lineScanner.nextInt(); // skip LDS column |
|---|
| 31 | lineScanner.nextInt(); |
|---|
| 32 | lineScanner.next(); |
|---|
| 33 | lineScanner.nextFloat(); |
|---|
| 34 | |
|---|
| 35 | /** GRABS FROM CURRENT TO END OF LINE */ |
|---|
| 36 | lineScanner.useDelimiter("\\z"); |
|---|
| 37 | String loc = lineScanner.next().trim(); |
|---|
| 38 | lineScanner.close(); |
|---|
| 39 | return loc; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | // Returns the loction given the whole line from the lookup file |
|---|
| 43 | private String getLoopName(String line) |
|---|
| 44 | { |
|---|
| 45 | Scanner lineScanner = new Scanner(line); |
|---|
| 46 | |
|---|
| 47 | Integer fwy = lineScanner.nextInt(); |
|---|
| 48 | String dir = lineScanner.next(); |
|---|
| 49 | Float postmile = lineScanner.nextFloat(); |
|---|
| 50 | Integer ldsID = lineScanner.nextInt(); |
|---|
| 51 | Integer vdsID = lineScanner.nextInt(); |
|---|
| 52 | Integer loopID = lineScanner.nextInt(); |
|---|
| 53 | String shortLoc = lineScanner.next(); |
|---|
| 54 | Integer laneNum = lineScanner.nextInt(); |
|---|
| 55 | |
|---|
| 56 | /** GRABS FROM CURRENT TO END OF LINE */ |
|---|
| 57 | lineScanner.useDelimiter("\\z"); |
|---|
| 58 | String loc = lineScanner.next().trim(); |
|---|
| 59 | lineScanner.close(); |
|---|
| 60 | return loc; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | public ExtendLDS() |
|---|
| 64 | { |
|---|
| 65 | try |
|---|
| 66 | { |
|---|
| 67 | Scanner ldsScanner = new Scanner(new File(ldsFileName)); |
|---|
| 68 | Scanner loopScanner = new Scanner(new File(loopFileName)); |
|---|
| 69 | PrintWriter ldsWriter = new PrintWriter(new File("extend_lds_file.txt")); |
|---|
| 70 | PrintWriter loopWriter = new PrintWriter(new File("extend_loop_file.txt")); |
|---|
| 71 | |
|---|
| 72 | System.out.println(ldsScanner.nextLine()); |
|---|
| 73 | |
|---|
| 74 | while(ldsScanner.hasNextLine()) |
|---|
| 75 | { |
|---|
| 76 | String line = ldsScanner.nextLine(); |
|---|
| 77 | Scanner lineScanner = new Scanner(line); |
|---|
| 78 | Integer lds_id = lineScanner.nextInt(); |
|---|
| 79 | Integer linenum = lineScanner.nextInt(); |
|---|
| 80 | Integer dropnum = lineScanner.nextInt(); |
|---|
| 81 | lineScanner.nextInt(); // skip LDS column |
|---|
| 82 | Integer fwy = lineScanner.nextInt(); |
|---|
| 83 | String direction = lineScanner.next(); |
|---|
| 84 | Float postmile = lineScanner.nextFloat(); |
|---|
| 85 | String LDS_NAME = getLDSName(line); |
|---|
| 86 | |
|---|
| 87 | ldsWriter.print(Integer.toString(lds_id) + "\t"); // write lds id |
|---|
| 88 | ldsWriter.print(Integer.toString(linenum) + "\t"); // write line num |
|---|
| 89 | ldsWriter.print(Integer.toString(dropnum) + "\t"); // write drop num |
|---|
| 90 | ldsWriter.print("0" + "\t"); // 0 write sch |
|---|
| 91 | ldsWriter.print("0" + "\t"); // 0 write lineinfo |
|---|
| 92 | ldsWriter.print("0" + "\t"); // 0 write syskey |
|---|
| 93 | ldsWriter.print("0" + "\t");// 0 write sch seq |
|---|
| 94 | ldsWriter.print("0" + "\t");// 0 write glo seq |
|---|
| 95 | ldsWriter.print("0" + "\t");// 0 write count |
|---|
| 96 | ldsWriter.print(Integer.toString(fwy) + "\t");// write fwy |
|---|
| 97 | ldsWriter.print(direction + "\t");// write dir |
|---|
| 98 | ldsWriter.print(Float.toString(postmile) + "\t");// write ca pm |
|---|
| 99 | ldsWriter.print(LDS_NAME + "\t");// writ string location |
|---|
| 100 | ldsWriter.print("\n"); |
|---|
| 101 | lineScanner.close(); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | loopScanner.nextLine(); |
|---|
| 105 | |
|---|
| 106 | while(loopScanner.hasNextLine()) |
|---|
| 107 | { |
|---|
| 108 | String line = loopScanner.nextLine(); |
|---|
| 109 | Scanner lineScanner = new Scanner(line); |
|---|
| 110 | |
|---|
| 111 | Integer fwy = lineScanner.nextInt(); |
|---|
| 112 | String dir = lineScanner.next(); |
|---|
| 113 | Float postmile = lineScanner.nextFloat(); |
|---|
| 114 | Integer ldsID = lineScanner.nextInt(); |
|---|
| 115 | Integer vdsID = lineScanner.nextInt(); |
|---|
| 116 | Integer loopID = lineScanner.nextInt(); |
|---|
| 117 | String shortLoc = lineScanner.next(); |
|---|
| 118 | Integer laneNum = lineScanner.nextInt(); |
|---|
| 119 | String LOOP_NAME = getLoopName(line); |
|---|
| 120 | |
|---|
| 121 | loopWriter.print(fwy + "\t"); |
|---|
| 122 | loopWriter.print(dir+ "\t"); |
|---|
| 123 | loopWriter.print(postmile + "\t"); |
|---|
| 124 | loopWriter.print(ldsID + "\t"); |
|---|
| 125 | loopWriter.print(vdsID + "\t"); |
|---|
| 126 | loopWriter.print(loopID + "\t"); |
|---|
| 127 | loopWriter.print(shortLoc + "\t"); |
|---|
| 128 | loopWriter.print(laneNum + "\t"); |
|---|
| 129 | loopWriter.print(LOOP_NAME.replace(" ", "_") + "\t"); |
|---|
| 130 | loopWriter.print("?" + "\t"); |
|---|
| 131 | loopWriter.print("0" + "\t"); |
|---|
| 132 | loopWriter.print('\n'); |
|---|
| 133 | |
|---|
| 134 | lineScanner.close(); |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | ldsScanner.close(); |
|---|
| 138 | loopScanner.close(); |
|---|
| 139 | ldsWriter.close(); |
|---|
| 140 | loopWriter.close(); |
|---|
| 141 | |
|---|
| 142 | } catch (FileNotFoundException ex) |
|---|
| 143 | { |
|---|
| 144 | Logger.getLogger(ExtendLDS.class.getName()).log(Level.SEVERE, null, ex); |
|---|
| 145 | } catch (IOException ex) |
|---|
| 146 | { |
|---|
| 147 | Logger.getLogger(ExtendLDS.class.getName()).log(Level.SEVERE, null, ex); |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | } |
|---|
| 151 | /** |
|---|
| 152 | * @param args the command line arguments |
|---|
| 153 | */ |
|---|
| 154 | public static void main(String[] args) |
|---|
| 155 | { |
|---|
| 156 | ExtendLDS extend = new ExtendLDS(); |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | } |
|---|