mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
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:
+5
-3
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user