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:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -539,7 +539,7 @@ public class BluetoothDiscoveryServiceTest {
|
||||
|
||||
@Override
|
||||
public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
|
||||
return Collections.singleton(typeUID);
|
||||
return Set.of(typeUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user