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:
@@ -69,8 +69,8 @@ public class EcobeeActions implements ThingActions {
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
if (handler instanceof EcobeeThermostatBridgeHandler) {
|
||||
this.handler = (EcobeeThermostatBridgeHandler) handler;
|
||||
if (handler instanceof EcobeeThermostatBridgeHandler bridgeHandler) {
|
||||
this.handler = bridgeHandler;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,5 +39,5 @@ enum EcobeeAuthState {
|
||||
/*
|
||||
* This state indicates that the "authorize" and "token" steps were successful.
|
||||
*/
|
||||
COMPLETE;
|
||||
COMPLETE
|
||||
}
|
||||
|
||||
@@ -61,8 +61,8 @@ public class EcobeeDiscoveryService extends AbstractDiscoveryService implements
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
if (handler instanceof EcobeeAccountBridgeHandler) {
|
||||
this.bridgeHandler = (EcobeeAccountBridgeHandler) handler;
|
||||
if (handler instanceof EcobeeAccountBridgeHandler accountBridgeHandler) {
|
||||
this.bridgeHandler = accountBridgeHandler;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ import static org.openhab.binding.ecobee.internal.EcobeeBindingConstants.CONFIG_
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -137,7 +136,7 @@ public class EcobeeAccountBridgeHandler extends BaseBridgeHandler {
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singleton(EcobeeDiscoveryService.class);
|
||||
return Set.of(EcobeeDiscoveryService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,10 +16,10 @@ import static org.openhab.binding.ecobee.internal.EcobeeBindingConstants.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
@@ -237,9 +237,9 @@ public class EcobeeThermostatBridgeHandler extends BaseBridgeHandler {
|
||||
public boolean actionPerformFunction(AbstractFunction function) {
|
||||
logger.debug("ThermostatBridge: Perform function '{}' on thermostat {}", function.type, thermostatId);
|
||||
SelectionDTO selection = new SelectionDTO();
|
||||
selection.setThermostats(Collections.singleton(thermostatId));
|
||||
selection.setThermostats(Set.of(thermostatId));
|
||||
FunctionRequest request = new FunctionRequest(selection);
|
||||
request.functions = Collections.singletonList(function);
|
||||
request.functions = List.of(function);
|
||||
EcobeeAccountBridgeHandler handler = getBridgeHandler();
|
||||
if (handler != null) {
|
||||
return handler.performThermostatFunction(request);
|
||||
@@ -249,7 +249,7 @@ public class EcobeeThermostatBridgeHandler extends BaseBridgeHandler {
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singletonList(EcobeeActions.class);
|
||||
return List.of(EcobeeActions.class);
|
||||
}
|
||||
|
||||
public void updateChannels(ThermostatDTO thermostat) {
|
||||
@@ -329,15 +329,15 @@ public class EcobeeThermostatBridgeHandler extends BaseBridgeHandler {
|
||||
success = true;
|
||||
}
|
||||
} else if (Integer.class.isAssignableFrom(fieldClass)) {
|
||||
if (command instanceof DecimalType) {
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
logger.debug("Set field of type Integer to value of DecimalType");
|
||||
field.set(object, Integer.valueOf(((DecimalType) command).intValue()));
|
||||
field.set(object, Integer.valueOf(decimalCommand.intValue()));
|
||||
success = true;
|
||||
} else if (command instanceof QuantityType) {
|
||||
Unit<?> unit = ((QuantityType<?>) command).getUnit();
|
||||
} else if (command instanceof QuantityType quantityCommand) {
|
||||
Unit<?> unit = quantityCommand.getUnit();
|
||||
logger.debug("Set field of type Integer to value of QuantityType with unit {}", unit);
|
||||
if (unit.equals(ImperialUnits.FAHRENHEIT) || unit.equals(SIUnits.CELSIUS)) {
|
||||
QuantityType<?> quantity = ((QuantityType<?>) command).toUnit(ImperialUnits.FAHRENHEIT);
|
||||
QuantityType<?> quantity = quantityCommand.toUnit(ImperialUnits.FAHRENHEIT);
|
||||
if (quantity != null) {
|
||||
field.set(object, quantity.intValue() * 10);
|
||||
success = true;
|
||||
@@ -801,7 +801,7 @@ public class EcobeeThermostatBridgeHandler extends BaseBridgeHandler {
|
||||
|
||||
private void performThermostatUpdate(ThermostatDTO thermostat) {
|
||||
SelectionDTO selection = new SelectionDTO();
|
||||
selection.setThermostats(Collections.singleton(thermostatId));
|
||||
selection.setThermostats(Set.of(thermostatId));
|
||||
ThermostatUpdateRequestDTO request = new ThermostatUpdateRequestDTO(selection);
|
||||
request.thermostat = thermostat;
|
||||
EcobeeAccountBridgeHandler handler = getBridgeHandler();
|
||||
|
||||
Reference in New Issue
Block a user