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