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

@@ -45,8 +45,14 @@ public class RdsBindingConstants {
private static final String API = "https://api.climatixic.com/";
private static final String ARG_RDS = "?filterId=[" + "{\"asn\":\"RDS110\"}," + "{\"asn\":\"RDS120\"},"
+ "{\"asn\":\"RDS110.R\"}," + "{\"asn\":\"RDS120.B\"}" + "]";
private static final String ARG_RDS = """
?filterId=[\
{"asn":"RDS110"},\
{"asn":"RDS120"},\
{"asn":"RDS110.R"},\
{"asn":"RDS120.B"}\
]\
""";
private static final String ARG_PARENT = "?parentId=[\"%s\"]&take=100";
private static final String ARG_POINT = "?filterId=[%s]";

View File

@@ -201,7 +201,6 @@ public class RdsDiscoveryService extends AbstractDiscoveryService {
bridgeUID, label, plantId);
thingDiscovered(disco);
;
} catch (RdsCloudException e) {
logger.warn(LOG_SYSTEM_EXCEPTION, "publishPlant()", e.getClass().getName(), e.getMessage());
} catch (JsonParseException | IOException e) {

View File

@@ -34,7 +34,6 @@ import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.ThingStatusInfo;
import org.openhab.core.thing.binding.BaseThingHandler;
import org.openhab.core.thing.binding.BridgeHandler;
import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType;
import org.openhab.core.types.State;
@@ -314,9 +313,9 @@ public class RdsHandler extends BaseThingHandler {
switch (channel.id) {
case CHA_TARGET_TEMP: {
Command doCommand = command;
if (command instanceof QuantityType<?>) {
if (command instanceof QuantityType<?> quantityCommand) {
Unit<?> unit = points.getPointByClass(channel.clazz).getUnit();
QuantityType<?> temp = ((QuantityType<?>) command).toUnit(unit);
QuantityType<?> temp = quantityCommand.toUnit(unit);
if (temp != null) {
doCommand = temp;
}
@@ -381,11 +380,9 @@ public class RdsHandler extends BaseThingHandler {
private RdsCloudHandler getCloudHandler() throws RdsCloudException {
@Nullable
Bridge b;
@Nullable
BridgeHandler h;
if ((b = getBridge()) != null && (h = b.getHandler()) != null && h instanceof RdsCloudHandler) {
return (RdsCloudHandler) h;
if ((b = getBridge()) != null && (b.getHandler() instanceof RdsCloudHandler cloudHandler)) {
return cloudHandler;
}
throw new RdsCloudException("no cloud handler found");
}

View File

@@ -14,10 +14,7 @@ package org.openhab.binding.siemensrds.internal;
import static org.openhab.binding.siemensrds.internal.RdsBindingConstants.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;
@@ -44,8 +41,7 @@ import org.osgi.service.component.annotations.Component;
@Component(configurationPid = "binding.siemensrds", service = ThingHandlerFactory.class)
public class RdsHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
.unmodifiableSet(new HashSet<>(Arrays.asList(THING_TYPE_CLOUD, THING_TYPE_RDS)));
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_CLOUD, THING_TYPE_RDS);
private final Map<ThingUID, ServiceRegistration<?>> discos = new HashMap<>();
@@ -58,8 +54,8 @@ public class RdsHandlerFactory extends BaseThingHandlerFactory {
protected @Nullable ThingHandler createHandler(Thing thing) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
if ((thingTypeUID.equals(THING_TYPE_CLOUD)) && (thing instanceof Bridge)) {
RdsCloudHandler handler = new RdsCloudHandler((Bridge) thing);
if ((thingTypeUID.equals(THING_TYPE_CLOUD)) && (thing instanceof Bridge bridge)) {
RdsCloudHandler handler = new RdsCloudHandler(bridge);
createDiscoveryService(handler);
return handler;
}
@@ -73,8 +69,8 @@ public class RdsHandlerFactory extends BaseThingHandlerFactory {
@Override
protected synchronized void removeHandler(ThingHandler handler) {
if (handler instanceof RdsCloudHandler) {
destroyDiscoveryService((RdsCloudHandler) handler);
if (handler instanceof RdsCloudHandler cloudHandler) {
destroyDiscoveryService(cloudHandler);
}
}

View File

@@ -72,8 +72,8 @@ public class NestedNumberPoint extends BasePoint {
@Override
public void refreshValueFrom(BasePoint from) {
super.refreshValueFrom(from);
if (from instanceof NestedNumberPoint) {
NestedNumberValue fromInner = ((NestedNumberPoint) from).inner;
if (from instanceof NestedNumberPoint point) {
NestedNumberValue fromInner = point.inner;
NestedNumberValue thisInner = this.inner;
if (thisInner != null && fromInner != null) {
thisInner.value = fromInner.value;

View File

@@ -46,8 +46,8 @@ public class NumberPoint extends BasePoint {
@Override
public void refreshValueFrom(BasePoint from) {
super.refreshValueFrom(from);
if (from instanceof NumberPoint) {
this.value = ((NumberPoint) from).value;
if (from instanceof NumberPoint point) {
this.value = point.value;
}
}
}

View File

@@ -33,7 +33,7 @@ import com.google.gson.JsonSyntaxException;
@NonNullByDefault
public class PointDeserializer implements JsonDeserializer<BasePoint> {
private static enum PointType {
private enum PointType {
UNDEFINED,
STRING,
NESTED_NUMBER,

View File

@@ -52,8 +52,8 @@ public class StringPoint extends BasePoint {
@Override
public void refreshValueFrom(BasePoint from) {
super.refreshValueFrom(from);
if (from instanceof StringPoint) {
this.value = ((StringPoint) from).value;
if (from instanceof StringPoint stringPoint) {
this.value = stringPoint.value;
}
}
}