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:
@@ -75,8 +75,8 @@ public class BridgeActions implements ThingActions {
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
if (handler instanceof DeconzBridgeHandler) {
|
||||
this.handler = (DeconzBridgeHandler) handler;
|
||||
if (handler instanceof DeconzBridgeHandler bridgeHandler) {
|
||||
this.handler = bridgeHandler;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -144,8 +144,8 @@ public class GroupActions implements ThingActions {
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
if (handler instanceof GroupThingHandler) {
|
||||
this.handler = (GroupThingHandler) handler;
|
||||
if (handler instanceof GroupThingHandler thingHandler) {
|
||||
this.handler = thingHandler;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ import static org.openhab.binding.deconz.internal.BindingConstants.*;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
@@ -48,7 +47,7 @@ public class BridgeDiscoveryParticipant implements UpnpDiscoveryParticipant {
|
||||
|
||||
@Override
|
||||
public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
|
||||
return Collections.singleton(BRIDGE_TYPE);
|
||||
return Set.of(BRIDGE_TYPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -291,8 +291,8 @@ public class ThingDiscoveryService extends AbstractDiscoveryService implements D
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
if (handler instanceof DeconzBridgeHandler) {
|
||||
this.handler = (DeconzBridgeHandler) handler;
|
||||
if (handler instanceof DeconzBridgeHandler bridgeHandler) {
|
||||
this.handler = bridgeHandler;
|
||||
this.bridgeUID = handler.getThing().getUID();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,10 +119,10 @@ public class GroupThingHandler extends DeconzBaseThingHandler {
|
||||
newGroupAction.xy = new double[] { xy[0], xy[1] };
|
||||
newGroupAction.bri = (int) (xy[2] * BRIGHTNESS_MAX);
|
||||
}
|
||||
} else if (command instanceof PercentType) {
|
||||
newGroupAction.bri = Util.fromPercentType((PercentType) command);
|
||||
} else if (command instanceof DecimalType) {
|
||||
newGroupAction.bri = ((DecimalType) command).intValue();
|
||||
} else if (command instanceof PercentType percentCommand) {
|
||||
newGroupAction.bri = Util.fromPercentType(percentCommand);
|
||||
} else if (command instanceof DecimalType decimalCommand) {
|
||||
newGroupAction.bri = decimalCommand.intValue();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import static org.openhab.core.library.unit.SIUnits.CELSIUS;
|
||||
import static org.openhab.core.library.unit.Units.PERCENT;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -63,7 +62,7 @@ import com.google.gson.Gson;
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class SensorThermostatThingHandler extends SensorBaseThingHandler {
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_THERMOSTAT);
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_THERMOSTAT);
|
||||
|
||||
private static final List<String> CONFIG_CHANNELS = List.of(CHANNEL_EXTERNAL_WINDOW_OPEN, CHANNEL_BATTERY_LEVEL,
|
||||
CHANNEL_BATTERY_LOW, CHANNEL_HEATSETPOINT, CHANNEL_TEMPERATURE_OFFSET, CHANNEL_THERMOSTAT_MODE,
|
||||
@@ -102,8 +101,8 @@ public class SensorThermostatThingHandler extends SensorBaseThingHandler {
|
||||
newConfig.offset = newOffset;
|
||||
}
|
||||
case CHANNEL_THERMOSTAT_MODE -> {
|
||||
if (command instanceof StringType) {
|
||||
String thermostatMode = ((StringType) command).toString();
|
||||
if (command instanceof StringType stringCommand) {
|
||||
String thermostatMode = stringCommand.toString();
|
||||
try {
|
||||
newConfig.mode = ThermostatMode.valueOf(thermostatMode);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
@@ -205,8 +204,8 @@ public class SensorThermostatThingHandler extends SensorBaseThingHandler {
|
||||
|
||||
private @Nullable Integer getTemperatureFromCommand(Command command) {
|
||||
BigDecimal newTemperature;
|
||||
if (command instanceof DecimalType) {
|
||||
newTemperature = ((DecimalType) command).toBigDecimal();
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
newTemperature = decimalCommand.toBigDecimal();
|
||||
} else if (command instanceof QuantityType) {
|
||||
@SuppressWarnings("unchecked")
|
||||
QuantityType<Temperature> temperatureCelsius = ((QuantityType<Temperature>) command).toUnit(CELSIUS);
|
||||
|
||||
Reference in New Issue
Block a user