Java 17 features (A-G) (#15516)

- add missing @override
- Java style array syntax
- remove redundant modifiers
- always move String constants to left side in comparisons
- simplify lambda expressions and return statements
- use replace instead of replaceAll w/o regex
- instanceof matching and multiline strings

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich
2023-09-05 22:30:16 +02:00
committed by GitHub
parent a0dc5c05f2
commit cf10b3e9c7
486 changed files with 2053 additions and 1955 deletions

View File

@@ -80,8 +80,8 @@ public class ConnectedBluetoothHandler extends BeaconBluetoothHandler {
Object idleDisconnectDelayRaw = getConfig().get(BluetoothBindingConstants.CONFIGURATION_IDLE_DISCONNECT_DELAY);
idleDisconnectDelay = 1000;
if (idleDisconnectDelayRaw instanceof Number) {
idleDisconnectDelay = ((Number) idleDisconnectDelayRaw).intValue();
if (idleDisconnectDelayRaw instanceof Number numberCommand) {
idleDisconnectDelay = numberCommand.intValue();
}
// Start the recurrent job if the device is always connected
@@ -202,11 +202,11 @@ public class ConnectedBluetoothHandler extends BeaconBluetoothHandler {
return CompletableFuture.failedFuture(new IllegalStateException("connectionTaskExecutor is shut down"));
}
// we use a RetryFuture because it supports running Callable instances
return RetryFuture.callWithRetry(() -> {
// we block for completion here so that we keep the lock on the connectionTaskExecutor active.
return callable.apply(connectAndGetCharacteristic(serviceUUID, characteristicUUID)).get();
}, connectionTaskExecutor)// we make this completion async so that operations chained off the returned future
// will not run on the connectionTaskExecutor
return RetryFuture.callWithRetry(() ->
// we block for completion here so that we keep the lock on the connectionTaskExecutor active.
callable.apply(connectAndGetCharacteristic(serviceUUID, characteristicUUID)).get(), connectionTaskExecutor)
// we make this completion async so that operations chained off the returned future
// will not run on the connectionTaskExecutor
.whenCompleteAsync((r, th) -> {
// we us a while loop here in case the exceptions get nested
while (th instanceof CompletionException || th instanceof ExecutionException) {

View File

@@ -94,8 +94,7 @@ public class RetryFuture<T> extends HeritableFuture<T> {
if (th instanceof CompletionException) {
th = th.getCause();
}
if (th instanceof RetryException) {
RetryException e = (RetryException) th;
if (th instanceof RetryException e) {
setParentFuture(() -> {
if (!isDone()) {
return scheduler.schedule(this, e.delay, e.unit);

View File

@@ -539,7 +539,7 @@ public class BluetoothDiscoveryServiceTest {
@Override
public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
return Collections.singleton(typeUID);
return Set.of(typeUID);
}
@Override