Some tweaks to the formatting settings
This commit is contained in:
parent
240a3784ed
commit
ca26a0e652
7 changed files with 59 additions and 93 deletions
|
@ -1,7 +1,7 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<option name="LINE_SEPARATOR" value=" " />
|
||||
<option name="RIGHT_MARGIN" value="80" />
|
||||
<option name="RIGHT_MARGIN" value="100" />
|
||||
<option name="WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN" value="true" />
|
||||
<option name="ENABLE_SECOND_REFORMAT" value="true" />
|
||||
<option name="SOFT_MARGINS" value="80" />
|
||||
|
@ -40,7 +40,6 @@
|
|||
<option name="EXTENDS_KEYWORD_WRAP" value="1" />
|
||||
<option name="THROWS_KEYWORD_WRAP" value="1" />
|
||||
<option name="METHOD_CALL_CHAIN_WRAP" value="2" />
|
||||
<option name="WRAP_FIRST_METHOD_IN_CALL_CHAIN" value="true" />
|
||||
<option name="BINARY_OPERATION_WRAP" value="1" />
|
||||
<option name="TERNARY_OPERATION_WRAP" value="5" />
|
||||
<option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" />
|
||||
|
@ -52,12 +51,13 @@
|
|||
<option name="ARRAY_INITIALIZER_WRAP" value="5" />
|
||||
<option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" />
|
||||
<option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" />
|
||||
<option name="ASSIGNMENT_WRAP" value="5" />
|
||||
<option name="ASSIGNMENT_WRAP" value="1" />
|
||||
<option name="ASSERT_STATEMENT_WRAP" value="1" />
|
||||
<option name="WRAP_LONG_LINES" value="true" />
|
||||
<option name="PARAMETER_ANNOTATION_WRAP" value="5" />
|
||||
<option name="VARIABLE_ANNOTATION_WRAP" value="5" />
|
||||
<option name="ENUM_CONSTANTS_WRAP" value="5" />
|
||||
<option name="KEEP_BUILDER_METHODS_INDENTS" value="true" />
|
||||
<indentOptions>
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
</indentOptions>
|
||||
|
|
|
@ -15,9 +15,7 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation(group = "commons-cli",
|
||||
name = "commons-cli",
|
||||
version = "1.5.0")
|
||||
implementation(group = "commons-cli", name = "commons-cli", version = "1.5.0")
|
||||
}
|
||||
|
||||
fun versionBanner(): String {
|
||||
|
|
|
@ -22,21 +22,18 @@ import org.apache.commons.cli.Option;
|
|||
import org.apache.commons.cli.Options;
|
||||
|
||||
final class AppOptions {
|
||||
public final Option help = Option
|
||||
.builder()
|
||||
public final Option help = Option.builder()
|
||||
.argName("h")
|
||||
.longOpt("help")
|
||||
.desc("Shows this help " + "message and exits")
|
||||
.desc("Shows this help message and exits")
|
||||
.build();
|
||||
|
||||
public final Option version = Option
|
||||
.builder()
|
||||
public final Option version = Option.builder()
|
||||
.argName("v")
|
||||
.longOpt("version")
|
||||
.desc("Shows version information and exits")
|
||||
.build();
|
||||
|
||||
public final Options options = new Options()
|
||||
.addOption(help)
|
||||
public final Options options = new Options().addOption(help)
|
||||
.addOption(version);
|
||||
}
|
||||
|
|
|
@ -22,12 +22,9 @@ import java.util.Locale;
|
|||
|
||||
public record GlobalConf() {
|
||||
public static final String langGerman = "de";
|
||||
public static final String applicationOutputLanguage = (Locale
|
||||
.getDefault()
|
||||
public static final String applicationOutputLanguage = (Locale.getDefault()
|
||||
.getLanguage()
|
||||
.equals(Locale.GERMAN.getLanguage()))
|
||||
?
|
||||
Locale.GERMAN.getLanguage()
|
||||
:
|
||||
Locale.ENGLISH.getLanguage();
|
||||
? Locale.GERMAN.getLanguage()
|
||||
: Locale.ENGLISH.getLanguage();
|
||||
}
|
||||
|
|
|
@ -36,9 +36,7 @@ public final class Main {
|
|||
|
||||
private static void printVersionInformation() {
|
||||
final var thisPackage = Main.class.getPackage();
|
||||
final var
|
||||
appVersion =
|
||||
thisPackage.getImplementationVersion() != null
|
||||
final var appVersion = thisPackage.getImplementationVersion() != null
|
||||
? thisPackage.getImplementationVersion()
|
||||
: "version unknown";
|
||||
|
||||
|
@ -58,20 +56,15 @@ public final class Main {
|
|||
private static void printHelpInformation() {
|
||||
switch (applicationOutputLanguage) {
|
||||
case GlobalConf.langGerman -> logger.log(Level.ERROR,
|
||||
"Hilfe " +
|
||||
"kommt noch. (Nicht " +
|
||||
"Hilfe kommt noch. (Nicht " +
|
||||
"implementiert)");
|
||||
default -> logger.log(Level.ERROR,
|
||||
"Help is yet to come. (Not " +
|
||||
"implemented)");
|
||||
default -> logger.log(Level.ERROR, "Help is yet to come. (Not implemented)");
|
||||
}
|
||||
}
|
||||
|
||||
private static CommandLine parseArgs(final Options options,
|
||||
final String[] args)
|
||||
private static CommandLine parseArgs(final Options options, final String[] args)
|
||||
throws ParseException {
|
||||
return DefaultParser
|
||||
.builder()
|
||||
return DefaultParser.builder()
|
||||
.setStripLeadingAndTrailingQuotes(true)
|
||||
.build()
|
||||
.parse(options, args);
|
||||
|
@ -94,37 +87,27 @@ public final class Main {
|
|||
} else if (userData.length == 0) {
|
||||
switch (applicationOutputLanguage) {
|
||||
case GlobalConf.langGerman -> logger.log(Level.ERROR,
|
||||
"Es" +
|
||||
" wurde keine " +
|
||||
"Uhrzeit " +
|
||||
"Es wurde keine Uhrzeit " +
|
||||
"angegeben.");
|
||||
default -> logger.log(Level.ERROR,
|
||||
"No target time was " + "provided.");
|
||||
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.");
|
||||
"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")
|
||||
System.getLogger("main")
|
||||
.log(Level.ERROR,
|
||||
"Parsing of arguments " +
|
||||
"failed and the program cannot " + "continue.",
|
||||
"Parsing of arguments failed and the program cannot continue.",
|
||||
e);
|
||||
System.exit(1);
|
||||
}
|
||||
|
|
|
@ -31,16 +31,13 @@ public final class Sleep {
|
|||
public static void waitUntilTimeStamp(ZonedDateTime timestamp) {
|
||||
try {
|
||||
Thread.sleep(Math.max(0,
|
||||
Instant
|
||||
.now()
|
||||
Instant.now()
|
||||
.until(timestamp, ChronoUnit.MILLIS)));
|
||||
} catch (final InterruptedException ignored) {
|
||||
}
|
||||
|
||||
final String formattedTimeStamp = DateTimeFormatter
|
||||
.ofLocalizedDateTime(FormatStyle.LONG)
|
||||
.withZone(TimeZone
|
||||
.getDefault()
|
||||
final String formattedTimeStamp = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)
|
||||
.withZone(TimeZone.getDefault()
|
||||
.toZoneId())
|
||||
.format(Instant.now());
|
||||
|
||||
|
@ -50,8 +47,7 @@ public final class Sleep {
|
|||
};
|
||||
|
||||
final String msgWithData = msg.formatted(formattedTimeStamp);
|
||||
System
|
||||
.getLogger("sleep")
|
||||
System.getLogger("sleep")
|
||||
.log(Level.INFO, msgWithData);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,28 +34,23 @@ public final class TimeCalculator {
|
|||
final var userTimeInputRelative = LocalTime.parse(userTimeInputRaw);
|
||||
final var userTimeInputAbsolute = ZonedDateTime.of(LocalDate.now(),
|
||||
userTimeInputRelative,
|
||||
TimeZone
|
||||
.getDefault()
|
||||
TimeZone.getDefault()
|
||||
.toZoneId());
|
||||
|
||||
final var userTimeInputFinal = (Instant
|
||||
.now()
|
||||
final var userTimeInputFinal = (Instant.now()
|
||||
.isBefore(userTimeInputAbsolute.toInstant()))
|
||||
? userTimeInputAbsolute
|
||||
: userTimeInputAbsolute.plusDays(1);
|
||||
|
||||
final var formattedTimeStamp = userTimeInputFinal.format(
|
||||
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG));
|
||||
final var formattedTimeStamp =
|
||||
userTimeInputFinal.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG));
|
||||
|
||||
final String msg = switch (GlobalConf.applicationOutputLanguage) {
|
||||
case GlobalConf.langGerman -> ("Dieses Program wird bis zum %s " +
|
||||
"warten.").formatted(
|
||||
formattedTimeStamp);
|
||||
default -> "WaitUntil will suspend until %s".formatted(
|
||||
case GlobalConf.langGerman -> ("Dieses Program wird bis zum %s warten.").formatted(
|
||||
formattedTimeStamp);
|
||||
default -> "WaitUntil will suspend until %s".formatted(formattedTimeStamp);
|
||||
};
|
||||
System
|
||||
.getLogger("timecalculator")
|
||||
System.getLogger("timecalculator")
|
||||
.log(Level.INFO, msg);
|
||||
|
||||
return userTimeInputFinal;
|
||||
|
|
Loading…
Reference in a new issue