From 9aba3f156a6e4df4e628bc99f5ee5f797d37ecef Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 20:08:50 +0200 Subject: [PATCH] Apply IntelliJ code formatting and alternatives suggestions --- .../kotlin/de/jotoho/waituntil/sleeping.kt | 4 +- src/main/kotlin/de/jotoho/waituntil/start.kt | 37 ++++++++++--------- .../kotlin/de/jotoho/waituntil/timecalc.kt | 2 +- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/de/jotoho/waituntil/sleeping.kt b/src/main/kotlin/de/jotoho/waituntil/sleeping.kt index b318873..ae031b7 100644 --- a/src/main/kotlin/de/jotoho/waituntil/sleeping.kt +++ b/src/main/kotlin/de/jotoho/waituntil/sleeping.kt @@ -7,8 +7,8 @@ import java.time.format.FormatStyle import java.time.temporal.ChronoUnit import java.util.* -public fun waitUntilTimeStamp(timestamp: ZonedDateTime) { - Thread.sleep(Math.max(Instant.now().until(timestamp, ChronoUnit.MILLIS), 0)) +fun waitUntilTimeStamp(timestamp: ZonedDateTime) { + Thread.sleep(Instant.now().until(timestamp, ChronoUnit.MILLIS).coerceAtLeast(0)) val formattedTimeStamp: String = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG) diff --git a/src/main/kotlin/de/jotoho/waituntil/start.kt b/src/main/kotlin/de/jotoho/waituntil/start.kt index 4ed1795..16a0ce6 100644 --- a/src/main/kotlin/de/jotoho/waituntil/start.kt +++ b/src/main/kotlin/de/jotoho/waituntil/start.kt @@ -1,56 +1,57 @@ package de.jotoho.waituntil import java.util.* +import kotlin.system.exitProcess // This file contains the main function and other utility function necessary for interpreting the terminal arguments. // See README.md and LICENSE.md for license information // Author: Jonas Tobias Hopusch (@jotoho) -val langGerman: String = Locale.GERMAN.getLanguage(); -val applicationOutputLanguage: String = if (Locale.getDefault().getLanguage().equals(Locale.GERMAN.getLanguage())) - Locale.GERMAN.getLanguage() - else Locale.ENGLISH.getLanguage(); +val langGerman: String = Locale.GERMAN.language +val applicationOutputLanguage: String = if (Locale.getDefault().language.equals(Locale.GERMAN.language)) + Locale.GERMAN.language + else Locale.ENGLISH.language fun main(args: Array) { - val optionDictionary = mapOf(Pair("-h", "--help")); + val optionDictionary = mapOf(Pair("-h", "--help")) - val options = HashSet(); - val words = HashSet(); + val options = HashSet() + val words = HashSet() for (arg in args) { if (arg.startsWith("--")) { options.add(arg.substring(startIndex=2)) } else if (arg.startsWith('-')) { - val translation = optionDictionary.get(arg); + val translation = optionDictionary[arg] if (translation != null) - options.add(translation.substring(startIndex=2)); + options.add(translation.substring(startIndex=2)) else - System.err.println("Short-hand '$arg' does not exist. Ignoring!"); + System.err.println("Short-hand '$arg' does not exist. Ignoring!") } else - words.add(arg); + words.add(arg) } if (options.contains("help")) { when (applicationOutputLanguage) { - langGerman -> println("Hilfe kommt noch. (Nicht implementiert)"); + langGerman -> println("Hilfe kommt noch. (Nicht implementiert)") else -> { - println("Help is yet to come. (Not implemented)"); + println("Help is yet to come. (Not implemented)") } } } else if (words.size == 1) { - val target = calculateAndAnnounceTargetTime(words.iterator().next()); - waitUntilTimeStamp(target); + val target = calculateAndAnnounceTargetTime(words.iterator().next()) + waitUntilTimeStamp(target) } else { when (applicationOutputLanguage) { - langGerman -> System.err.println("FATAL: Es wurde exact ein nicht-flag Argument erwartet. (${words.size} erhalten)"); + langGerman -> System.err.println("FATAL: Es wurde exact ein nicht-flag Argument erwartet. (${words.size} erhalten)") else -> { - System.err.println("FATAL: Expected one non-flag argument. (Got ${words.size})"); + System.err.println("FATAL: Expected one non-flag argument. (Got ${words.size})") } } - System.exit(1); + exitProcess(1) } } diff --git a/src/main/kotlin/de/jotoho/waituntil/timecalc.kt b/src/main/kotlin/de/jotoho/waituntil/timecalc.kt index 36c17a8..4a52357 100644 --- a/src/main/kotlin/de/jotoho/waituntil/timecalc.kt +++ b/src/main/kotlin/de/jotoho/waituntil/timecalc.kt @@ -8,7 +8,7 @@ import java.time.format.DateTimeFormatter import java.time.format.FormatStyle import java.util.TimeZone -public fun calculateAndAnnounceTargetTime(userTimeInputRaw: String): ZonedDateTime { +fun calculateAndAnnounceTargetTime(userTimeInputRaw: String): ZonedDateTime { val userTimeInputRelative = LocalTime.parse(userTimeInputRaw) val userTimeInputAbsolute = ZonedDateTime.of(