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

@@ -158,7 +158,7 @@ public class PlugwiseHAController {
DomainObjects domainObjects = executeRequest(request);
this.gatewayUpdateDateTime = ZonedDateTime.parse(request.getServerDateTime(), PlugwiseHAController.FORMAT);
int size = 0;
if (!(domainObjects.getAppliances() == null)) {
if (domainObjects.getAppliances() != null) {
size = domainObjects.getAppliances().size();
}
this.logger.debug("Found {} Plugwise Home Automation appliance(s)", size);
@@ -201,7 +201,7 @@ public class PlugwiseHAController {
DomainObjects domainObjects = executeRequest(request);
this.gatewayUpdateDateTime = ZonedDateTime.parse(request.getServerDateTime(), PlugwiseHAController.FORMAT);
int size = 0;
if (!(domainObjects.getLocations() == null)) {
if (domainObjects.getLocations() != null) {
size = domainObjects.getLocations().size();
}
this.logger.debug("Found {} Plugwise Home Automation Zone(s)", size);

View File

@@ -51,8 +51,7 @@ public class DateTimeConverter extends AbstractSingleValueConverter {
}
try {
ZonedDateTime dateTime = ZonedDateTime.parse(str, DateTimeConverter.FORMAT);
return dateTime;
return ZonedDateTime.parse(str, DateTimeConverter.FORMAT);
} catch (DateTimeParseException e) {
logger.debug("Invalid datetime format in {}", str);
return null;

View File

@@ -77,6 +77,7 @@ public class ActuatorFunctionality extends PlugwiseBaseModel implements Plugwise
return upperBound;
}
@Override
public ZonedDateTime getUpdatedDate() {
return updatedDate;
}

View File

@@ -230,7 +230,7 @@ public class Appliance extends PlugwiseBaseModel implements PlugwiseComparableDa
public boolean isBatteryOperated() {
if (this.zigbeeNode instanceof ZigBeeNode) {
return this.zigbeeNode.getPowerSource().equals("battery") && this.getBatteryLevel().isPresent();
return "battery".equals(this.zigbeeNode.getPowerSource()) && this.getBatteryLevel().isPresent();
} else {
return false;
}

View File

@@ -83,6 +83,7 @@ public class Log extends PlugwiseBaseModel implements PlugwiseComparableDate<Log
return measurementDate;
}
@Override
public ZonedDateTime getUpdatedDate() {
return updatedDate;
}

View File

@@ -102,8 +102,8 @@ public class PlugwiseHADiscoveryService extends AbstractDiscoveryService impleme
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof PlugwiseHABridgeHandler) {
bridgeHandler = (PlugwiseHABridgeHandler) handler;
if (handler instanceof PlugwiseHABridgeHandler bridgeHandler) {
this.bridgeHandler = bridgeHandler;
}
}

View File

@@ -119,9 +119,7 @@ public class PlugwiseHAApplianceHandler extends PlugwiseHABaseHandler<Appliance,
@Override
protected @Nullable Appliance getEntity(PlugwiseHAController controller) throws PlugwiseHAException {
PlugwiseHAThingConfig config = getPlugwiseThingConfig();
Appliance appliance = controller.getAppliance(config.getId());
return appliance;
return controller.getAppliance(config.getId());
}
@Override
@@ -140,21 +138,21 @@ public class PlugwiseHAApplianceHandler extends PlugwiseHABaseHandler<Appliance,
switch (channelID) {
case APPLIANCE_LOCK_CHANNEL:
if (command instanceof OnOffType) {
if (command instanceof OnOffType onOffCommand) {
try {
controller.setRelay(entity, (command == OnOffType.ON));
} catch (PlugwiseHAException e) {
logger.warn("Unable to switch relay lock {} for appliance '{}'", (State) command,
logger.warn("Unable to switch relay lock {} for appliance '{}'", onOffCommand,
entity.getName());
}
}
break;
case APPLIANCE_OFFSET_CHANNEL:
if (command instanceof QuantityType) {
if (command instanceof QuantityType quantityCommand) {
Unit<Temperature> unit = entity.getOffsetTemperatureUnit().orElse(UNIT_CELSIUS).equals(UNIT_CELSIUS)
? SIUnits.CELSIUS
: ImperialUnits.FAHRENHEIT;
QuantityType<?> state = ((QuantityType<?>) command).toUnit(unit);
QuantityType<?> state = quantityCommand.toUnit(unit);
if (state != null) {
try {
@@ -167,19 +165,19 @@ public class PlugwiseHAApplianceHandler extends PlugwiseHABaseHandler<Appliance,
}
break;
case APPLIANCE_POWER_CHANNEL:
if (command instanceof OnOffType) {
if (command instanceof OnOffType onOffCommand) {
try {
controller.setRelay(entity, command == OnOffType.ON);
} catch (PlugwiseHAException e) {
logger.warn("Unable to switch relay {} for appliance '{}'", (State) command, entity.getName());
logger.warn("Unable to switch relay {} for appliance '{}'", onOffCommand, entity.getName());
}
}
break;
case APPLIANCE_SETPOINT_CHANNEL:
if (command instanceof QuantityType) {
if (command instanceof QuantityType quantityCommand) {
Unit<Temperature> unit = entity.getSetpointTemperatureUnit().orElse(UNIT_CELSIUS)
.equals(UNIT_CELSIUS) ? SIUnits.CELSIUS : ImperialUnits.FAHRENHEIT;
QuantityType<?> state = ((QuantityType<?>) command).toUnit(unit);
QuantityType<?> state = quantityCommand.toUnit(unit);
if (state != null) {
try {

View File

@@ -18,8 +18,8 @@ import static org.openhab.core.thing.ThingStatus.ONLINE;
import static org.openhab.core.thing.ThingStatusDetail.*;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@@ -108,7 +108,7 @@ public class PlugwiseHABridgeHandler extends BaseBridgeHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(PlugwiseHADiscoveryService.class);
return Set.of(PlugwiseHADiscoveryService.class);
}
@Override

View File

@@ -105,9 +105,7 @@ public class PlugwiseHAZoneHandler extends PlugwiseHABaseHandler<Location, Plugw
@Override
protected @Nullable Location getEntity(PlugwiseHAController controller) throws PlugwiseHAException {
PlugwiseHAThingConfig config = getPlugwiseThingConfig();
Location location = controller.getLocation(config.getId());
return location;
return controller.getLocation(config.getId());
}
@Override
@@ -119,20 +117,20 @@ public class PlugwiseHAZoneHandler extends PlugwiseHABaseHandler<Location, Plugw
if (controller != null) {
switch (channelID) {
case ZONE_COOLING_CHANNEL:
if (command instanceof OnOffType) {
if (command instanceof OnOffType onOffCommand) {
try {
controller.setAllowCooling(entity, command == OnOffType.ON);
} catch (PlugwiseHAException e) {
logger.warn("Unable to switch allow cooling {} for zone '{}'", (State) command,
logger.warn("Unable to switch allow cooling {} for zone '{}'", onOffCommand,
entity.getName());
}
}
break;
case ZONE_SETPOINT_CHANNEL:
if (command instanceof QuantityType) {
if (command instanceof QuantityType quantityCommand) {
Unit<Temperature> unit = entity.getSetpointTemperatureUnit().orElse(UNIT_CELSIUS)
.equals(UNIT_CELSIUS) ? SIUnits.CELSIUS : ImperialUnits.FAHRENHEIT;
QuantityType<?> state = ((QuantityType<?>) command).toUnit(unit);
QuantityType<?> state = quantityCommand.toUnit(unit);
if (state != null) {
try {
controller.setLocationThermostat(entity, state.doubleValue());
@@ -144,31 +142,31 @@ public class PlugwiseHAZoneHandler extends PlugwiseHABaseHandler<Location, Plugw
}
break;
case ZONE_PREHEAT_CHANNEL:
if (command instanceof OnOffType) {
if (command instanceof OnOffType onOffCommand) {
try {
controller.setPreHeating(entity, command == OnOffType.ON);
} catch (PlugwiseHAException e) {
logger.warn("Unable to switch zone pre heating {} for zone '{}'", (State) command,
logger.warn("Unable to switch zone pre heating {} for zone '{}'", onOffCommand,
entity.getName());
}
}
break;
case ZONE_REGULATION_CHANNEL:
if (command instanceof StringType) {
if (command instanceof StringType stringCommand) {
try {
controller.setRegulationControl(entity, command.toString());
} catch (PlugwiseHAException e) {
logger.warn("Unable to switch regulation control {} for zone '{}'", (State) command,
logger.warn("Unable to switch regulation control {} for zone '{}'", stringCommand,
entity.getName());
}
}
break;
case ZONE_PRESETSCENE_CHANNEL:
if (command instanceof StringType) {
if (command instanceof StringType stringCommand) {
try {
controller.setPresetScene(entity, command.toString());
} catch (PlugwiseHAException e) {
logger.warn("Unable to switch preset scene {} for zone '{}'", (State) command,
logger.warn("Unable to switch preset scene {} for zone '{}'", stringCommand,
entity.getName());
}
}