From 99c1bb4d6ad787c8b474f8dffb001b1a2f56910b Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sat, 12 Mar 2022 03:45:06 +0100 Subject: [PATCH] Let IntelliJ format all files --- .../java/de/jotoho/waituntil/AppOptions.java | 14 ++----- .../java/de/jotoho/waituntil/GlobalConf.java | 4 +- src/main/java/de/jotoho/waituntil/Main.java | 39 +++++++------------ src/main/java/de/jotoho/waituntil/Sleep.java | 10 ++--- .../de/jotoho/waituntil/TimeCalculator.java | 25 ++++++------ 5 files changed, 36 insertions(+), 56 deletions(-) diff --git a/src/main/java/de/jotoho/waituntil/AppOptions.java b/src/main/java/de/jotoho/waituntil/AppOptions.java index 83d9412..4e2201f 100644 --- a/src/main/java/de/jotoho/waituntil/AppOptions.java +++ b/src/main/java/de/jotoho/waituntil/AppOptions.java @@ -4,19 +4,13 @@ import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; final class AppOptions { + public final static Option help = Option.builder().argName("h").longOpt("help").desc("Shows this help " + "message and exits").build(); + public final static Option version = Option.builder().argName("v").longOpt("version").desc("Shows version information and exits").build(); + private final static Options options = new Options().addOption(help).addOption(version); + // Disable Instance Creation private AppOptions() {} - public final static Option help = - Option.builder().argName("h").longOpt("help").desc("Shows this help " + - "message and exits").build(); - public final static Option version = - Option.builder().argName("v").longOpt("version").desc("Shows version information and exits").build(); - - private final static Options options = new Options() - .addOption(help) - .addOption(version); - public static Options getOptions() { return options; } diff --git a/src/main/java/de/jotoho/waituntil/GlobalConf.java b/src/main/java/de/jotoho/waituntil/GlobalConf.java index 08e8f7a..fad2f75 100644 --- a/src/main/java/de/jotoho/waituntil/GlobalConf.java +++ b/src/main/java/de/jotoho/waituntil/GlobalConf.java @@ -22,7 +22,5 @@ import java.util.Locale; public record GlobalConf() { public static final String langGerman = "de"; - public static final String applicationOutputLanguage = (Locale.getDefault().getLanguage().equals(Locale.GERMAN.getLanguage())) - ? Locale.GERMAN.getLanguage() - : Locale.ENGLISH.getLanguage(); + public static final String applicationOutputLanguage = (Locale.getDefault().getLanguage().equals(Locale.GERMAN.getLanguage())) ? Locale.GERMAN.getLanguage() : Locale.ENGLISH.getLanguage(); } diff --git a/src/main/java/de/jotoho/waituntil/Main.java b/src/main/java/de/jotoho/waituntil/Main.java index 272f3ea..1ea42c1 100644 --- a/src/main/java/de/jotoho/waituntil/Main.java +++ b/src/main/java/de/jotoho/waituntil/Main.java @@ -36,15 +36,15 @@ public final class Main { final var appVersion = thisPackage.getImplementationVersion() != null ? thisPackage.getImplementationVersion() : "version unknown"; System.out.println("waituntil " + appVersion); System.out.println(""" - Project Repository: https://gitea.jotoho.de/jotoho/waituntil + Project Repository: https://gitea.jotoho.de/jotoho/waituntil - This program is free software: you can redistribute it and/or modify it under the terms of the - GNU General Public License as published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. + This program is free software: you can redistribute it and/or modify it under the terms of the + GNU General Public License as published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details."""); + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details."""); } private static void printHelpInformation() { @@ -56,11 +56,7 @@ public final class Main { public static void main(final String[] args) { try { - final var parsedArguments = - DefaultParser.builder() - .setStripLeadingAndTrailingQuotes(true) - .build() - .parse(AppOptions.getOptions(), args); + final var parsedArguments = DefaultParser.builder().setStripLeadingAndTrailingQuotes(true).build().parse(AppOptions.getOptions(), args); final var userData = parsedArguments.getArgs(); @@ -70,29 +66,22 @@ public final class Main { printVersionInformation(); } else if (userData.length == 0) { switch (applicationOutputLanguage) { - case GlobalConf.langGerman -> logger.log(Level.ERROR, - "Es wurde keine Uhrzeit angegeben."); - default -> logger.log(Level.ERROR, "No target time" + - " was " + - "provided."); + case GlobalConf.langGerman -> logger.log(Level.ERROR, "Es wurde keine Uhrzeit angegeben."); + default -> logger.log(Level.ERROR, "No target time" + " was " + "provided."); } System.exit(1); } else if (userData.length > 1) { switch (applicationOutputLanguage) { - case GlobalConf.langGerman -> logger.log(Level.ERROR, - "Zu viele Argumente wurden angegeben."); - default -> logger.log(Level.ERROR, "Too many arguments " + - "provided."); + case GlobalConf.langGerman -> logger.log(Level.ERROR, "Zu viele Argumente wurden angegeben."); + default -> logger.log(Level.ERROR, "Too many arguments " + "provided."); } System.exit(1); } else { - final var target = - TimeCalculator.calculateAndAnnounceTargetTime(userData[0]); + final var target = TimeCalculator.calculateAndAnnounceTargetTime(userData[0]); Sleep.waitUntilTimeStamp(target); } } catch (final ParseException e) { - System.getLogger("main").log(Level.ERROR, "Parsing " + - "of arguments failed and the program cannot continue.", e); + System.getLogger("main").log(Level.ERROR, "Parsing " + "of arguments failed and the program cannot continue.", e); System.exit(1); } } diff --git a/src/main/java/de/jotoho/waituntil/Sleep.java b/src/main/java/de/jotoho/waituntil/Sleep.java index 9de0947..a5c56bd 100644 --- a/src/main/java/de/jotoho/waituntil/Sleep.java +++ b/src/main/java/de/jotoho/waituntil/Sleep.java @@ -23,9 +23,7 @@ import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; import java.time.temporal.ChronoUnit; -import java.util.*; - -import java.lang.Math; +import java.util.TimeZone; public final class Sleep { public static void waitUntilTimeStamp(ZonedDateTime timestamp) { @@ -35,9 +33,9 @@ public final class Sleep { } final String formattedTimeStamp = - DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG) - .withZone(TimeZone.getDefault().toZoneId()) - .format(Instant.now()); + DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG) + .withZone(TimeZone.getDefault().toZoneId()) + .format(Instant.now()); final String msg = switch (GlobalConf.applicationOutputLanguage) { case GlobalConf.langGerman -> "Erfolgreich bis %s gewartet!"; diff --git a/src/main/java/de/jotoho/waituntil/TimeCalculator.java b/src/main/java/de/jotoho/waituntil/TimeCalculator.java index 9f52dee..20b40fc 100644 --- a/src/main/java/de/jotoho/waituntil/TimeCalculator.java +++ b/src/main/java/de/jotoho/waituntil/TimeCalculator.java @@ -24,7 +24,8 @@ import java.time.LocalTime; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; -import java.util.*; +import java.util.TimeZone; + import static java.lang.System.Logger.Level; public final class TimeCalculator { @@ -32,24 +33,24 @@ public final class TimeCalculator { public static ZonedDateTime calculateAndAnnounceTargetTime(final String userTimeInputRaw) { final var userTimeInputRelative = LocalTime.parse(userTimeInputRaw); final var userTimeInputAbsolute = - ZonedDateTime.of( - LocalDate.now(), - userTimeInputRelative, - TimeZone.getDefault().toZoneId() - ); + ZonedDateTime.of( + LocalDate.now(), + userTimeInputRelative, + TimeZone.getDefault().toZoneId() + ); final var userTimeInputFinal = (Instant.now().isBefore(userTimeInputAbsolute.toInstant())) - ? userTimeInputAbsolute - : userTimeInputAbsolute.plusDays(1); + ? userTimeInputAbsolute + : userTimeInputAbsolute.plusDays(1); final var formattedTimeStamp = - userTimeInputFinal.format( - DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG) - ); + userTimeInputFinal.format( + DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG) + ); final String msg = switch (GlobalConf.applicationOutputLanguage) { case GlobalConf.langGerman -> "Dieses Program wird bis zum %s warten." - .formatted(formattedTimeStamp); + .formatted(formattedTimeStamp); default -> "WaitUntil will suspend until %s".formatted(formattedTimeStamp); }; System.getLogger("timecalculator").log(Level.INFO, msg);