Java 17 features (H-M) (#15520)

- 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-08 14:36:59 +02:00
committed by GitHub
parent 3751fd0646
commit edaf17b345
519 changed files with 2703 additions and 2660 deletions

View File

@@ -14,7 +14,6 @@ package org.openhab.binding.keba.internal;
import static org.openhab.binding.keba.internal.KebaBindingConstants.THING_TYPE_KECONTACTP20;
import java.util.Collections;
import java.util.Set;
import org.openhab.binding.keba.internal.handler.KeContactHandler;
@@ -35,7 +34,7 @@ import org.osgi.service.component.annotations.Component;
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.keba")
public class KebaHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_KECONTACTP20);
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_KECONTACTP20);
private final KeContactTransceiver transceiver = new KeContactTransceiver();

View File

@@ -342,7 +342,7 @@ public class KeContactHandler extends BaseThingHandler {
updateState(CHANNEL_MAX_SYSTEM_CURRENT, newState);
if (maxSystemCurrent != 0) {
if (maxSystemCurrent < maxPresetCurrent) {
transceiver.send("curr " + String.valueOf(maxSystemCurrent), this);
transceiver.send("curr " + maxSystemCurrent, this);
updateState(CHANNEL_MAX_PRESET_CURRENT,
new QuantityType<ElectricCurrent>(maxSystemCurrent / 1000.0, Units.AMPERE));
updateState(CHANNEL_MAX_PRESET_CURRENT_RANGE, new QuantityType<Dimensionless>(
@@ -528,12 +528,10 @@ public class KeContactHandler extends BaseThingHandler {
} else {
switch (channelUID.getId()) {
case CHANNEL_MAX_PRESET_CURRENT: {
if (command instanceof QuantityType<?>) {
QuantityType<?> value = ((QuantityType<?>) command).toUnit("mA");
if (command instanceof QuantityType<?> quantityCommand) {
QuantityType<?> value = quantityCommand.toUnit("mA");
transceiver.send(
"curr " + String.valueOf(Math.min(Math.max(6000, value.intValue()), maxSystemCurrent)),
this);
transceiver.send("curr " + Math.min(Math.max(6000, value.intValue()), maxSystemCurrent), this);
}
break;
}
@@ -549,13 +547,13 @@ public class KeContactHandler extends BaseThingHandler {
newValue = maxSystemCurrent;
} else if (command == OnOffType.OFF) {
newValue = 6000;
} else if (command instanceof QuantityType<?>) {
QuantityType<?> value = ((QuantityType<?>) command).toUnit("%");
} else if (command instanceof QuantityType<?> quantityCommand) {
QuantityType<?> value = quantityCommand.toUnit("%");
newValue = Math.round(6000 + (maxSystemCurrent - 6000) * value.doubleValue() / 100.0);
} else {
return;
}
transceiver.send("curr " + String.valueOf(newValue), this);
transceiver.send("curr " + newValue, this);
}
break;
}
@@ -596,11 +594,10 @@ public class KeContactHandler extends BaseThingHandler {
break;
}
case CHANNEL_SETENERGY: {
if (command instanceof QuantityType<?>) {
QuantityType<?> value = ((QuantityType<?>) command).toUnit(Units.WATT_HOUR);
if (command instanceof QuantityType<?> quantityCommand) {
QuantityType<?> value = quantityCommand.toUnit(Units.WATT_HOUR);
transceiver.send(
"setenergy " + String.valueOf(
Math.min(Math.max(0, Math.round(value.doubleValue() * 10.0)), 999999999)),
"setenergy " + Math.min(Math.max(0, Math.round(value.doubleValue() * 10.0)), 999999999),
this);
}
break;

View File

@@ -405,7 +405,7 @@ public class KeContactTransceiver {
private void establishConnection(KeContactHandler handler) {
String ipAddress = handler.getIPAddress();
if (handler.getThing().getStatusInfo().getStatusDetail() != ThingStatusDetail.CONFIGURATION_ERROR
&& !ipAddress.equals("")) {
&& !"".equals(ipAddress)) {
logger.debug("Establishing the connection to the KEBA KeContact '{}'", handler.getThing().getUID());
DatagramChannel datagramChannel = null;