Java 17 features (T-Z) (#15576)

- 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
- remove null check before instanceof

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich
2023-09-21 07:58:53 +02:00
committed by GitHub
parent bf1aa3deb2
commit 1b122a53b9
277 changed files with 1402 additions and 1298 deletions

View File

@@ -52,9 +52,9 @@ public class TradfriBindingConstants {
.unmodifiableSet(Stream.of(THING_TYPE_DIMMABLE_LIGHT, THING_TYPE_COLOR_TEMP_LIGHT, THING_TYPE_COLOR_LIGHT)
.collect(Collectors.toSet()));
public static final Set<ThingTypeUID> SUPPORTED_PLUG_TYPES_UIDS = Collections.singleton(THING_TYPE_ONOFF_PLUG);
public static final Set<ThingTypeUID> SUPPORTED_PLUG_TYPES_UIDS = Set.of(THING_TYPE_ONOFF_PLUG);
public static final Set<ThingTypeUID> SUPPORTED_BLINDS_TYPES_UIDS = Collections.singleton(THING_TYPE_BLINDS);
public static final Set<ThingTypeUID> SUPPORTED_BLINDS_TYPES_UIDS = Set.of(THING_TYPE_BLINDS);
public static final Set<ThingTypeUID> SUPPORTED_AIR_PURIFIER_TYPES_UIDS = Set.of(THING_TYPE_AIR_PURIFIER);
@@ -70,7 +70,7 @@ public class TradfriBindingConstants {
.unmodifiableSet(Stream.of(THING_TYPE_DIMMER, THING_TYPE_REMOTE_CONTROL,
THING_TYPE_OPEN_CLOSE_REMOTE_CONTROL, THING_TYPE_MOTION_SENSOR).collect(Collectors.toSet()));
public static final Set<ThingTypeUID> SUPPORTED_BRIDGE_TYPES_UIDS = Collections.singleton(GATEWAY_TYPE_UID);
public static final Set<ThingTypeUID> SUPPORTED_BRIDGE_TYPES_UIDS = Set.of(GATEWAY_TYPE_UID);
public static final Set<ThingTypeUID> SUPPORTED_DEVICE_TYPES_UIDS = Collections.unmodifiableSet(Stream
.of(SUPPORTED_LIGHT_TYPES_UIDS.stream(), SUPPORTED_CONTROLLER_TYPES_UIDS.stream(),

View File

@@ -86,8 +86,8 @@ public class TradfriDiscoveryService extends AbstractDiscoveryService
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof TradfriGatewayHandler) {
this.handler = (TradfriGatewayHandler) handler;
if (handler instanceof TradfriGatewayHandler gatewayHandler) {
this.handler = gatewayHandler;
}
}

View File

@@ -75,8 +75,8 @@ public class TradfriAirPurifierHandler extends TradfriThingHandler {
}
private void handleFanModeCommand(Command command) {
if (command instanceof Number) {
set(new TradfriAirPurifierData().setFanMode((Number) command).getJsonString());
if (command instanceof Number numberCommand) {
set(new TradfriAirPurifierData().setFanMode(numberCommand).getJsonString());
} else {
logger.debug("Cannot handle command '{}' of type {} for channel '{}'", command, command.getClass(),
CHANNEL_FAN_MODE);
@@ -84,8 +84,8 @@ public class TradfriAirPurifierHandler extends TradfriThingHandler {
}
private void handleDisableLed(Command command) {
if (command instanceof OnOffType) {
set(new TradfriAirPurifierData().setDisableLed((OnOffType) command).getJsonString());
if (command instanceof OnOffType onOffCommand) {
set(new TradfriAirPurifierData().setDisableLed(onOffCommand).getJsonString());
} else {
logger.debug("Cannot handle command '{}' of type {} for channel '{}'", command, command.getClass(),
CHANNEL_DISABLE_LED);
@@ -93,8 +93,8 @@ public class TradfriAirPurifierHandler extends TradfriThingHandler {
}
private void handleLockButton(Command command) {
if (command instanceof OnOffType) {
set(new TradfriAirPurifierData().setLockPhysicalButton((OnOffType) command).getJsonString());
if (command instanceof OnOffType onOffCommand) {
set(new TradfriAirPurifierData().setLockPhysicalButton(onOffCommand).getJsonString());
} else {
logger.debug("Cannot handle command '{}' of type {} for channel '{}'", command, command.getClass(),
CHANNEL_DISABLE_LED);

View File

@@ -108,8 +108,8 @@ public class TradfriBlindHandler extends TradfriThingHandler {
}
private void handlePositionCommand(Command command) {
if (command instanceof PercentType) {
setPosition((PercentType) command);
if (command instanceof PercentType percentCommand) {
setPosition(percentCommand);
} else if (command instanceof StopMoveType) {
if (StopMoveType.STOP.equals(command)) {
triggerStop();

View File

@@ -18,7 +18,6 @@ import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
@@ -137,7 +136,7 @@ public class TradfriGatewayHandler extends BaseBridgeHandler implements CoapCall
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(TradfriDiscoveryService.class);
return Set.of(TradfriDiscoveryService.class);
}
private void establishConnection() {

View File

@@ -154,10 +154,10 @@ public class TradfriLightHandler extends TradfriThingHandler {
}
private void handleBrightnessCommand(Command command) {
if (command instanceof PercentType) {
setBrightness((PercentType) command);
} else if (command instanceof OnOffType) {
setState(((OnOffType) command));
if (command instanceof PercentType percentCommand) {
setBrightness(percentCommand);
} else if (command instanceof OnOffType onOffCommand) {
setState(onOffCommand);
} else if (command instanceof IncreaseDecreaseType) {
final TradfriLightData state = this.state;
if (state != null && state.getBrightness() != null) {
@@ -177,8 +177,8 @@ public class TradfriLightHandler extends TradfriThingHandler {
}
private void handleColorTemperatureCommand(Command command) {
if (command instanceof PercentType) {
setColorTemperature((PercentType) command);
if (command instanceof PercentType percentCommand) {
setColorTemperature(percentCommand);
} else if (command instanceof IncreaseDecreaseType) {
final TradfriLightData state = this.state;
if (state != null && state.getColorTemperature() != null) {
@@ -198,13 +198,13 @@ public class TradfriLightHandler extends TradfriThingHandler {
}
private void handleColorCommand(Command command) {
if (command instanceof HSBType) {
setColor((HSBType) command);
setBrightness(((HSBType) command).getBrightness());
} else if (command instanceof OnOffType) {
setState(((OnOffType) command));
} else if (command instanceof PercentType) {
setBrightness((PercentType) command);
if (command instanceof HSBType hsbCommand) {
setColor(hsbCommand);
setBrightness(hsbCommand.getBrightness());
} else if (command instanceof OnOffType onOffCommand) {
setState(onOffCommand);
} else if (command instanceof PercentType percentCommand) {
setBrightness(percentCommand);
} else if (command instanceof IncreaseDecreaseType) {
final TradfriLightData state = this.state;
// increase or decrease only the brightness, but keep color

View File

@@ -75,8 +75,8 @@ public class TradfriPlugHandler extends TradfriThingHandler {
switch (channelUID.getId()) {
case CHANNEL_POWER:
if (command instanceof OnOffType) {
setState(((OnOffType) command));
if (command instanceof OnOffType onOffCommand) {
setState(onOffCommand);
} else {
logger.debug("Cannot handle command '{}' for channel '{}'", command, CHANNEL_POWER);
}

View File

@@ -135,8 +135,8 @@ public class TradfriAirPurifierData extends TradfriDeviceData {
public @Nullable State getAirQualityRating() {
State pm25State = getAirQualityPM25();
if (pm25State != null) {
if (pm25State instanceof Number) {
int pm25Value = ((Number) pm25State).intValue();
if (pm25State instanceof Number number) {
int pm25Value = number.intValue();
int qualityRating = 1;
if (pm25Value >= AIR_PURIFIER_AIR_QUALITY_BAD) {