66 lines
2.1 KiB
Kotlin
66 lines
2.1 KiB
Kotlin
package org.mosad.seil0.projectlaogai.controller
|
|
|
|
import org.mosad.seil0.projectlaogai.util.Lesson
|
|
|
|
/**
|
|
* TODO this controller contains
|
|
* * a list with all additional lessons
|
|
* * the main course and additional info for timetables
|
|
* * all concrete objects
|
|
*/
|
|
class TimetableController {
|
|
|
|
companion object {
|
|
val aLessons = HashMap<String, Lesson>() // the key is courseName_lessonID
|
|
val aSubjectMap = HashMap<String, ArrayList<String>>()
|
|
|
|
/**
|
|
* add a subject to the subjects map and all it's lessons
|
|
* to the aLessons list
|
|
* @param courseName course to which the subject belongs
|
|
* @param subject the subjects name
|
|
*/
|
|
fun addASubject(courseName: String, subject: String) {
|
|
// add subject
|
|
if (aSubjectMap.containsKey(courseName)) {
|
|
aSubjectMap[courseName]?.add(subject)
|
|
} else {
|
|
aSubjectMap[courseName] = arrayListOf(subject)
|
|
}
|
|
|
|
// add concrete lessons
|
|
TCoRAPIController.getLessons(courseName, subject, 0).forEach {lesson ->
|
|
//the courseName, subject and lessonID, separator: -
|
|
val key = "$courseName-$subject-${lesson.lessonID}"
|
|
aLessons[key] = lesson
|
|
}
|
|
println(aLessons)
|
|
}
|
|
|
|
/**
|
|
* remove a subject from the subjects map and all it's lessons
|
|
* from the aLessons list
|
|
* @param courseName course to which the subject belongs
|
|
* @param subject the subjects name
|
|
*/
|
|
fun removeASubject(courseName: String, subject: String) {
|
|
// remove subject
|
|
|
|
aSubjectMap[courseName]?.remove(subject)
|
|
|
|
// remove concrete lessons
|
|
|
|
println(aLessons)
|
|
val iter = aLessons.iterator()
|
|
while (iter.hasNext()) {
|
|
val it = iter.next()
|
|
if(it.key.contains("$courseName-$subject")) {
|
|
println(it.key)
|
|
iter.remove() // use iterator to remove, otherwise ConcurrentModificationException
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
} |