Better null checks
This commit is contained in:
		| @ -42,11 +42,7 @@ class TimetableParser(timetableURL: String? = null, htmlDoc: Document? = null) { | |||||||
|         val semaphore = Semaphore(3, 0) |         val semaphore = Semaphore(3, 0) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private val htmlDoc: Document? = |     private val htmlDoc: Document? = htmlDoc ?: timetableURL?.let { | ||||||
|         htmlDoc |  | ||||||
|             ?: if (timetableURL == null) { |  | ||||||
|                 null |  | ||||||
|             } else { |  | ||||||
|         runBlocking { |         runBlocking { | ||||||
|             try { |             try { | ||||||
|                 // Only allow sending a limited amount of requests at the same time |                 // Only allow sending a limited amount of requests at the same time | ||||||
| @ -66,13 +62,9 @@ class TimetableParser(timetableURL: String? = null, htmlDoc: Document? = null) { | |||||||
|      * the timetable is organised per row not per column; |      * the timetable is organised per row not per column; | ||||||
|      * Mon 1, Tue 1, Wed 1, Thur 1, Fri 1, Sat 1, Mon 2 and so on |      * Mon 1, Tue 1, Wed 1, Thur 1, Fri 1, Sat 1, Mon 2 and so on | ||||||
|      */ |      */ | ||||||
|     fun parseTimeTable(): TimetableWeek? { |     fun parseTimeTable(): TimetableWeek? = htmlDoc?.let { | ||||||
|         if (htmlDoc == null) { |  | ||||||
|             return null |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         val timetableWeek = TimetableWeek() |         val timetableWeek = TimetableWeek() | ||||||
|         val rows = htmlDoc.select("table.timetable").select("tr[scope=\"row\"]") |         val rows = it.select("table.timetable").select("tr[scope=\"row\"]") | ||||||
|  |  | ||||||
|         var sDay = -1 |         var sDay = -1 | ||||||
|         var sRow = -1 |         var sRow = -1 | ||||||
| @ -141,12 +133,8 @@ class TimetableParser(timetableURL: String? = null, htmlDoc: Document? = null) { | |||||||
|     /** |     /** | ||||||
|      * parse the week number of the year for the timetable |      * parse the week number of the year for the timetable | ||||||
|      */ |      */ | ||||||
|     fun parseWeekNumberYear(): Int? { |     fun parseWeekNumberYear(): Int? = htmlDoc?.let { | ||||||
|         if (htmlDoc == null) { |         it.select("h1.timetable-caption").text().substringAfter("- ") | ||||||
|             return null |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return htmlDoc.select("h1.timetable-caption").text().substringAfter("- ") |  | ||||||
|             .substringBefore(".").replace(" ", "").toInt() |             .substringBefore(".").replace(" ", "").toInt() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user