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

@@ -128,8 +128,8 @@ public class SmartherApiConnector {
} catch (ExecutionException e) {
final Throwable cause = e.getCause();
if (cause instanceof SmartherGatewayException) {
throw (SmartherGatewayException) cause;
if (cause instanceof SmartherGatewayException gatewayException) {
throw gatewayException;
} else {
throw new SmartherGatewayException(e.getMessage(), e);
}

View File

@@ -173,7 +173,7 @@ public class Location {
if (locations == null || locations.isEmpty()) {
return null;
}
return locations.stream().map(a -> String.valueOf(a.getName())).collect(Collectors.joining(NAME_SEPARATOR));
return locations.stream().map(a -> a.getName()).collect(Collectors.joining(NAME_SEPARATOR));
}
@Override

View File

@@ -50,6 +50,6 @@ public class Modules {
if (modules == null || modules.isEmpty()) {
return null;
}
return modules.stream().map(a -> String.valueOf(a.getName())).collect(Collectors.joining(NAME_SEPARATOR));
return modules.stream().map(a -> a.getName()).collect(Collectors.joining(NAME_SEPARATOR));
}
}

View File

@@ -14,7 +14,6 @@ package org.openhab.binding.bticinosmarther.internal.discovery;
import static org.openhab.binding.bticinosmarther.internal.SmartherBindingConstants.*;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -47,7 +46,7 @@ public class SmartherModuleDiscoveryService extends AbstractDiscoveryService
implements DiscoveryService, ThingHandlerService {
// Only modules can be discovered. A bridge must be manually added.
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_MODULE);
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_MODULE);
private static final int DISCOVERY_TIME_SECONDS = 30;
@@ -86,8 +85,7 @@ public class SmartherModuleDiscoveryService extends AbstractDiscoveryService
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof SmartherAccountHandler) {
final SmartherAccountHandler localBridgeHandler = (SmartherAccountHandler) handler;
if (handler instanceof SmartherAccountHandler localBridgeHandler) {
this.bridgeHandler = localBridgeHandler;
this.bridgeUID = localBridgeHandler.getUID();
}

View File

@@ -90,8 +90,8 @@ public class SmartherHandlerFactory extends BaseThingHandlerFactory {
@Override
protected synchronized void removeHandler(ThingHandler thingHandler) {
if (thingHandler instanceof SmartherBridgeHandler) {
authService.removeSmartherAccountHandler((SmartherBridgeHandler) thingHandler);
if (thingHandler instanceof SmartherBridgeHandler bridgeHandler) {
authService.removeSmartherAccountHandler(bridgeHandler);
}
}
}

View File

@@ -25,6 +25,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@@ -121,7 +122,7 @@ public class SmartherBridgeHandler extends BaseBridgeHandler
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(SmartherModuleDiscoveryService.class);
return Set.of(SmartherModuleDiscoveryService.class);
}
// ===========================================================================

View File

@@ -222,14 +222,14 @@ public class SmartherModuleHandler extends BaseThingHandler {
}
break;
case CHANNEL_SETTINGS_PROGRAM:
if (command instanceof DecimalType) {
localModuleSettings.setProgram(((DecimalType) command).intValue());
if (command instanceof DecimalType decimalCommand) {
localModuleSettings.setProgram(decimalCommand.intValue());
return;
}
break;
case CHANNEL_SETTINGS_BOOSTTIME:
if (command instanceof DecimalType) {
localModuleSettings.setBoostTime(BoostTime.fromValue(((DecimalType) command).intValue()));
if (command instanceof DecimalType decimalCommand) {
localModuleSettings.setBoostTime(BoostTime.fromValue(decimalCommand.intValue()));
return;
}
break;
@@ -324,8 +324,8 @@ public class SmartherModuleHandler extends BaseThingHandler {
* @return {@code true} if the change succeeded, {@code false} otherwise
*/
private boolean changeTimeHour(Command command, final ModuleSettings settings) {
if (command instanceof DecimalType) {
int endHour = ((DecimalType) command).intValue();
if (command instanceof DecimalType decimalCommand) {
int endHour = decimalCommand.intValue();
if (endHour >= 0 && endHour <= 23) {
settings.setEndHour(endHour);
return true;
@@ -344,8 +344,8 @@ public class SmartherModuleHandler extends BaseThingHandler {
* @return {@code true} if the change succeeded, {@code false} otherwise
*/
private boolean changeTimeMinute(Command command, final ModuleSettings settings) {
if (command instanceof DecimalType) {
int endMinute = ((DecimalType) command).intValue();
if (command instanceof DecimalType decimalCommand) {
int endMinute = decimalCommand.intValue();
if (endMinute >= 0 && endMinute <= 59) {
// Only 15 min increments are allowed
endMinute = Math.round(endMinute / 15) * 15;

View File

@@ -55,7 +55,7 @@ public final class StringUtil {
* @return the passed in string, or the empty string if it was {@code null}
*
*/
public static final String defaultString(@Nullable String str) {
public static String defaultString(@Nullable String str) {
return (str == null) ? "" : str;
}