Leverage basic Java 17 features (#451)

- Refactor code to use the following basic Java 17 features:
  - pattern matching for instanceof
  - @Serial annotation
  - switch expressions
  - enhanced switch statements
  - StringBuilder.isEmpty()
- Replace two switch statements with simpler if statements.
- Rename a few local variables.
This commit is contained in:
translatenix
2024-04-25 12:52:28 -07:00
committed by GitHub
parent 3ab9e4184e
commit a7c7e51180
142 changed files with 1333 additions and 1798 deletions

View File

@@ -454,37 +454,36 @@ public final class ExecutorOptions {
}
ExecutorSpiOptions toSpiOptions() {
switch (spiOptionsVersion) {
case -1:
case 2:
return new ExecutorSpiOptions2(
allowedModules,
allowedResources,
environmentVariables,
externalProperties,
modulePath,
rootDir,
timeout,
outputFormat,
moduleCacheDir,
projectDir,
certificateFiles,
certificateUris,
testPort);
case 1: // for testing only
return new ExecutorSpiOptions(
allowedModules,
allowedResources,
environmentVariables,
externalProperties,
modulePath,
rootDir,
timeout,
outputFormat,
moduleCacheDir,
projectDir);
default:
throw new AssertionError("Unknown ExecutorSpiOptions version: " + spiOptionsVersion);
}
return switch (spiOptionsVersion) {
case -1, 2 ->
new ExecutorSpiOptions2(
allowedModules,
allowedResources,
environmentVariables,
externalProperties,
modulePath,
rootDir,
timeout,
outputFormat,
moduleCacheDir,
projectDir,
certificateFiles,
certificateUris,
testPort);
case 1 -> // for testing only
new ExecutorSpiOptions(
allowedModules,
allowedResources,
environmentVariables,
externalProperties,
modulePath,
rootDir,
timeout,
outputFormat,
moduleCacheDir,
projectDir);
default ->
throw new AssertionError("Unknown ExecutorSpiOptions version: " + spiOptionsVersion);
};
}
}

View File

@@ -198,9 +198,7 @@ final class Version implements Comparable<Version> {
@Override
public boolean equals(/* @Nullable */ Object obj) {
if (this == obj) return true;
if (!(obj instanceof Version)) return false;
var other = (Version) obj;
if (!(obj instanceof Version other)) return false;
return major == other.major
&& minor == other.minor
&& patch == other.patch