Created
October 10, 2012 13:35
-
-
Save arturaz/3865690 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse(file: File): ListBuffer[Schedule] = { | |
val reader = new BufferedReader(new FileReader(file)) | |
try { | |
val schedules = ListBuffer.empty[Schedule] | |
var basicSchedule: BasicSchedule = null | |
var origin: OriginLocation = null | |
var intermediateLocations = ListBuffer.empty[IntermediateLocation] | |
var line: String = reader.readLine() | |
while (line != null) { | |
if (basicSchedule == null) { | |
parse(this.basicScheduleWoNl, line).map { bs => | |
basicSchedule = bs | |
} | |
} | |
else { | |
if (origin == null) { | |
parse(this.originLocationWoNl, line).map { loc => | |
origin = loc | |
} | |
} | |
else { | |
parse(intermediateLocationWoNl, line).map { loc => | |
intermediateLocations += loc | |
}.getOrElse { | |
parse(terminatingLocationWoNl, line).map { terminating => | |
schedules += Schedule( | |
basicSchedule, origin, intermediateLocations.toList, | |
terminating | |
) | |
basicSchedule = null | |
origin = null | |
intermediateLocations.clear() | |
} | |
} | |
} | |
} | |
line = reader.readLine() | |
} | |
schedules | |
} | |
finally { | |
reader.close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment