simplify method

This commit is contained in:
2025-03-09 00:14:07 +01:00
parent 4abd3d6179
commit e51646ace4
2 changed files with 19 additions and 29 deletions

View File

@@ -42,7 +42,7 @@ public class ExpiredMessageTask implements Runnable {
if(Cache.isVerbose()) LOGGER.info("expired check: {}", messageId); if(Cache.isVerbose()) LOGGER.info("expired check: {}", messageId);
String expiryTimestamp = databaseSource.getQueuedExpiringMessageExpiryDate(messageId); String expiryTimestamp = databaseSource.getQueuedExpiringMessageExpiryDate(messageId);
if(expiryTimestamp == null || expiryTimestamp.equals("")) // if missing timestamp if(expiryTimestamp == null || expiryTimestamp.isEmpty()) // if missing timestamp
{ {
// count it as already expired // count it as already expired
databaseSource.untrackExpiredMessage(messageId); databaseSource.untrackExpiredMessage(messageId);

View File

@@ -18,14 +18,14 @@ public class FormatUtil
// cosmetic string to print on startup. // cosmetic string to print on startup.
private static final String LOGO = """ private static final String LOGO = """
\s
██╗░░██╗██╗██████╗░███████╗██╗░░██╗░█████╗░ ██╗░░██╗██╗██████╗░███████╗██╗░░██╗░█████╗░
██║░░██║██║██╔══██╗██╔════╝██║░██╔╝██╔══██╗ ██║░░██║██║██╔══██╗██╔════╝██║░██╔╝██╔══██╗
███████║██║██║░░██║█████╗░░█████═╝░██║░░██║ ███████║██║██║░░██║█████╗░░█████═╝░██║░░██║
██╔══██║██║██║░░██║██╔══╝░░██╔═██╗░██║░░██║ ██╔══██║██║██║░░██║██╔══╝░░██╔═██╗░██║░░██║
██║░░██║██║██████╔╝███████╗██║░╚██╗╚█████╔╝ ██║░░██║██║██████╔╝███████╗██║░╚██╗╚█████╔╝
╚═╝░░╚═╝╚═╝╚═════╝░╚══════╝╚═╝░░╚═╝░╚════╝░ ╚═╝░░╚═╝╚═╝╚═════╝░╚══════╝╚═╝░░╚═╝░╚════╝░
"""; \s""";
/** /**
@@ -60,36 +60,26 @@ public class FormatUtil
* *
* @return the formatted String * @return the formatted String
*/ */
public static String getNiceDuration(Duration duration) public static String getNiceDuration(Duration duration) {
{
long seconds = duration.toSecondsPart();
long minutes = duration.toMinutesPart();
long hours = duration.toHoursPart();
long days = duration.toDays(); long days = duration.toDays();
long hours = duration.toHoursPart();
long minutes = duration.toMinutesPart();
long seconds = duration.toSecondsPart();
StringBuilder uptimeStringBuilder = new StringBuilder(); StringBuilder sb = new StringBuilder();
if(days == 0) if (days > 0) {
{ sb.append(days).append("d ");
if(hours == 0) sb.append(hours).append("h ");
{ sb.append(minutes).append("m ");
if(minutes == 0) } else if (hours > 0) {
{ sb.append(hours).append("h ");
// empty code block because it makes the code easier to read sb.append(minutes).append("m ");
} else { } else if (minutes > 0) {
uptimeStringBuilder.append(minutes).append("m "); sb.append(minutes).append("m ");
}
} else {
uptimeStringBuilder.append(hours).append("h ");
uptimeStringBuilder.append(minutes).append("m ");
}
} else {
uptimeStringBuilder.append(days).append("d ");
uptimeStringBuilder.append(hours).append("h ");
uptimeStringBuilder.append(minutes).append("m ");
} }
uptimeStringBuilder.append(seconds).append("s "); sb.append(seconds).append("s");
return uptimeStringBuilder.toString(); return sb.toString();
} }
/** /**