Compare commits
3 Commits
2af0eaebdd
...
4c76542f54
Author | SHA1 | Date | |
---|---|---|---|
4c76542f54 | |||
8426fa4a33 | |||
416789c88c |
@ -1,5 +1,3 @@
|
|||||||
package de.vorsorge.theo.util;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
@ -26,18 +24,43 @@ public class FabianUtil {
|
|||||||
public static class ProgressHandler {
|
public static class ProgressHandler {
|
||||||
|
|
||||||
private static final DecimalFormat TIME_DECIMAL_FORMAT = new DecimalFormat("00");
|
private static final DecimalFormat TIME_DECIMAL_FORMAT = new DecimalFormat("00");
|
||||||
|
protected static final int DEFAULT_LOG_DISTANCE = 50;
|
||||||
|
protected static final int DEFAULT_TIME_LOG_DISTANCE = 15;
|
||||||
|
|
||||||
private final ZonedDateTime startTime;
|
private final ZonedDateTime startTime;
|
||||||
private final BigDecimal logDistance;
|
private final BigDecimal logDistance;
|
||||||
|
private final int timeLogDistance;
|
||||||
private BigDecimal counter = BigDecimal.ZERO;
|
private BigDecimal counter = BigDecimal.ZERO;
|
||||||
|
private ZonedDateTime lastLoggedAt;
|
||||||
|
|
||||||
|
|
||||||
|
public ProgressHandler() {
|
||||||
|
this(DEFAULT_LOG_DISTANCE, DEFAULT_TIME_LOG_DISTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public ProgressHandler(int logDistance) {
|
public ProgressHandler(int logDistance) {
|
||||||
|
this(logDistance, DEFAULT_TIME_LOG_DISTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ProgressHandler(int logDistance, int timeLogDistance) {
|
||||||
startTime = ZonedDateTime.now();
|
startTime = ZonedDateTime.now();
|
||||||
if (logDistance < 1) {
|
this.logDistance = validateBD(logDistance, "Log-Distanz");
|
||||||
throw new RuntimeException("Log-Distanz darf nicht 0 oder negativ sein.");
|
this.timeLogDistance = validateInt(timeLogDistance, "Zeitbasierte Log-Distanz");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected BigDecimal validateBD(int bd, String name) {
|
||||||
|
return BigDecimal.valueOf(validateInt(bd, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected int validateInt(int n, String name) {
|
||||||
|
if (n < 1) {
|
||||||
|
throw new RuntimeException(name + " darf nicht 0 oder negativ sein.");
|
||||||
}
|
}
|
||||||
this.logDistance = BigDecimal.valueOf(logDistance);
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -64,15 +87,27 @@ public class FabianUtil {
|
|||||||
|
|
||||||
|
|
||||||
public void logIf() {
|
public void logIf() {
|
||||||
if (counter.remainder(logDistance).signum() == 0) {
|
if (counter.remainder(logDistance).signum() == 0 || isBored()) {
|
||||||
log();
|
log();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean isBored() {
|
||||||
|
ZonedDateTime time = lastLoggedAt == null ? startTime : lastLoggedAt;
|
||||||
|
return time.until(ZonedDateTime.now(), ChronoUnit.SECONDS) >= timeLogDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void log() {
|
public void log() {
|
||||||
Duration timePassed = getTimePassed();
|
Duration timePassed = getTimePassed();
|
||||||
System.out.println(counter + " Stück erledigt. " + formatDuration(timePassed) + " vergangen.");
|
System.out.println(counter + " Stück erledigt. " + formatDuration(timePassed) + " vergangen.");
|
||||||
|
updateLastLoggedAt();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void updateLastLoggedAt() {
|
||||||
|
lastLoggedAt = ZonedDateTime.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -82,17 +117,18 @@ public class FabianUtil {
|
|||||||
|
|
||||||
|
|
||||||
protected String formatDuration(Duration dur) {
|
protected String formatDuration(Duration dur) {
|
||||||
return formatLong(dur.toHours()) + ":" + formatInt(dur.toMinutesPart()) + ":" + formatInt(dur.toSecondsPart());
|
return formatNumber(dur.toHours()) + ":" + formatNumber(dur.toMinutesPart()) + ":" + formatNumber(dur.toSecondsPart());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String formatLong(long n) {
|
protected String formatNumber(Number n) {
|
||||||
return TIME_DECIMAL_FORMAT.format(n);
|
return TIME_DECIMAL_FORMAT.format(n == null ? 0 : n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String formatInt(int n) {
|
public void logFinal() {
|
||||||
return TIME_DECIMAL_FORMAT.format(n);
|
Duration timePassed = getTimePassed();
|
||||||
|
System.out.println(counter + " Stück (100 %) erledigt. " + formatDuration(timePassed) + " vergangen.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,12 +140,19 @@ public class FabianUtil {
|
|||||||
private final BigDecimal total;
|
private final BigDecimal total;
|
||||||
|
|
||||||
|
|
||||||
|
public ProgressHandlerWithTotal(int total) {
|
||||||
|
this(DEFAULT_LOG_DISTANCE, DEFAULT_TIME_LOG_DISTANCE, total);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public ProgressHandlerWithTotal(int logDistance, int total) {
|
public ProgressHandlerWithTotal(int logDistance, int total) {
|
||||||
super(logDistance);
|
this(logDistance, DEFAULT_TIME_LOG_DISTANCE, total);
|
||||||
if (total < 1) {
|
}
|
||||||
throw new RuntimeException("Maximale Anzahl darf nicht 0 oder negativ sein.");
|
|
||||||
}
|
|
||||||
this.total = BigDecimal.valueOf(total);
|
public ProgressHandlerWithTotal(int logDistance, int timeLogDistance, int total) {
|
||||||
|
super(logDistance, timeLogDistance);
|
||||||
|
this.total = validateBD(total, "Gesamt-Anzahl");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -129,14 +172,10 @@ public class FabianUtil {
|
|||||||
remainingTimePart = ", " + formatDuration(timeToGo) + " verbleibend";
|
remainingTimePart = ", " + formatDuration(timeToGo) + " verbleibend";
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(counter + " Stück von " + total + " (" + PERCENTAGE_FORMAT.format(percentage.doubleValue()) + " %) erledigt. "
|
String counterPrint = total.compareTo(BigDecimal.TEN) >= 0 ? formatNumber(counter) : counter.toString();
|
||||||
|
System.out.println(counterPrint + " Stück von " + total + " (" + PERCENTAGE_FORMAT.format(percentage) + " %) erledigt. "
|
||||||
+ formatDuration(timePassed) + " vergangen" + remainingTimePart + ".");
|
+ formatDuration(timePassed) + " vergangen" + remainingTimePart + ".");
|
||||||
}
|
updateLastLoggedAt();
|
||||||
|
|
||||||
|
|
||||||
public void logFinal() {
|
|
||||||
Duration timePassed = getTimePassed();
|
|
||||||
System.out.println(total + " Stück (100 %) erledigt. " + formatDuration(timePassed) + " vergangen.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
112
LoadingBar.java
112
LoadingBar.java
@ -9,21 +9,24 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
class LoadingBar {
|
public class LoadingBar {
|
||||||
|
|
||||||
private static final String TIME_FORMAT = "HH:mm";
|
private static final String TIME_FORMAT = "HH:mm";
|
||||||
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern(TIME_FORMAT);
|
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern(TIME_FORMAT);
|
||||||
private static final Pattern TIME_PATTERN = Pattern.compile("(?>[01][0-9]|2[0-4]):[0-5][0-9]");
|
private static final Pattern TIME_PATTERN = Pattern.compile("(?>[01]\\d|2[0-4]):[0-5]\\d");
|
||||||
private static final Pattern LUNCH_DURATION_PATTERN = Pattern.compile("\\d+");
|
private static final Pattern LUNCH_DURATION_PATTERN = Pattern.compile("\\d+");
|
||||||
private static final Pattern OFFSET_PATTERN = Pattern.compile("[\\+\\-]\\d+");
|
private static final Pattern OFFSET_PATTERN = Pattern.compile("[+-]\\d+");
|
||||||
private static final DecimalFormat PERCENTAGE_FORMAT = new DecimalFormat("00.00");
|
private static final DecimalFormat PERCENTAGE_FORMAT = new DecimalFormat("00.00");
|
||||||
private static final int MIN_LUNCH_DURATION = 30;
|
private static final int MIN_LUNCH_DURATION = 30;
|
||||||
private static final LocalTime LATEST_LUNCH_TIME = LocalTime.of(13, 30);
|
private static final LocalTime LATEST_LUNCH_TIME = LocalTime.of(13, 30);
|
||||||
private static final int DEFAULT_NUMBER_WORK_MINS_BEFORE_LUNCH = 5 * 60;
|
private static final long DEFAULT_NUMBER_WORK_MINS_BEFORE_LUNCH = 5L * 60;
|
||||||
private static final int MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH = 6 * 60;
|
private static final int MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH = 6 * 60;
|
||||||
private static final int MAX_NUMBER_WORK_MINS = 8 * 60;
|
private static final long MAX_NUMBER_WORK_MINS = 8L * 60;
|
||||||
|
private static final int MINS_PER_HOUR = 60;
|
||||||
|
private static final int LINE_LENGTH = 100;
|
||||||
|
|
||||||
private static enum DaySection {
|
|
||||||
|
private enum DaySection {
|
||||||
MITTAG("-m", "Mittag"),
|
MITTAG("-m", "Mittag"),
|
||||||
ZAPFENSTREICH("-z", "Zapfenstreich");
|
ZAPFENSTREICH("-z", "Zapfenstreich");
|
||||||
|
|
||||||
@ -31,7 +34,7 @@ class LoadingBar {
|
|||||||
private final String description;
|
private final String description;
|
||||||
|
|
||||||
|
|
||||||
private DaySection(String param, String description) {
|
DaySection(String param, String description) {
|
||||||
this.param = param;
|
this.param = param;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
@ -92,7 +95,7 @@ class LoadingBar {
|
|||||||
private static void handleZapfenstreich(String[] args, LocalTime startTime) {
|
private static void handleZapfenstreich(String[] args, LocalTime startTime) {
|
||||||
Integer lunchDuration = null;
|
Integer lunchDuration = null;
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
showLoadingBarZapfenstreich(startTime, lunchDuration);
|
showLoadingBarZapfenstreich(startTime);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String nextArg = args[2];
|
String nextArg = args[2];
|
||||||
@ -162,8 +165,8 @@ class LoadingBar {
|
|||||||
if (pattern.matcher(param).matches()) {
|
if (pattern.matcher(param).matches()) {
|
||||||
return;
|
return;
|
||||||
} // FSFIXME fine tune message -> HH:mm, mm, -+mm
|
} // FSFIXME fine tune message -> HH:mm, mm, -+mm
|
||||||
var firstInputPart = timeInput ? "Uhrzeitformat ("+ TIME_FORMAT + ")" : "Minutenanzahl (" + LUNCH_DURATION_PATTERN + ")";
|
var firstInputPart = timeInput ? "Uhrzeitformat (" + TIME_FORMAT + ")" : "Minutenanzahl (" + LUNCH_DURATION_PATTERN + ")";
|
||||||
var possibleTimeInputPart = !timeInput && timeInputPossible ? " oder Uhrzeitformat ("+ TIME_FORMAT + ")" : "";
|
var possibleTimeInputPart = !timeInput && timeInputPossible ? " oder Uhrzeitformat (" + TIME_FORMAT + ")" : "";
|
||||||
System.out.println(errMsgPrefix + " \"" + param + "\" muss " + firstInputPart + possibleTimeInputPart + " entsprechen.");
|
System.out.println(errMsgPrefix + " \"" + param + "\" muss " + firstInputPart + possibleTimeInputPart + " entsprechen.");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
@ -174,7 +177,7 @@ class LoadingBar {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<String> sectionDescs = Arrays.stream(DaySection.values()).map((DaySection ds) -> ds.getDescription() + " (" + ds.getParam() + ")")
|
List<String> sectionDescs = Arrays.stream(DaySection.values()).map((DaySection ds) -> ds.getDescription() + " (" + ds.getParam() + ")")
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
String sectionDescsJoined = String.join(" oder ", sectionDescs);
|
String sectionDescsJoined = String.join(" oder ", sectionDescs);
|
||||||
System.out.println("Argument nach Startzeit \"" + param + "\" muss Angabe für " + sectionDescsJoined + " sein.");
|
System.out.println("Argument nach Startzeit \"" + param + "\" muss Angabe für " + sectionDescsJoined + " sein.");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
@ -183,32 +186,32 @@ class LoadingBar {
|
|||||||
|
|
||||||
private static void printHelp() {
|
private static void printHelp() {
|
||||||
System.out.println("Mögliche Argumente für LoadingBar:\n"
|
System.out.println("Mögliche Argumente für LoadingBar:\n"
|
||||||
+ "Normalfall Vormittag (Mittagspause <= " + LATEST_LUNCH_TIME + ")\n"
|
+ "Normalfall Vormittag (Mittagspause <= " + LATEST_LUNCH_TIME + ")\n"
|
||||||
+ TIME_FORMAT + " " + DaySection.MITTAG.getParam() + "\n"
|
+ TIME_FORMAT + " " + DaySection.MITTAG.getParam() + "\n"
|
||||||
+ "Vormittag mit expliziter Mittagspause (<= " + LATEST_LUNCH_TIME + ")\n"
|
+ "Vormittag mit expliziter Mittagspause (<= " + LATEST_LUNCH_TIME + ")\n"
|
||||||
+ TIME_FORMAT + " " + DaySection.MITTAG.getParam() + " " + TIME_FORMAT + "\n"
|
+ TIME_FORMAT + " " + DaySection.MITTAG.getParam() + " " + TIME_FORMAT + "\n"
|
||||||
+ "Vormittag mit abweichender Minutenanzahl Arbeitszeit\n"
|
+ "Vormittag mit abweichender Minutenanzahl Arbeitszeit\n"
|
||||||
+ TIME_FORMAT + " " + DaySection.MITTAG.getParam() + " -+mm\n"
|
+ TIME_FORMAT + " " + DaySection.MITTAG.getParam() + " -+mm\n"
|
||||||
+ "Normalfall Nachmittag (Mittagspause " + MIN_LUNCH_DURATION + " min)\n"
|
+ "Normalfall Nachmittag (Mittagspause " + MIN_LUNCH_DURATION + " min)\n"
|
||||||
+ TIME_FORMAT + " " + DaySection.ZAPFENSTREICH.getParam() + "\n"
|
+ TIME_FORMAT + " " + DaySection.ZAPFENSTREICH.getParam() + "\n"
|
||||||
+ "Nachmittag mit expliziter Länge Mittagspause (Mittagspause unter " + MIN_LUNCH_DURATION + " min wird auf " + MIN_LUNCH_DURATION + " min korrigiert)\n"
|
+ "Nachmittag mit expliziter Länge Mittagspause (Mittagspause unter " + MIN_LUNCH_DURATION + " min wird auf " + MIN_LUNCH_DURATION + " min korrigiert)\n"
|
||||||
+ TIME_FORMAT + " " + DaySection.ZAPFENSTREICH.getParam() + " mm\n"
|
+ TIME_FORMAT + " " + DaySection.ZAPFENSTREICH.getParam() + " mm\n"
|
||||||
+ "Nachmittag mit explizitem Feierabend (Mittagspause je nach Minimum (s.u.))\n"
|
+ "Nachmittag mit explizitem Feierabend (Mittagspause je nach Minimum (s.u.))\n"
|
||||||
+ TIME_FORMAT + " " + DaySection.ZAPFENSTREICH.getParam() + " " + TIME_FORMAT + "\n"
|
+ TIME_FORMAT + " " + DaySection.ZAPFENSTREICH.getParam() + " " + TIME_FORMAT + "\n"
|
||||||
+ "Nachmittag mit abweichender Minutenanzahl Arbeitszeit\n"
|
+ "Nachmittag mit abweichender Minutenanzahl Arbeitszeit\n"
|
||||||
+ TIME_FORMAT + " " + DaySection.ZAPFENSTREICH.getParam() + " -+mm\n"
|
+ TIME_FORMAT + " " + DaySection.ZAPFENSTREICH.getParam() + " -+mm\n"
|
||||||
+ "Nachmittag mit explizitem Feierabend u. expliziter Länge Mittagspause (Mittagspause unter Minimum (s.u.) wird auf Minimum korrigiert)\n"
|
+ "Nachmittag mit explizitem Feierabend u. expliziter Länge Mittagspause (Mittagspause unter Minimum (s.u.) wird auf Minimum korrigiert)\n"
|
||||||
+ TIME_FORMAT + " " + DaySection.ZAPFENSTREICH.getParam() + " mm " + TIME_FORMAT + "\n"
|
+ TIME_FORMAT + " " + DaySection.ZAPFENSTREICH.getParam() + " mm " + TIME_FORMAT + "\n"
|
||||||
+ "Nachmittag mit explizitem Feierabend u. abweichender Minutenanzahl Arbeitszeit\n"
|
+ "Nachmittag mit explizitem Feierabend u. abweichender Minutenanzahl Arbeitszeit\n"
|
||||||
+ TIME_FORMAT + " " + DaySection.ZAPFENSTREICH.getParam() + " " + TIME_FORMAT + " -+mm\n\n"
|
+ TIME_FORMAT + " " + DaySection.ZAPFENSTREICH.getParam() + " " + TIME_FORMAT + " -+mm\n\n"
|
||||||
+ "Mittagspause minimum in Minuten:\n"
|
+ "Mittagspause minimum in Minuten:\n"
|
||||||
+ " - bis " + MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH + " min ("
|
+ " - bis " + MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH + " min ("
|
||||||
+ MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH / 60 + " std): 0\n"
|
+ MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH / MINS_PER_HOUR + " std): 0\n"
|
||||||
+ " - bis " + MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH + " min + "
|
+ " - bis " + MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH + " min + "
|
||||||
+ MIN_LUNCH_DURATION + " min: Arbeitszeit - " + MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH + " min\n"
|
+ MIN_LUNCH_DURATION + " min: Arbeitszeit - " + MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH + " min\n"
|
||||||
+ " - ab " + MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH + " min + " + MIN_LUNCH_DURATION + " min: "
|
+ " - ab " + MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH + " min + " + MIN_LUNCH_DURATION + " min: "
|
||||||
+ MIN_LUNCH_DURATION + " min\n"
|
+ MIN_LUNCH_DURATION + " min\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -231,14 +234,19 @@ class LoadingBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static void showLoadingBarZapfenstreich(LocalTime startTime) {
|
||||||
|
showLoadingBarZapfenstreich(startTime, -1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void showLoadingBarZapfenstreich(LocalTime startTime, Integer manualLunchDuration) {
|
private static void showLoadingBarZapfenstreich(LocalTime startTime, Integer manualLunchDuration) {
|
||||||
showLoadingBarZapfenstreich(startTime, manualLunchDuration, 0);
|
showLoadingBarZapfenstreich(startTime, manualLunchDuration, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void showLoadingBarZapfenstreich(LocalTime startTime, Integer manualLunchDuration, int endTimeOffset) {
|
private static void showLoadingBarZapfenstreich(LocalTime startTime, Integer manualLunchDuration, int endTimeOffset) {
|
||||||
int minLunchDuration = getMinLunchDuration(startTime, endTimeOffset);
|
long minLunchDuration = getMinLunchDuration(endTimeOffset);
|
||||||
int realLunchDuration = getRealLunchDuration(manualLunchDuration, minLunchDuration);
|
long realLunchDuration = getRealLunchDuration(manualLunchDuration, minLunchDuration);
|
||||||
LocalTime trueEndTime = startTime.plusMinutes(MAX_NUMBER_WORK_MINS + realLunchDuration + endTimeOffset);
|
LocalTime trueEndTime = startTime.plusMinutes(MAX_NUMBER_WORK_MINS + realLunchDuration + endTimeOffset);
|
||||||
realShowLoadingBarZapfenstreich(startTime, realLunchDuration, trueEndTime);
|
realShowLoadingBarZapfenstreich(startTime, realLunchDuration, trueEndTime);
|
||||||
}
|
}
|
||||||
@ -246,8 +254,8 @@ class LoadingBar {
|
|||||||
|
|
||||||
private static void showLoadingBarZapfenstreich(LocalTime startTime, Integer manualLunchDuration, LocalTime manualEndTime) {
|
private static void showLoadingBarZapfenstreich(LocalTime startTime, Integer manualLunchDuration, LocalTime manualEndTime) {
|
||||||
LocalTime trueEndTime = manualEndTime;
|
LocalTime trueEndTime = manualEndTime;
|
||||||
int minLunchDuration = getMinLunchDuration(startTime, trueEndTime);
|
long minLunchDuration = getMinLunchDuration(startTime, trueEndTime);
|
||||||
int realLunchDuration = getRealLunchDuration(manualLunchDuration, minLunchDuration);
|
long realLunchDuration = getRealLunchDuration(manualLunchDuration, minLunchDuration);
|
||||||
if (trueEndTime == null) {
|
if (trueEndTime == null) {
|
||||||
trueEndTime = startTime.plusMinutes(MAX_NUMBER_WORK_MINS + realLunchDuration);
|
trueEndTime = startTime.plusMinutes(MAX_NUMBER_WORK_MINS + realLunchDuration);
|
||||||
}
|
}
|
||||||
@ -255,17 +263,17 @@ class LoadingBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static int getMinLunchDuration(LocalTime startTime, int endTimeOffset) {
|
private static long getMinLunchDuration(int endTimeOffset) {
|
||||||
if (endTimeOffset == 0) {
|
if (endTimeOffset == 0) {
|
||||||
return MIN_LUNCH_DURATION;
|
return MIN_LUNCH_DURATION;
|
||||||
}
|
}
|
||||||
int totalDuration = MAX_NUMBER_WORK_MINS + endTimeOffset;
|
long totalDuration = MAX_NUMBER_WORK_MINS + endTimeOffset;
|
||||||
int effectiveLunchDuration = totalDuration - MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH;
|
long effectiveLunchDuration = totalDuration - MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH;
|
||||||
return getMinLunchDuration(effectiveLunchDuration);
|
return getMinLunchDuration(effectiveLunchDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static int getMinLunchDuration(LocalTime startTime, LocalTime endTime) {
|
private static long getMinLunchDuration(LocalTime startTime, LocalTime endTime) {
|
||||||
if (endTime == null) {
|
if (endTime == null) {
|
||||||
return MIN_LUNCH_DURATION;
|
return MIN_LUNCH_DURATION;
|
||||||
}
|
}
|
||||||
@ -275,20 +283,20 @@ class LoadingBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static int getMinLunchDuration(int effectiveLunchDuration) {
|
private static long getMinLunchDuration(long effectiveLunchDuration) {
|
||||||
if (effectiveLunchDuration < 0) {
|
if (effectiveLunchDuration < 0) {
|
||||||
effectiveLunchDuration = 0;
|
effectiveLunchDuration = 0;
|
||||||
}
|
}
|
||||||
return effectiveLunchDuration < MIN_LUNCH_DURATION ? effectiveLunchDuration : MIN_LUNCH_DURATION;
|
return Math.min(effectiveLunchDuration, MIN_LUNCH_DURATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static int getRealLunchDuration(Integer manualLunchDuration, int minLunchDuration) {
|
private static long getRealLunchDuration(Integer manualLunchDuration, long minLunchDuration) {
|
||||||
return manualLunchDuration != null && manualLunchDuration >= minLunchDuration ? manualLunchDuration : minLunchDuration;
|
return manualLunchDuration != null && manualLunchDuration >= minLunchDuration ? manualLunchDuration : minLunchDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void realShowLoadingBarZapfenstreich(LocalTime startTime, int manualLunchDuration, LocalTime endTime) {
|
private static void realShowLoadingBarZapfenstreich(LocalTime startTime, long manualLunchDuration, LocalTime endTime) {
|
||||||
if (manualLunchDuration > 0) {
|
if (manualLunchDuration > 0) {
|
||||||
var totalWorkTime = LocalTime.MIDNIGHT.plusMinutes(startTime.until(endTime, ChronoUnit.MINUTES) - manualLunchDuration);
|
var totalWorkTime = LocalTime.MIDNIGHT.plusMinutes(startTime.until(endTime, ChronoUnit.MINUTES) - manualLunchDuration);
|
||||||
System.out.print("Arbeitszeit: " + TIME_FORMATTER.format(totalWorkTime) + "; ");
|
System.out.print("Arbeitszeit: " + TIME_FORMATTER.format(totalWorkTime) + "; ");
|
||||||
@ -329,7 +337,7 @@ class LoadingBar {
|
|||||||
long remainingMinutes = initialMinutes - passedMinutes;
|
long remainingMinutes = initialMinutes - passedMinutes;
|
||||||
int numberOfEquals = (int) wholePercentage;
|
int numberOfEquals = (int) wholePercentage;
|
||||||
var sb = new StringBuilder("[");
|
var sb = new StringBuilder("[");
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < LINE_LENGTH; i++) {
|
||||||
if (i < numberOfEquals) {
|
if (i < numberOfEquals) {
|
||||||
sb.append("=");
|
sb.append("=");
|
||||||
} else {
|
} else {
|
||||||
@ -337,7 +345,7 @@ class LoadingBar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.append("] ").append(PERCENTAGE_FORMAT.format(wholePercentage)).append("% ")
|
sb.append("] ").append(PERCENTAGE_FORMAT.format(wholePercentage)).append("% ")
|
||||||
.append(minutesToTimeString(passedMinutes)).append(" - ").append(minutesToTimeString(remainingMinutes));
|
.append(minutesToTimeString(passedMinutes)).append(" - ").append(minutesToTimeString(remainingMinutes));
|
||||||
if (progressive) {
|
if (progressive) {
|
||||||
sb.append("\r");
|
sb.append("\r");
|
||||||
}
|
}
|
||||||
@ -346,6 +354,6 @@ class LoadingBar {
|
|||||||
|
|
||||||
|
|
||||||
private static String minutesToTimeString(long minutes) {
|
private static String minutesToTimeString(long minutes) {
|
||||||
return LocalTime.of((int) minutes / 60, (int) minutes % 60).format(TIME_FORMATTER);
|
return LocalTime.of((int) minutes / MINS_PER_HOUR, (int) minutes % MINS_PER_HOUR).format(TIME_FORMATTER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,14 @@ import java.util.Objects;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
class SimpleLoadingBar {
|
public class SimpleLoadingBar {
|
||||||
|
|
||||||
private static final String TIME_FORMAT = "HH:mm";
|
private static final String TIME_FORMAT = "HH:mm";
|
||||||
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern(TIME_FORMAT);
|
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern(TIME_FORMAT);
|
||||||
private static final Pattern TIME_PATTERN = Pattern.compile("(?>[01][0-9]|2[0-4]):[0-5][0-9]");
|
private static final Pattern TIME_PATTERN = Pattern.compile("(?>[01]\\d|2[0-4]):[0-5]\\d");
|
||||||
private static final DecimalFormat PERCENTAGE_FORMAT = new DecimalFormat("00.00");
|
private static final DecimalFormat PERCENTAGE_FORMAT = new DecimalFormat("00.00");
|
||||||
|
private static final int MINS_PER_HOUR = 60;
|
||||||
|
private static final int LINE_LENGTH = 100;
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -29,7 +31,7 @@ class SimpleLoadingBar {
|
|||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
startTime = firstTime;
|
startTime = firstTime;
|
||||||
nextArg = args[1];
|
nextArg = args[1];
|
||||||
if (nextArg.equals("-msg")) {
|
if ("-msg".equals(nextArg)) {
|
||||||
title = args.length > 2 ? args[2] : title;
|
title = args.length > 2 ? args[2] : title;
|
||||||
} else {
|
} else {
|
||||||
verifyTimeFormat(nextArg, "Zweites Argument");
|
verifyTimeFormat(nextArg, "Zweites Argument");
|
||||||
@ -47,7 +49,7 @@ class SimpleLoadingBar {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// if there are 3 arguments, the third will be discarded.
|
// if there are 3 arguments, the third will be discarded.
|
||||||
boolean hasTitleArg = args.length > 3 && args[2].equals("-msg");
|
boolean hasTitleArg = args.length > 3 && "-msg".equals(args[2]);
|
||||||
title = hasTitleArg ? args[3] : title;
|
title = hasTitleArg ? args[3] : title;
|
||||||
title = title.isBlank() ? fallbackTitle : title;
|
title = title.isBlank() ? fallbackTitle : title;
|
||||||
showLoadingBar(startTime, endTime, title);
|
showLoadingBar(startTime, endTime, title);
|
||||||
@ -55,11 +57,11 @@ class SimpleLoadingBar {
|
|||||||
|
|
||||||
|
|
||||||
private static void printHelp() {
|
private static void printHelp() {
|
||||||
System.out.println(new StringBuilder().append("Mögliche Argumente für LoadingBar:\n")
|
System.out.println("Mögliche Argumente für LoadingBar:\n"
|
||||||
.append("Startzeit, Endzeit, Endnachricht (Optional)\n")
|
+ "Startzeit, Endzeit, Endnachricht (Optional)\n"
|
||||||
.append(TIME_FORMAT).append(" ").append(TIME_FORMAT).append("-msg <Nachricht>\n")
|
+ TIME_FORMAT + " " + TIME_FORMAT + " -msg <Nachricht>\n"
|
||||||
.append("Endzeit (Startzeit = jetzt), Endnachricht (Optional)\n")
|
+ "Endzeit (Startzeit = jetzt), Endnachricht (Optional)\n"
|
||||||
.append(TIME_FORMAT).append("-msg <Nachricht>\n")
|
+ TIME_FORMAT + " -msg <Nachricht>\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,12 +80,11 @@ class SimpleLoadingBar {
|
|||||||
if (TIME_PATTERN.matcher(param).matches()) {
|
if (TIME_PATTERN.matcher(param).matches()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
System.out.println(errMsgPrefix + " \"" + param + "\" muss Uhrzeitformat ("+ TIME_FORMAT + ") entsprechen.");
|
System.out.println(errMsgPrefix + " \"" + param + "\" muss Uhrzeitformat (" + TIME_FORMAT + ") entsprechen.");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void showLoadingBar(LocalTime startTime, LocalTime endTime, String title) {
|
public static void showLoadingBar(LocalTime startTime, LocalTime endTime, String title) {
|
||||||
long initialMinutes = startTime.until(endTime, ChronoUnit.MINUTES);
|
long initialMinutes = startTime.until(endTime, ChronoUnit.MINUTES);
|
||||||
System.out.print(minutesToTimeString(initialMinutes) + " gesamt; Endzeit: " + TIME_FORMATTER.format(endTime) + "\n");
|
System.out.print(minutesToTimeString(initialMinutes) + " gesamt; Endzeit: " + TIME_FORMATTER.format(endTime) + "\n");
|
||||||
@ -117,7 +118,7 @@ class SimpleLoadingBar {
|
|||||||
long remainingMinutes = initialMinutes - passedMinutes;
|
long remainingMinutes = initialMinutes - passedMinutes;
|
||||||
int numberOfEquals = (int) wholePercentage;
|
int numberOfEquals = (int) wholePercentage;
|
||||||
var sb = new StringBuilder("[");
|
var sb = new StringBuilder("[");
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < LINE_LENGTH; i++) {
|
||||||
if (i < numberOfEquals) {
|
if (i < numberOfEquals) {
|
||||||
sb.append("=");
|
sb.append("=");
|
||||||
} else {
|
} else {
|
||||||
@ -125,7 +126,7 @@ class SimpleLoadingBar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.append("] ").append(PERCENTAGE_FORMAT.format(wholePercentage)).append("% ")
|
sb.append("] ").append(PERCENTAGE_FORMAT.format(wholePercentage)).append("% ")
|
||||||
.append(minutesToTimeString(passedMinutes)).append(" - ").append(minutesToTimeString(remainingMinutes));
|
.append(minutesToTimeString(passedMinutes)).append(" - ").append(minutesToTimeString(remainingMinutes));
|
||||||
if (progressive) {
|
if (progressive) {
|
||||||
sb.append("\r");
|
sb.append("\r");
|
||||||
}
|
}
|
||||||
@ -134,15 +135,12 @@ class SimpleLoadingBar {
|
|||||||
|
|
||||||
|
|
||||||
private static String minutesToTimeString(long minutes) {
|
private static String minutesToTimeString(long minutes) {
|
||||||
return LocalTime.of((int) minutes / 60, (int) minutes % 60).format(TIME_FORMATTER);
|
return LocalTime.of((int) minutes / MINS_PER_HOUR, (int) minutes % MINS_PER_HOUR).format(TIME_FORMATTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static String formatTitle(String title) {
|
private static String formatTitle(String title) {
|
||||||
var sb = new StringBuilder();
|
String separator = "*".repeat(title.length());
|
||||||
for (int i = 0; i < title.length(); i++) {
|
return separator + "\n" + title + "\n" + separator;
|
||||||
sb.append("*");
|
|
||||||
}
|
|
||||||
return sb.toString() + "\n" + title + "\n" + sb.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user