Java 17 features (N-S) (#15565)

- 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-13 08:03:31 +02:00
committed by GitHub
parent 641b482551
commit ab58f4ffb4
471 changed files with 1624 additions and 1868 deletions

View File

@@ -42,8 +42,8 @@ public class OmnilinkActions implements ThingActions {
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof OmnilinkBridgeHandler) {
this.handler = (OmnilinkBridgeHandler) handler;
if (handler instanceof OmnilinkBridgeHandler bridgeHandler) {
this.handler = bridgeHandler;
}
}

View File

@@ -75,8 +75,8 @@ public class OmnilinkDiscoveryService extends AbstractDiscoveryService
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof OmnilinkBridgeHandler) {
bridgeHandler = (OmnilinkBridgeHandler) handler;
if (handler instanceof OmnilinkBridgeHandler omnilinkBridgeHandler) {
bridgeHandler = omnilinkBridgeHandler;
}
}

View File

@@ -177,11 +177,11 @@ public abstract class AbstractAreaHandler extends AbstractOmnilinkStatusHandler<
protected abstract EnumSet<AreaAlarm> getAlarms();
private void handleKeypadEmergency(ChannelUID channelUID, Command command) {
if (command instanceof DecimalType) {
if (command instanceof DecimalType decimalCommand) {
try {
final OmnilinkBridgeHandler bridge = getOmnilinkBridgeHandler();
if (bridge != null) {
bridge.activateKeypadEmergency(thingID, ((DecimalType) command).intValue());
bridge.activateKeypadEmergency(thingID, decimalCommand.intValue());
} else {
logger.debug("Received null bridge while sending Keypad Emergency command!");
}

View File

@@ -118,8 +118,8 @@ public class AudioSourceHandler extends AbstractOmnilinkHandler {
if (command instanceof RefreshType) {
updateState(CHANNEL_AUDIO_SOURCE_POLLING,
OnOffType.from((scheduledPolling != null && !scheduledPolling.isDone())));
} else if (command instanceof OnOffType) {
handlePolling(channelUID, (OnOffType) command);
} else if (command instanceof OnOffType onOffCommand) {
handlePolling(channelUID, onOffCommand);
} else {
logger.debug("Invalid command: {}, must be RefreshType or OnOffType", command);
}

View File

@@ -111,26 +111,24 @@ public class AudioZoneHandler extends AbstractOmnilinkStatusHandler<ExtendedAudi
}
break;
case CHANNEL_AUDIO_ZONE_VOLUME:
if (command instanceof PercentType) {
sendOmnilinkCommand(CommandMessage.CMD_AUDIO_ZONE_SET_VOLUME, ((PercentType) command).intValue(),
thingID);
if (command instanceof PercentType percentCommand) {
sendOmnilinkCommand(CommandMessage.CMD_AUDIO_ZONE_SET_VOLUME, percentCommand.intValue(), thingID);
} else {
logger.debug("Invalid command: {}, must be PercentType", command);
}
break;
case CHANNEL_AUDIO_ZONE_SOURCE:
if (command instanceof DecimalType) {
sendOmnilinkCommand(CommandMessage.CMD_AUDIO_ZONE_SET_SOURCE, ((DecimalType) command).intValue(),
thingID);
if (command instanceof DecimalType decimalCommand) {
sendOmnilinkCommand(CommandMessage.CMD_AUDIO_ZONE_SET_SOURCE, decimalCommand.intValue(), thingID);
} else {
logger.debug("Invalid command: {}, must be DecimalType", command);
}
break;
case CHANNEL_AUDIO_ZONE_CONTROL:
if (command instanceof PlayPauseType) {
handlePlayPauseCommand(channelUID, (PlayPauseType) command);
} else if (command instanceof NextPreviousType) {
handleNextPreviousCommand(channelUID, (NextPreviousType) command);
if (command instanceof PlayPauseType playPauseCommand) {
handlePlayPauseCommand(channelUID, playPauseCommand);
} else if (command instanceof NextPreviousType nextPreviousCommand) {
handleNextPreviousCommand(channelUID, nextPreviousCommand);
} else {
logger.debug("Invalid command: {}, must be PlayPauseType or NextPreviousType", command);
}

View File

@@ -68,16 +68,16 @@ public class ConsoleHandler extends AbstractOmnilinkHandler {
switch (channelUID.getId()) {
case CHANNEL_CONSOLE_ENABLE_DISABLE_BEEPER:
if (command instanceof StringType) {
if (command instanceof StringType stringCommand) {
sendOmnilinkCommand(CommandMessage.CMD_CONSOLE_ENABLE_DISABLE_BEEPER,
((StringType) command).equals(StringType.valueOf("OFF")) ? 0 : 1, thingID);
stringCommand.equals(StringType.valueOf("OFF")) ? 0 : 1, thingID);
} else {
logger.debug("Invalid command: {}, must be StringType", command);
}
break;
case CHANNEL_CONSOLE_BEEP:
if (command instanceof DecimalType) {
sendOmnilinkCommand(CommandMessage.CMD_CONSOLE_BEEP, ((DecimalType) command).intValue(), thingID);
if (command instanceof DecimalType decimalCommand) {
sendOmnilinkCommand(CommandMessage.CMD_CONSOLE_BEEP, decimalCommand.intValue(), thingID);
} else {
logger.debug("Invalid command: {}, must be DecimalType", command);
}

View File

@@ -191,10 +191,10 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica
switch (channelUID.getId()) {
case CHANNEL_CONSOLE_ENABLE_DISABLE_BEEPER:
if (command instanceof StringType) {
if (command instanceof StringType stringCommand) {
try {
sendOmnilinkCommand(CommandMessage.CMD_CONSOLE_ENABLE_DISABLE_BEEPER,
((StringType) command).equals(StringType.valueOf("OFF")) ? 0 : 1, 0);
stringCommand.equals(StringType.valueOf("OFF")) ? 0 : 1, 0);
updateState(CHANNEL_CONSOLE_ENABLE_DISABLE_BEEPER, UnDefType.UNDEF);
} catch (NumberFormatException | OmniInvalidResponseException | OmniUnknownMessageTypeException
| BridgeOfflineException e) {
@@ -205,9 +205,9 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica
}
break;
case CHANNEL_CONSOLE_BEEP:
if (command instanceof DecimalType) {
if (command instanceof DecimalType decimalCommand) {
try {
sendOmnilinkCommand(CommandMessage.CMD_CONSOLE_BEEP, ((DecimalType) command).intValue(), 0);
sendOmnilinkCommand(CommandMessage.CMD_CONSOLE_BEEP, decimalCommand.intValue(), 0);
updateState(CHANNEL_CONSOLE_BEEP, UnDefType.UNDEF);
} catch (NumberFormatException | OmniInvalidResponseException | OmniUnknownMessageTypeException
| BridgeOfflineException e) {
@@ -287,24 +287,21 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica
if (objectStatus != null) {
Status[] statuses = objectStatus.getStatuses();
for (Status status : statuses) {
if (status instanceof ExtendedUnitStatus) {
ExtendedUnitStatus unitStatus = (ExtendedUnitStatus) status;
if (status instanceof ExtendedUnitStatus unitStatus) {
int unitNumber = unitStatus.getNumber();
logger.debug("Received status update for Unit: {}, status: {}", unitNumber, unitStatus);
Optional<Thing> theThing = getUnitThing(unitNumber);
theThing.map(Thing::getHandler)
.ifPresent(theHandler -> ((UnitHandler) theHandler).handleStatus(unitStatus));
} else if (status instanceof ExtendedZoneStatus) {
ExtendedZoneStatus zoneStatus = (ExtendedZoneStatus) status;
} else if (status instanceof ExtendedZoneStatus zoneStatus) {
int zoneNumber = zoneStatus.getNumber();
logger.debug("Received status update for Zone: {}, status: {}", zoneNumber, zoneStatus);
Optional<Thing> theThing = getChildThing(THING_TYPE_ZONE, zoneNumber);
theThing.map(Thing::getHandler)
.ifPresent(theHandler -> ((ZoneHandler) theHandler).handleStatus(zoneStatus));
} else if (status instanceof ExtendedAreaStatus) {
ExtendedAreaStatus areaStatus = (ExtendedAreaStatus) status;
} else if (status instanceof ExtendedAreaStatus areaStatus) {
int areaNumber = areaStatus.getNumber();
logger.debug("Received status update for Area: {}, status: {}", areaNumber, areaStatus);
@@ -321,16 +318,14 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica
theThing.map(Thing::getHandler)
.ifPresent(theHandler -> ((AbstractAreaHandler) theHandler).handleStatus(areaStatus));
});
} else if (status instanceof ExtendedAccessControlReaderLockStatus) {
ExtendedAccessControlReaderLockStatus lockStatus = (ExtendedAccessControlReaderLockStatus) status;
} else if (status instanceof ExtendedAccessControlReaderLockStatus lockStatus) {
int lockNumber = lockStatus.getNumber();
logger.debug("Received status update for Lock: {}, status: {}", lockNumber, lockStatus);
Optional<Thing> theThing = getChildThing(THING_TYPE_LOCK, lockNumber);
theThing.map(Thing::getHandler)
.ifPresent(theHandler -> ((LockHandler) theHandler).handleStatus(lockStatus));
} else if (status instanceof ExtendedThermostatStatus) {
ExtendedThermostatStatus thermostatStatus = (ExtendedThermostatStatus) status;
} else if (status instanceof ExtendedThermostatStatus thermostatStatus) {
int thermostatNumber = thermostatStatus.getNumber();
logger.debug("Received status update for Thermostat: {}, status: {}", thermostatNumber,
@@ -338,8 +333,7 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica
Optional<Thing> theThing = getChildThing(THING_TYPE_THERMOSTAT, thermostatNumber);
theThing.map(Thing::getHandler)
.ifPresent(theHandler -> ((ThermostatHandler) theHandler).handleStatus(thermostatStatus));
} else if (status instanceof ExtendedAudioZoneStatus) {
ExtendedAudioZoneStatus audioZoneStatus = (ExtendedAudioZoneStatus) status;
} else if (status instanceof ExtendedAudioZoneStatus audioZoneStatus) {
int audioZoneNumber = audioZoneStatus.getNumber();
logger.debug("Received status update for Audio Zone: {}, status: {}", audioZoneNumber,
@@ -347,8 +341,7 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica
Optional<Thing> theThing = getChildThing(THING_TYPE_AUDIO_ZONE, audioZoneNumber);
theThing.map(Thing::getHandler)
.ifPresent(theHandler -> ((AudioZoneHandler) theHandler).handleStatus(audioZoneStatus));
} else if (status instanceof ExtendedAuxSensorStatus) {
ExtendedAuxSensorStatus auxSensorStatus = (ExtendedAuxSensorStatus) status;
} else if (status instanceof ExtendedAuxSensorStatus auxSensorStatus) {
int auxSensorNumber = auxSensorStatus.getNumber();
// Aux Sensors can be either temperature or humidity, need to check both.

View File

@@ -117,7 +117,7 @@ public class TempSensorHandler extends AbstractOmnilinkStatusHandler<ExtendedAux
}
if (bridgeHandler != null) {
temperatureFormat = bridgeHandler.getTemperatureFormat();
if (!temperatureFormat.isPresent()) {
if (temperatureFormat.isEmpty()) {
logger.warn("Receieved null temperature format!");
return;
}

View File

@@ -136,7 +136,7 @@ public class ThermostatHandler extends AbstractOmnilinkStatusHandler<ExtendedThe
}
if (bridgeHandler != null) {
temperatureFormat = bridgeHandler.getTemperatureFormat();
if (!temperatureFormat.isPresent()) {
if (temperatureFormat.isEmpty()) {
logger.warn("Receieved null temperature format!");
return;
}

View File

@@ -107,8 +107,8 @@ public class UnitHandler extends AbstractOmnilinkStatusHandler<ExtendedUnitStatu
switch (channelUID.getId()) {
case CHANNEL_UNIT_LEVEL:
case CHANNEL_UNIT_SWITCH:
if (command instanceof OnOffType) {
handleOnOff(channelUID, (OnOffType) command);
if (command instanceof OnOffType onOffCommand) {
handleOnOff(channelUID, onOffCommand);
} else {
logger.debug("Invalid command: {}, must be OnOffType", command);
}
@@ -119,8 +119,8 @@ public class UnitHandler extends AbstractOmnilinkStatusHandler<ExtendedUnitStatu
case CHANNEL_UNIT_OFF_FOR_MINUTES:
case CHANNEL_UNIT_ON_FOR_HOURS:
case CHANNEL_UNIT_OFF_FOR_HOURS:
if (command instanceof DecimalType) {
handleUnitDuration(channelUID, (DecimalType) command);
if (command instanceof DecimalType decimalCommand) {
handleUnitDuration(channelUID, decimalCommand);
} else {
logger.debug("Invalid command: {}, must be DecimalType", command);
}

View File

@@ -61,10 +61,10 @@ public class DimmableUnitHandler extends UnitHandler {
private void handleUnitLevel(ChannelUID channelUID, Command command) {
logger.debug("handleUnitLevel called for channel: {}, command: {}", channelUID, command);
if (command instanceof PercentType) {
handlePercent(channelUID, (PercentType) command);
} else if (command instanceof IncreaseDecreaseType) {
handleIncreaseDecrease(channelUID, (IncreaseDecreaseType) command);
if (command instanceof PercentType percentCommand) {
handlePercent(channelUID, percentCommand);
} else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
handleIncreaseDecrease(channelUID, increaseDecreaseCommand);
} else {
// Only handle percent or increase/decrease.
super.handleCommand(channelUID, command);

View File

@@ -61,16 +61,15 @@ public class FlagHandler extends UnitHandler {
switch (channelUID.getId()) {
case CHANNEL_FLAG_VALUE:
if (command instanceof DecimalType) {
sendOmnilinkCommand(CommandMessage.CMD_UNIT_SET_COUNTER, ((DecimalType) command).intValue(),
thingID);
if (command instanceof DecimalType decimalCommand) {
sendOmnilinkCommand(CommandMessage.CMD_UNIT_SET_COUNTER, decimalCommand.intValue(), thingID);
} else {
logger.debug("Invalid command: {}, must be DecimalType", command);
}
break;
case CHANNEL_FLAG_SWITCH:
if (command instanceof OnOffType) {
handleOnOff(channelUID, (OnOffType) command);
if (command instanceof OnOffType onOffCommand) {
handleOnOff(channelUID, onOffCommand);
} else {
logger.debug("Invalid command: {}, must be OnOffType", command);
}

View File

@@ -64,22 +64,22 @@ public class UpbRoomHandler extends UnitHandler {
case CHANNEL_ROOM_SCENE_B:
case CHANNEL_ROOM_SCENE_C:
case CHANNEL_ROOM_SCENE_D:
if (command instanceof OnOffType) {
handleRoomScene(channelUID, (OnOffType) command);
if (command instanceof OnOffType onOffCommand) {
handleRoomScene(channelUID, onOffCommand);
} else {
logger.debug("Invalid command: {}, must be OnOffType", command);
}
break;
case CHANNEL_ROOM_SWITCH:
if (command instanceof OnOffType) {
super.handleOnOff(channelUID, (OnOffType) command);
if (command instanceof OnOffType onOffCommand) {
super.handleOnOff(channelUID, onOffCommand);
} else {
logger.debug("Invalid command: {}, must be OnOffType", command);
}
break;
case CHANNEL_ROOM_STATE:
if (command instanceof DecimalType) {
handleRoomState(channelUID, (DecimalType) command);
if (command instanceof DecimalType decimalCommand) {
handleRoomState(channelUID, decimalCommand);
} else {
logger.debug("Invalid command: {}, must be DecimalType", command);
}