Java 21 language features (#4535)

* Java 21 language features

* use getFirst and getLast methods
* replace new Locale by Locale.of
* replace Paths.get by Path.of
* use ThreadLocalRandom.current().nextDouble()
* add @Serial annotations

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich
2025-01-06 23:22:43 +01:00
committed by GitHub
parent f8fdd66f78
commit 40d079ae80
190 changed files with 594 additions and 443 deletions
@@ -16,6 +16,7 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
@@ -143,9 +144,9 @@ public class ScriptEngineImpl implements ScriptEngine, ModelParser {
EList<EObject> contents = resource.getContents();
if (!contents.isEmpty()) {
Iterable<Issue> validationErrors = getValidationErrors(contents.get(0));
Iterable<Issue> validationErrors = getValidationErrors(contents.getFirst());
if (!validationErrors.iterator().hasNext()) {
return (XExpression) contents.get(0);
return (XExpression) contents.getFirst();
} else {
deleteResource(resource);
throw new ScriptParsingException("Failed to parse expression (due to managed ValidationError/s)",
@@ -162,7 +163,8 @@ public class ScriptEngineImpl implements ScriptEngine, ModelParser {
final int MAX_TRIES = 1000;
for (int i = 0; i < MAX_TRIES; i++) {
// NOTE: The "filename extension" (".script") must match the file.extensions in the *.mwe2
URI syntheticUri = URI.createURI(name + Math.random() + "." + Script.SCRIPT_FILEEXT);
URI syntheticUri = URI
.createURI(name + ThreadLocalRandom.current().nextDouble() + "." + Script.SCRIPT_FILEEXT);
if (resourceSet.getResource(syntheticUri, false) == null) {
return syntheticUri;
}