Java 17 features (T-Z) (#15576)

- 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-21 07:58:53 +02:00
committed by GitHub
parent bf1aa3deb2
commit 1b122a53b9
277 changed files with 1402 additions and 1298 deletions

View File

@@ -761,7 +761,7 @@ public class VerisureSession {
if (deviceId != null) {
deviceId = VerisureThingConfiguration.normalizeDeviceId(deviceId);
VerisureThingDTO mouseThing = verisureThings.get(deviceId);
if (mouseThing != null && mouseThing instanceof VerisureMiceDetectionDTO) {
if (mouseThing instanceof VerisureMiceDetectionDTO) {
VerisureMiceDetectionDTO miceDetectorThing = (VerisureMiceDetectionDTO) mouseThing;
miceDetectorThing.setTemperatureValue(climate.getTemperatureValue());
miceDetectorThing.setTemperatureTime(climate.getTemperatureTimestamp());

View File

@@ -13,7 +13,7 @@
package org.openhab.binding.verisure.internal.discovery;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@@ -107,7 +107,7 @@ public class VerisureThingDiscoveryService extends AbstractDiscoveryService
@Override
public void activate() {
super.activate(Collections.singletonMap(DiscoveryService.CONFIG_PROPERTY_BACKGROUND_DISCOVERY, true));
super.activate(Map.of(DiscoveryService.CONFIG_PROPERTY_BACKGROUND_DISCOVERY, true));
}
@Override
@@ -117,8 +117,8 @@ public class VerisureThingDiscoveryService extends AbstractDiscoveryService
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof VerisureBridgeHandler) {
verisureBridgeHandler = (VerisureBridgeHandler) handler;
if (handler instanceof VerisureBridgeHandler verisureBridgeHandler) {
this.verisureBridgeHandler = verisureBridgeHandler;
bridgeUID = verisureBridgeHandler.getUID();
}
}

View File

@@ -16,7 +16,6 @@ import static org.openhab.binding.verisure.internal.VerisureBindingConstants.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -45,7 +44,7 @@ import org.openhab.core.types.UnDefType;
@NonNullByDefault
public class VerisureAlarmThingHandler extends VerisureThingHandler<VerisureAlarmsDTO> {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_ALARM);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_ALARM);
private static final int REFRESH_DELAY_SECONDS = 10;
@@ -143,7 +142,7 @@ public class VerisureAlarmThingHandler extends VerisureThingHandler<VerisureAlar
String alarmStatus = armState.getStatusType();
if (alarmStatus != null) {
getThing().getChannels().stream().map(Channel::getUID)
.filter(channelUID -> isLinked(channelUID) && !channelUID.getId().equals("timestamp"))
.filter(channelUID -> isLinked(channelUID) && !"timestamp".equals(channelUID.getId()))
.forEach(channelUID -> {
State state = getValue(channelUID.getId(), armState);
updateState(channelUID, state);

View File

@@ -15,7 +15,6 @@ package org.openhab.binding.verisure.internal.handler;
import static org.openhab.binding.verisure.internal.VerisureBindingConstants.*;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledFuture;
@@ -53,7 +52,7 @@ import org.slf4j.LoggerFactory;
@NonNullByDefault
public class VerisureBridgeHandler extends BaseBridgeHandler {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_BRIDGE);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_BRIDGE);
private static final int REFRESH_DELAY_SECONDS = 30;
private final Logger logger = LoggerFactory.getLogger(VerisureBridgeHandler.class);
@@ -159,7 +158,7 @@ public class VerisureBridgeHandler extends BaseBridgeHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(VerisureThingDiscoveryService.class);
return Set.of(VerisureThingDiscoveryService.class);
}
private void refreshAndUpdateStatus() {

View File

@@ -14,7 +14,6 @@ package org.openhab.binding.verisure.internal.handler;
import static org.openhab.binding.verisure.internal.VerisureBindingConstants.*;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -34,8 +33,7 @@ import org.openhab.core.thing.ThingTypeUID;
@NonNullByDefault
public class VerisureBroadbandConnectionThingHandler extends VerisureThingHandler<VerisureBroadbandConnectionsDTO> {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections
.singleton(THING_TYPE_BROADBAND_CONNECTION);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_BROADBAND_CONNECTION);
public VerisureBroadbandConnectionThingHandler(Thing thing) {
super(thing);

View File

@@ -71,7 +71,7 @@ public class VerisureClimateDeviceThingHandler extends VerisureThingHandler<Veri
private void updateClimateDeviceState(VerisureClimatesDTO climateJSON) {
getThing().getChannels().stream().map(Channel::getUID)
.filter(channelUID -> isLinked(channelUID) && !channelUID.getId().equals("timestamp"))
.filter(channelUID -> isLinked(channelUID) && !"timestamp".equals(channelUID.getId()))
.forEach(channelUID -> {
State state = getValue(channelUID.getId(), climateJSON);
updateState(channelUID, state);

View File

@@ -14,7 +14,6 @@ package org.openhab.binding.verisure.internal.handler;
import static org.openhab.binding.verisure.internal.VerisureBindingConstants.*;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -41,7 +40,7 @@ import org.openhab.core.types.UnDefType;
@NonNullByDefault
public class VerisureDoorWindowThingHandler extends VerisureThingHandler<VerisureDoorWindowsDTO> {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_DOORWINDOW);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_DOORWINDOW);
public VerisureDoorWindowThingHandler(Thing thing) {
super(thing);
@@ -64,7 +63,7 @@ public class VerisureDoorWindowThingHandler extends VerisureThingHandler<Verisur
DoorWindow doorWindow = doorWindowList.get(0);
getThing().getChannels().stream().map(Channel::getUID)
.filter(channelUID -> isLinked(channelUID) && !channelUID.getId().equals("timestamp"))
.filter(channelUID -> isLinked(channelUID) && !"timestamp".equals(channelUID.getId()))
.forEach(channelUID -> {
State state = getValue(channelUID.getId(), doorWindow, doorWindowJSON);
updateState(channelUID, state);

View File

@@ -51,7 +51,7 @@ public class VerisureEventLogThingHandler extends VerisureThingHandler<VerisureE
private BigDecimal lastEventId = BigDecimal.ZERO;
private long lastEventTime = 0;
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_EVENT_LOG);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_EVENT_LOG);
public VerisureEventLogThingHandler(Thing thing) {
super(thing);
@@ -83,7 +83,7 @@ public class VerisureEventLogThingHandler extends VerisureThingHandler<VerisureE
private void updateEventLogState(VerisureEventLogDTO eventLogJSON) {
EventLog eventLog = eventLogJSON.getData().getInstallation().getEventLog();
if (eventLog.getPagedList().size() > 0) {
if (!eventLog.getPagedList().isEmpty()) {
getThing().getChannels().stream().map(Channel::getUID).filter(channelUID -> isLinked(channelUID))
.forEach(channelUID -> {
State state = getValue(channelUID.getId(), eventLogJSON, eventLog);

View File

@@ -14,7 +14,6 @@ package org.openhab.binding.verisure.internal.handler;
import static org.openhab.binding.verisure.internal.VerisureBindingConstants.*;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -38,7 +37,7 @@ import org.openhab.core.types.UnDefType;
@NonNullByDefault
public class VerisureGatewayThingHandler extends VerisureThingHandler<VerisureGatewayDTO> {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_GATEWAY);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_GATEWAY);
public VerisureGatewayThingHandler(Thing thing) {
super(thing);

View File

@@ -14,7 +14,6 @@ package org.openhab.binding.verisure.internal.handler;
import static org.openhab.binding.verisure.internal.VerisureBindingConstants.*;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -46,7 +45,7 @@ import org.openhab.core.types.UnDefType;
@NonNullByDefault
public class VerisureMiceDetectionThingHandler extends VerisureThingHandler<VerisureMiceDetectionDTO> {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_MICE_DETECTION);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_MICE_DETECTION);
public VerisureMiceDetectionThingHandler(Thing thing) {
super(thing);
@@ -68,12 +67,12 @@ public class VerisureMiceDetectionThingHandler extends VerisureThingHandler<Veri
if (!miceList.isEmpty()) {
Mouse mouse = miceList.get(0);
getThing().getChannels().stream().map(Channel::getUID).filter(channelUID -> isLinked(channelUID)
&& !channelUID.getId().equals("timestamp") && !channelUID.getId().equals("temperatureTimestamp"))
&& !"timestamp".equals(channelUID.getId()) && !"temperatureTimestamp".equals(channelUID.getId()))
.forEach(channelUID -> {
State state = getValue(channelUID.getId(), miceDetectionJSON, mouse);
updateState(channelUID, state);
});
if (mouse.getDetections().size() != 0) {
if (!mouse.getDetections().isEmpty()) {
updateTimeStamp(mouse.getDetections().get(0).getNodeTime());
}
updateTimeStamp(miceDetectionJSON.getTemperatureTime(), CHANNEL_TEMPERATURE_TIMESTAMP);
@@ -86,25 +85,25 @@ public class VerisureMiceDetectionThingHandler extends VerisureThingHandler<Veri
public State getValue(String channelId, VerisureMiceDetectionDTO miceDetectionJSON, Mouse mouse) {
switch (channelId) {
case CHANNEL_COUNT_LATEST_DETECTION:
if (mouse.getDetections().size() == 0) {
if (mouse.getDetections().isEmpty()) {
return new DecimalType(0);
} else {
return new DecimalType(mouse.getDetections().get(0).getCount());
}
case CHANNEL_COUNT_LAST_24_HOURS:
if (mouse.getDetections().size() == 0) {
if (mouse.getDetections().isEmpty()) {
return new DecimalType(0);
} else {
return new DecimalType(mouse.getDetections().stream().mapToInt(Detection::getCount).sum());
}
case CHANNEL_DURATION_LATEST_DETECTION:
if (mouse.getDetections().size() == 0) {
if (mouse.getDetections().isEmpty()) {
return new QuantityType<Time>(0, Units.SECOND);
} else {
return new QuantityType<Time>(mouse.getDetections().get(0).getDuration(), Units.SECOND);
}
case CHANNEL_DURATION_LAST_24_HOURS:
if (mouse.getDetections().size() == 0) {
if (mouse.getDetections().isEmpty()) {
return new QuantityType<Time>(0, Units.SECOND);
} else {
return new QuantityType<Time>(mouse.getDetections().stream().mapToInt(Detection::getDuration).sum(),

View File

@@ -16,7 +16,6 @@ import static org.openhab.binding.verisure.internal.VerisureBindingConstants.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException;
@@ -51,7 +50,7 @@ import org.openhab.core.types.UnDefType;
@NonNullByDefault
public class VerisureSmartLockThingHandler extends VerisureThingHandler<VerisureSmartLocksDTO> {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_SMARTLOCK);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_SMARTLOCK);
private static final int REFRESH_DELAY_SECONDS = 10;
@@ -255,7 +254,7 @@ public class VerisureSmartLockThingHandler extends VerisureThingHandler<Verisure
VerisureSmartLockDTO smartLockJSON = smartLocksJSON.getSmartLockJSON();
if (smartLockStatus != null) {
getThing().getChannels().stream().map(Channel::getUID)
.filter(channelUID -> isLinked(channelUID) && !channelUID.getId().equals("timestamp"))
.filter(channelUID -> isLinked(channelUID) && !"timestamp".equals(channelUID.getId()))
.forEach(channelUID -> {
State state = getValue(channelUID.getId(), doorlock, smartLockStatus, smartLockJSON);
updateState(channelUID, state);

View File

@@ -16,7 +16,6 @@ import static org.openhab.binding.verisure.internal.VerisureBindingConstants.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -47,7 +46,7 @@ import org.openhab.core.types.UnDefType;
@NonNullByDefault
public class VerisureSmartPlugThingHandler extends VerisureThingHandler<VerisureSmartPlugsDTO> {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_SMARTPLUG);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_SMARTPLUG);
private static final int REFRESH_DELAY_SECONDS = 10;
@@ -132,7 +131,7 @@ public class VerisureSmartPlugThingHandler extends VerisureThingHandler<Verisure
String smartPlugStatus = smartplug.getCurrentState();
if (smartPlugStatus != null) {
getThing().getChannels().stream().map(Channel::getUID)
.filter(channelUID -> isLinked(channelUID) && !channelUID.getId().equals("timestamp"))
.filter(channelUID -> isLinked(channelUID) && !"timestamp".equals(channelUID.getId()))
.forEach(channelUID -> {
State state = getValue(channelUID.getId(), smartplug, smartPlugStatus);
updateState(channelUID, state);

View File

@@ -14,7 +14,6 @@ package org.openhab.binding.verisure.internal.handler;
import static org.openhab.binding.verisure.internal.VerisureBindingConstants.*;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -38,7 +37,7 @@ import org.openhab.core.types.UnDefType;
@NonNullByDefault
public class VerisureUserPresenceThingHandler extends VerisureThingHandler<VerisureUserPresencesDTO> {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_USERPRESENCE);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_USERPRESENCE);
public VerisureUserPresenceThingHandler(Thing thing) {
super(thing);
@@ -60,7 +59,7 @@ public class VerisureUserPresenceThingHandler extends VerisureThingHandler<Veris
if (!userTrackingList.isEmpty()) {
UserTracking userTracking = userTrackingList.get(0);
getThing().getChannels().stream().map(Channel::getUID)
.filter(channelUID -> isLinked(channelUID) && !channelUID.getId().equals("timestamp"))
.filter(channelUID -> isLinked(channelUID) && !"timestamp".equals(channelUID.getId()))
.forEach(channelUID -> {
State state = getValue(channelUID.getId(), userTracking);
updateState(channelUID, state);