From f98dc3d808041185d08c6a8530c54c5d8573a31f Mon Sep 17 00:00:00 2001 From: Hannes Braun Date: Wed, 13 Oct 2021 16:39:01 +0200 Subject: [PATCH] Small improvements - Improve formatting - Fix some typos - Mini code improvements --- .../thecitadelofricks/controller/CacheController.kt | 12 ++++++------ .../controller/StartupController.kt | 3 ++- .../thecitadelofricks/controller/StatusController.kt | 2 +- .../thecitadelofricks/hsoparser/TimetableParser.kt | 5 ++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/org/mosad/thecitadelofricks/controller/CacheController.kt b/src/main/kotlin/org/mosad/thecitadelofricks/controller/CacheController.kt index 24d4ddd..879098b 100644 --- a/src/main/kotlin/org/mosad/thecitadelofricks/controller/CacheController.kt +++ b/src/main/kotlin/org/mosad/thecitadelofricks/controller/CacheController.kt @@ -48,11 +48,11 @@ class CacheController { scheduledUpdates() } - companion object{ + companion object { private val logger: Logger = LoggerFactory.getLogger(CacheController::class.java) var courseList = CoursesList(CoursesMeta(), sortedMapOf()) - var mensaMenu = MensaMenu(MensaMeta(0,""), MensaWeek(), MensaWeek()) + var mensaMenu = MensaMenu(MensaMeta(0, ""), MensaWeek(), MensaWeek()) var timetableList = HashMap() // this list contains all timetables /** @@ -68,7 +68,7 @@ class CacheController { val currentTime = System.currentTimeMillis() / 1000 val timetableLink = "https://mosad.xyz" val weekNumberYear = 0 - val instr = javaClass.getResourceAsStream("/html/Timetable_normal-week.html") + val instr = CacheController::class.java.getResourceAsStream("/html/Timetable_normal-week.html") val timetableParser = TimetableParser(htmlDoc = Jsoup.parse(instr, "UTF-8", "https://www.hs-offenburg.de/")) @@ -151,7 +151,7 @@ class CacheController { /** * this function updates the courseList - * during the update process the old data will be returned for a API request + * during the update process the old data will be returned for an API request */ private fun asyncUpdateCourseList() = GlobalScope.launch { CourseListParser().getCourseLinks(StartupController.courseListURL)?.let { @@ -167,7 +167,7 @@ class CacheController { /** * this function updates the mensa menu list - * during the update process the old data will be returned for a API request + * during the update process the old data will be returned for an API request */ private fun asyncUpdateMensa() = GlobalScope.launch { val mensaCurrentWeek = MensaParser().getMensaMenu(StartupController.mensaMenuURL) @@ -183,7 +183,7 @@ class CacheController { /** * this function updates all existing timetables - * during the update process the old data will be returned for a API request + * during the update process the old data will be returned for an API request * a FixedThreadPool is used to make parallel requests for faster updates */ private fun asyncUpdateTimetables() = GlobalScope.launch { diff --git a/src/main/kotlin/org/mosad/thecitadelofricks/controller/StartupController.kt b/src/main/kotlin/org/mosad/thecitadelofricks/controller/StartupController.kt index 05446ac..57ef721 100644 --- a/src/main/kotlin/org/mosad/thecitadelofricks/controller/StartupController.kt +++ b/src/main/kotlin/org/mosad/thecitadelofricks/controller/StartupController.kt @@ -135,7 +135,8 @@ class StartupController { try { val timetableObject = JsonParser.parseString(bufferedReader.readLine()).asJsonObject val timetable = Gson().fromJson(timetableObject, TimetableCourseWeek().javaClass) - CacheController.timetableList.put("${timetable.meta.courseName}-${timetable.meta.weekIndex}", timetable) + CacheController.timetableList["${timetable.meta.courseName}-${timetable.meta.weekIndex}"] = + timetable } catch (ex: Exception) { logger.error("error while reading cache", ex) } finally { diff --git a/src/main/kotlin/org/mosad/thecitadelofricks/controller/StatusController.kt b/src/main/kotlin/org/mosad/thecitadelofricks/controller/StatusController.kt index 09f6da7..e32e547 100644 --- a/src/main/kotlin/org/mosad/thecitadelofricks/controller/StatusController.kt +++ b/src/main/kotlin/org/mosad/thecitadelofricks/controller/StatusController.kt @@ -62,7 +62,7 @@ class StatusController { } fun updateTimetableRequests(courseName: String) { - timetableRequests[courseName] = timetableRequests.getOrPut(courseName) {0} + 1 + timetableRequests[courseName] = (timetableRequests[courseName] ?: 0) + 1 totalRequests++ } diff --git a/src/main/kotlin/org/mosad/thecitadelofricks/hsoparser/TimetableParser.kt b/src/main/kotlin/org/mosad/thecitadelofricks/hsoparser/TimetableParser.kt index c544530..39e386c 100644 --- a/src/main/kotlin/org/mosad/thecitadelofricks/hsoparser/TimetableParser.kt +++ b/src/main/kotlin/org/mosad/thecitadelofricks/hsoparser/TimetableParser.kt @@ -72,7 +72,7 @@ class TimetableParser(timetableURL: String? = null, htmlDoc: Document? = null) { var lessonIndexDay = 0 // the index of the lesson per timeslot // elements are now all lessons, including empty ones - row.select("td.lastcol, td[style]").forEach {element -> + row.select("td.lastcol, td[style]").forEach { element -> // if there is a lecture with rowspan="2", we need to shift everything by one to the left. This is stupid and ugly there needs to bee an API if ((sDay > -1 && sRow > -1) && (sDay == day && ((sRow + 1) == rowIndex))) { @@ -115,8 +115,7 @@ class TimetableParser(timetableURL: String? = null, htmlDoc: Document? = null) { lessonIndexDay++ - if (element.hasClass("lastcol")) - { + if (element.hasClass("lastcol")) { day++ lessonIndexDay = 0 }