= %d CHARACTERS LONG> |"
+ .formatted(
+ LONG_STRING.substring(0, BasicLogManager.TRUNCATE_REMAINING_SIZE),
+ TRUNCATE_SIZE));
}
}
diff --git a/src/org/sosy_lab/common/log/ConsoleLogFormatter.java b/src/org/sosy_lab/common/log/ConsoleLogFormatter.java
index 95cdfb123..23f231fb4 100644
--- a/src/org/sosy_lab/common/log/ConsoleLogFormatter.java
+++ b/src/org/sosy_lab/common/log/ConsoleLogFormatter.java
@@ -34,8 +34,8 @@ public static Formatter withColorsIfPossible() {
@Override
protected void format(LogRecord lr, StringBuilder sb) {
sb.append(lr.getMessage()).append(" (");
- if (lr instanceof ExtendedLogRecord) {
- String component = ((ExtendedLogRecord) lr).getSourceComponentName();
+ if (lr instanceof ExtendedLogRecord extendedLogRecord) {
+ String component = extendedLogRecord.getSourceComponentName();
if (!component.isEmpty()) {
sb.append(component).append(':');
}
diff --git a/src/org/sosy_lab/common/log/TestLogManager.java b/src/org/sosy_lab/common/log/TestLogManager.java
index 4bb66e302..553526a6b 100644
--- a/src/org/sosy_lab/common/log/TestLogManager.java
+++ b/src/org/sosy_lab/common/log/TestLogManager.java
@@ -132,7 +132,7 @@ private static void checkLogExceptionBaseParams(Level pPriority, Throwable pE) {
@FormatMethod
private static void checkFormatParamsNotNull(String pFormat, Object... pArgs) {
checkNotNull(pArgs);
- checkArgument(!String.format(pFormat, pArgs).isEmpty());
+ checkArgument(!pFormat.formatted(pArgs).isEmpty());
}
private static void checkObjectArgsConcatenationParams(Object... pArgs) {
diff --git a/src/org/sosy_lab/common/log/TimestampedLogFormatter.java b/src/org/sosy_lab/common/log/TimestampedLogFormatter.java
index 06252a856..6657d9a0e 100644
--- a/src/org/sosy_lab/common/log/TimestampedLogFormatter.java
+++ b/src/org/sosy_lab/common/log/TimestampedLogFormatter.java
@@ -39,8 +39,8 @@ public void format(LogRecord lr, StringBuilder sb) {
DATE_FORMAT.formatTo(lr.getInstant(), sb);
sb.append('\t').append(lr.getLevel()).append('\t');
- if (lr instanceof ExtendedLogRecord) {
- String component = ((ExtendedLogRecord) lr).getSourceComponentName();
+ if (lr instanceof ExtendedLogRecord extendedLogRecord) {
+ String component = extendedLogRecord.getSourceComponentName();
if (!component.isEmpty()) {
sb.append(component).append(':');
}
diff --git a/src/org/sosy_lab/common/rationals/ExtendedRational.java b/src/org/sosy_lab/common/rationals/ExtendedRational.java
index 3d14d17ff..cf9ced016 100644
--- a/src/org/sosy_lab/common/rationals/ExtendedRational.java
+++ b/src/org/sosy_lab/common/rationals/ExtendedRational.java
@@ -77,18 +77,15 @@ private ExtendedRational(NumberType pType) {
* The method works, because the Java Double class also supports Infinity/-Infinity/NaN.
*/
public double toDouble() {
- switch (numberType) {
- case NEG_INFTY:
- return Double.NEGATIVE_INFINITY;
- case RATIONAL:
+ return switch (numberType) {
+ case NEG_INFTY -> Double.NEGATIVE_INFINITY;
+ case RATIONAL -> {
assert rational != null;
- return rational.doubleValue();
- case INFTY:
- return Double.POSITIVE_INFINITY;
- case NaN:
- return Double.NaN;
- }
- throw new UnsupportedOperationException("Unexpected number type");
+ yield rational.doubleValue();
+ }
+ case INFTY -> Double.POSITIVE_INFINITY;
+ case NaN -> Double.NaN;
+ };
}
/**
@@ -97,13 +94,13 @@ public double toDouble() {
*/
@Override
public String toString() {
- switch (numberType) {
- case RATIONAL:
+ return switch (numberType) {
+ case RATIONAL -> {
assert rational != null;
- return rational.toString();
- default:
- return Double.toString(toDouble());
- }
+ yield rational.toString();
+ }
+ default -> Double.toString(toDouble());
+ };
}
/**
@@ -123,16 +120,12 @@ public String toString() {
* @return New {@link ExtendedRational}.
*/
public static ExtendedRational ofString(String s) {
- switch (s) {
- case "Infinity":
- return ExtendedRational.INFTY;
- case "-Infinity":
- return ExtendedRational.NEG_INFTY;
- case "NaN":
- return ExtendedRational.NaN;
- default:
- return new ExtendedRational(Rational.ofString(s));
- }
+ return switch (s) {
+ case "Infinity" -> ExtendedRational.INFTY;
+ case "-Infinity" -> ExtendedRational.NEG_INFTY;
+ case "NaN" -> ExtendedRational.NaN;
+ default -> new ExtendedRational(Rational.ofString(s));
+ };
}
@Override
diff --git a/src/org/sosy_lab/common/time/TimeSpan.java b/src/org/sosy_lab/common/time/TimeSpan.java
index e030236d7..0613a065f 100644
--- a/src/org/sosy_lab/common/time/TimeSpan.java
+++ b/src/org/sosy_lab/common/time/TimeSpan.java
@@ -157,41 +157,31 @@ public static TimeSpan valueOf(String input) {
String unit = it.next();
switch (unit) {
- case "day":
- case "days":
- case "d":
+ case "day", "days", "d" -> {
if (days != 0) {
throw new IllegalArgumentException("Days set twice: " + unit);
}
days = value;
- break;
-
- case "h":
- case "hour":
- case "hours":
+ }
+ case "h", "hour", "hours" -> {
if (hours != 0) {
throw new IllegalArgumentException("Hours set twice: " + unit);
}
hours = value;
- break;
-
- case "min":
- case "m":
+ }
+ case "min", "m" -> {
if (minutes != 0) {
throw new IllegalArgumentException("Minutes set twice: " + unit);
}
minutes = value;
- break;
-
- case "s":
+ }
+ case "s" -> {
if (seconds != 0) {
throw new IllegalArgumentException("Seconds set twice: " + unit);
}
seconds = value;
- break;
-
- default:
- throw new IllegalArgumentException("Unknown unit: " + unit);
+ }
+ default -> throw new IllegalArgumentException("Unknown unit: " + unit);
}
}
@@ -396,10 +386,10 @@ public boolean equals(@Nullable Object obj) {
if (obj == this) {
return true;
}
- if (!(obj instanceof TimeSpan)) {
+ if (!(obj instanceof TimeSpan other)) {
return false;
}
- TimeSpan other = (TimeSpan) obj;
+
if (unit == other.unit) {
return span == other.span;
}
@@ -622,7 +612,7 @@ String formatHumanReadableLarge() {
long hours = getChecked(HOURS) - years * 365 * 24 - days * 24;
if (started || hours > 0) {
started = true;
- result.append(String.format("%02dh ", hours));
+ result.append("%02dh ".formatted(hours));
}
if (unit.equals(HOURS)) {
return result.toString().trim();
@@ -630,7 +620,7 @@ String formatHumanReadableLarge() {
long minutes = getChecked(MINUTES) - years * 365 * 24 * 60 - days * 24 * 60 - hours * 60;
if (started || minutes > 0) {
- result.append(String.format("%02dmin ", minutes));
+ result.append("%02dmin ".formatted(minutes));
}
if (unit.equals(MINUTES)) {
started = true;
@@ -643,7 +633,7 @@ String formatHumanReadableLarge() {
- days * 24 * 60 * 60
- hours * 60 * 60
- minutes * 60;
- result.append(String.format("%02ds", seconds));
+ result.append("%02ds".formatted(seconds));
return result.toString();
}
@@ -656,15 +646,11 @@ String formatHumanReadableLarge() {
static {
String format =
Ascii.toUpperCase(System.getProperty(DEFAULT_FORMAT_PROPERTY_NAME, "SIMPLE").trim());
- switch (format) {
- case "HUMAN_READABLE_LARGE":
- DEFAULT_FORMAT = TimeSpan::formatHumanReadableLarge;
- break;
- case "SIMPLE":
- DEFAULT_FORMAT = TimeSpan::formatSimple;
- break;
- default:
- DEFAULT_FORMAT = TimeSpan::formatSimple;
- }
+ DEFAULT_FORMAT =
+ switch (format) {
+ case "HUMAN_READABLE_LARGE" -> TimeSpan::formatHumanReadableLarge;
+ case "SIMPLE" -> TimeSpan::formatSimple;
+ default -> TimeSpan::formatSimple;
+ };
}
}
diff --git a/src/org/sosy_lab/common/time/Timer.java b/src/org/sosy_lab/common/time/Timer.java
index 6d841ba6a..68be30864 100644
--- a/src/org/sosy_lab/common/time/Timer.java
+++ b/src/org/sosy_lab/common/time/Timer.java
@@ -39,25 +39,15 @@ public final class Timer {
String clockToUse =
Ascii.toUpperCase(
System.getProperty(DEFAULT_CLOCK_PROPERTY_NAME, "WALLTIME_MILLIS").trim());
- switch (clockToUse) {
- case "WALLTIME_MILLIS":
- DEFAULT_CLOCK = Tickers.getWalltimeMillis();
- break;
- case "WALLTIME_NANOS":
- DEFAULT_CLOCK = Tickers.getWalltimeNanos();
- break;
- case "THREAD_CPUTIME":
- DEFAULT_CLOCK = Tickers.getCurrentThreadCputime();
- break;
- case "PROCESS_CPUTIME":
- DEFAULT_CLOCK = Tickers.getProcessCputime();
- break;
- case "NONE":
- DEFAULT_CLOCK = Tickers.getNullTicker();
- break;
- default:
- DEFAULT_CLOCK = null;
- }
+ DEFAULT_CLOCK =
+ switch (clockToUse) {
+ case "WALLTIME_MILLIS" -> Tickers.getWalltimeMillis();
+ case "WALLTIME_NANOS" -> Tickers.getWalltimeNanos();
+ case "THREAD_CPUTIME" -> Tickers.getCurrentThreadCputime();
+ case "PROCESS_CPUTIME" -> Tickers.getProcessCputime();
+ case "NONE" -> Tickers.getNullTicker();
+ default -> null;
+ };
}
// Visible for NestedTimer
@@ -98,10 +88,10 @@ public final class Timer {
public Timer() {
if (DEFAULT_CLOCK == null) {
throw new IllegalArgumentException(
- String.format(
- "Invalid value \'%s\' for property %s,"
- + "cannot create Timer without explicitly specified clock.",
- System.getProperty(DEFAULT_CLOCK_PROPERTY_NAME), DEFAULT_CLOCK_PROPERTY_NAME));
+ ("Invalid value \'%s\' for property %s, "
+ + "cannot create Timer without explicitly specified clock.")
+ .formatted(
+ System.getProperty(DEFAULT_CLOCK_PROPERTY_NAME), DEFAULT_CLOCK_PROPERTY_NAME));
}
clock = DEFAULT_CLOCK;
}
@@ -253,11 +243,11 @@ public String toString() {
/** Syntax sugar method: pretty-format the timer output into a string in seconds. */
public String prettyFormat() {
TimeUnit t = TimeUnit.SECONDS;
- return String.format(
- "%s (Max: %s), (Avg: %s), (#intervals = %s)",
- getSumTime().formatAs(t),
- getMaxTime().formatAs(t),
- getAvgTime().formatAs(t),
- getNumberOfIntervals());
+ return "%s (Max: %s), (Avg: %s), (#intervals = %s)"
+ .formatted(
+ getSumTime().formatAs(t),
+ getMaxTime().formatAs(t),
+ getAvgTime().formatAs(t),
+ getNumberOfIntervals());
}
}