Skip to content

Instantly share code, notes, and snippets.

@arturaz
Created October 10, 2012 13:35
Show Gist options
  • Save arturaz/3865690 to your computer and use it in GitHub Desktop.
Save arturaz/3865690 to your computer and use it in GitHub Desktop.
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