The second week Monday

1, the new code design

* FileName: FileIO.java
write processing files *
* /
public class {the FileIO

public static String READ_PATH; // read path
public static String WRITE_PATH; // write path

/**
* 读取文件初始化地铁线路
*/
public static void readSubway(List < Station > map) throws IOException {
File readfile = new File(READ_PATH);
BufferedReader reader = new BufferedReader(new FileReader(readfile));
String tempString = null;
while ((tempString = reader.readLine()) != null) {
int trim = tempString.indexOf(' ');
String lineNo = tempString.substring(0, trim);
tempString = tempString.substring(trim + 1);
String[] stations = tempString.split(" ");

for (String s: stations) { // initialize site
Station test = new Station (s, lineNo); // To add a station
if (map.contains (test)) { // have
int index = (map. the indexOf (Test));
as map.get (index) = .isInterchangeStation to true;
as map.get (index) .line.add (called lineNo);
} the else {
map.add (Test);
}
}

for (int i = 0; i < stations.length; i++) { //添加相邻站点
Station s = new Station(stations[i], lineNo);
int index = (map.indexOf(s));
if(stations.length==1) {
break;
}
if (i == 0) {
Station pres = new Station(stations[i + 1], lineNo);
int preindex = (map.indexOf(pres));
map.get(index).linkStations.add(map.get(preindex));
} else if (i == stations.length - 1) {
Station nexts = new Station(stations[i - 1], lineNo);
int nextindex = (map.indexOf(nexts));
map.get(index).linkStations.add(map.get(nextindex));
} else {
Station pres = new Station(stations[i + 1], lineNo);
int preindex = (map.indexOf(pres));
Station nexts = new Station(stations[i - 1], lineNo);
int nextindex = (map.indexOf(nexts));
map.get(index).linkStations.add(map.get(preindex));
map.get(index).linkStations.add(map.get(nextindex));
}
}
}
reader.close();
}

2. plans to continue tomorrow to complete the first function to achieve the text reads map

3. The program issues, not seen before achieved read, design, learning, inquiry interrogation procedure more difficult, slow progress.

Guess you like

Origin www.cnblogs.com/pekey/p/11414761.html