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

@@ -54,7 +54,6 @@ public class HeliosEasyControlsActions implements ThingActions {
private void triggerSwitch(String variableName) {
try {
if (handler != null) {
handler.writeValue(variableName, "1");
}
} catch (HeliosException e) {

View File

@@ -21,10 +21,10 @@ import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.Semaphore;
@@ -207,8 +207,8 @@ public class HeliosEasyControlsHandler extends BaseThingHandler {
return null;
}
if (handler instanceof ModbusEndpointThingHandler) {
return (ModbusEndpointThingHandler) handler;
if (handler instanceof ModbusEndpointThingHandler thingHandler) {
return thingHandler;
} else {
logger.debug("Unexpected bridge handler: {}", handler);
return null;
@@ -319,9 +319,9 @@ public class HeliosEasyControlsHandler extends BaseThingHandler {
String value = null;
if (command instanceof OnOffType) {
value = command == OnOffType.ON ? "1" : "0";
} else if (command instanceof DateTimeType) {
} else if (command instanceof DateTimeType dateTimeCommand) {
try {
ZonedDateTime d = ((DateTimeType) command).getZonedDateTime();
ZonedDateTime d = dateTimeCommand.getZonedDateTime();
if (channelId.equals(HeliosEasyControlsBindingConstants.SYS_DATE)) {
setSysDateTime(d);
} else if (channelId.equals(HeliosEasyControlsBindingConstants.BYPASS_FROM)) {
@@ -329,7 +329,7 @@ public class HeliosEasyControlsHandler extends BaseThingHandler {
} else if (channelId.equals(HeliosEasyControlsBindingConstants.BYPASS_TO)) {
this.setBypass(false, d.getDayOfMonth(), d.getMonthValue());
} else {
value = formatDate(channelId, ((DateTimeType) command).getZonedDateTime());
value = formatDate(channelId, dateTimeCommand.getZonedDateTime());
}
} catch (InterruptedException e) {
logger.debug(
@@ -338,14 +338,13 @@ public class HeliosEasyControlsHandler extends BaseThingHandler {
}
} else if ((command instanceof DecimalType) || (command instanceof StringType)) {
value = command.toString();
} else if (command instanceof QuantityType<?>) {
} else if (command instanceof QuantityType<?> val) {
// convert item's unit to the Helios device's unit
Map<String, HeliosVariable> variableMap = this.variableMap;
if (variableMap != null) {
HeliosVariable v = variableMap.get(channelId);
if (v != null) {
String unit = v.getUnit();
QuantityType<?> val = (QuantityType<?>) command;
if (unit != null) {
switch (unit) {
case HeliosVariable.UNIT_DAY:
@@ -406,7 +405,7 @@ public class HeliosEasyControlsHandler extends BaseThingHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(HeliosEasyControlsActions.class);
return Set.of(HeliosEasyControlsActions.class);
}
/**
@@ -855,7 +854,7 @@ public class HeliosEasyControlsHandler extends BaseThingHandler {
switch (itemType) {
case "Number":
if (((HeliosVariable.TYPE_INTEGER.equals(variableType))
|| (HeliosVariable.TYPE_FLOAT.equals(variableType))) && (!value.equals("-"))) {
|| (HeliosVariable.TYPE_FLOAT.equals(variableType))) && (!"-".equals(value))) {
State state = null;
if (v.getUnit() == null) {
state = DecimalType.valueOf(value);
@@ -880,7 +879,7 @@ public class HeliosEasyControlsHandler extends BaseThingHandler {
break;
case "Switch":
if (variableType.equals(HeliosVariable.TYPE_INTEGER)) {
updateState(v.getGroupAndName(), value.equals("1") ? OnOffType.ON : OnOffType.OFF);
updateState(v.getGroupAndName(), "1".equals(value) ? OnOffType.ON : OnOffType.OFF);
}
break;
case "String":

View File

@@ -14,7 +14,6 @@ package org.openhab.binding.modbus.helioseasycontrols.internal;
import static org.openhab.binding.modbus.helioseasycontrols.internal.HeliosEasyControlsBindingConstants.THING_TYPE_HELIOS_VENTILATION_EASY_CONTROLS;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -39,8 +38,8 @@ import org.osgi.service.component.annotations.Reference;
@Component(configurationPid = "binding.helioseasycontrols", service = ThingHandlerFactory.class)
public class HeliosEasyControlsHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
.singleton(THING_TYPE_HELIOS_VENTILATION_EASY_CONTROLS);
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set
.of(THING_TYPE_HELIOS_VENTILATION_EASY_CONTROLS);
private final HeliosEasyControlsTranslationProvider translationProvider;
@Activate