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

@@ -31,13 +31,13 @@ public class VolvoOnCallException extends Exception {
private final Logger logger = LoggerFactory.getLogger(VolvoOnCallException.class);
private static final long serialVersionUID = -6215621577081394328L;
public static enum ErrorType {
public enum ErrorType {
UNKNOWN,
SERVICE_UNAVAILABLE,
SERVICE_UNABLE_TO_START,
IOEXCEPTION,
INTERRUPTED,
JSON_SYNTAX;
JSON_SYNTAX
}
private final ErrorType cause;

View File

@@ -46,8 +46,8 @@ public class VolvoOnCallActions implements ThingActions {
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof VehicleHandler) {
this.handler = (VehicleHandler) handler;
if (handler instanceof VehicleHandler vehicleHandler) {
this.handler = vehicleHandler;
}
}

View File

@@ -52,8 +52,8 @@ public class VolvoVehicleDiscoveryService extends AbstractDiscoveryService imple
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof VolvoOnCallBridgeHandler) {
this.handler = (VolvoOnCallBridgeHandler) handler;
if (handler instanceof VolvoOnCallBridgeHandler volvoOnCallBridgeHandler) {
this.handler = volvoOnCallBridgeHandler;
}
}
@@ -104,7 +104,6 @@ public class VolvoVehicleDiscoveryService extends AbstractDiscoveryService imple
logger.warn("Error while discovering vehicle: {}", e.getMessage());
}
}
;
}
stopScan();
}

View File

@@ -27,7 +27,7 @@ import com.google.gson.annotations.SerializedName;
@NonNullByDefault
public class PostResponse extends VocAnswer {
public static enum Status {
public enum Status {
@SerializedName("Started")
STARTED,
@SerializedName("MessageDelivered")
@@ -38,7 +38,7 @@ public class PostResponse extends VocAnswer {
SUCCESSFULL
}
public static enum ServiceType {
public enum ServiceType {
RHBLF, // Remote Honk and Blink Lights ?
RDU, // Remote door unlock
ERS, // Remote engine start

View File

@@ -38,7 +38,7 @@ public class Status extends VocAnswer {
LOW,
@SerializedName("VeryLow")
VERY_LOW,
UNKNOWN;
UNKNOWN
}
public double averageFuelConsumption = UNDEFINED;

View File

@@ -30,7 +30,7 @@ public class TyrePressure {
NORMAL,
@SerializedName("LowSoft")
LOW_SOFT,
UNKNOWN;
UNKNOWN
}
public PressureLevel frontLeftTyrePressure = PressureLevel.UNKNOWN;

View File

@@ -272,8 +272,7 @@ public class VehicleHandler extends BaseThingHandler {
if (api != null) {
queryApiAndUpdateChannels(api);
}
} else if (command instanceof OnOffType) {
OnOffType onOffCommand = (OnOffType) command;
} else if (command instanceof OnOffType onOffCommand) {
if (ENGINE_START.equals(channelID) && onOffCommand == OnOffType.ON) {
actionStart(5);
} else if (REMOTE_HEATER.equals(channelID) || PRECLIMATIZATION.equals(channelID)) {
@@ -549,7 +548,7 @@ public class VehicleHandler extends BaseThingHandler {
VocHttpApi api = bridgeHandler.getApi();
if (api != null) {
try {
PostResponse postResponse = api.postURL(url.toString(), param);
PostResponse postResponse = api.postURL(url, param);
if (postResponse != null) {
pendingActions
.add(scheduler.schedule(new ActionResultController(api, postResponse, scheduler, this),
@@ -560,13 +559,12 @@ public class VehicleHandler extends BaseThingHandler {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
}
}
;
pendingActions.removeIf(ScheduledFuture::isDone);
}
public void actionOpenClose(String action, OnOffType controlState) {
if (activeOptions.containsKey(action)) {
if (!vehicleStatus.getCarLocked().isPresent() || vehicleStatus.getCarLocked().get() != controlState) {
if (vehicleStatus.getCarLocked().isEmpty() || vehicleStatus.getCarLocked().get() != controlState) {
post(String.format("vehicles/%s/%s", configuration.vin, action), "{}");
} else {
logger.info("The car {} is already {}ed", configuration.vin, action);
@@ -599,6 +597,6 @@ public class VehicleHandler extends BaseThingHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singletonList(VolvoOnCallActions.class);
return List.of(VolvoOnCallActions.class);
}
}

View File

@@ -13,7 +13,7 @@
package org.openhab.binding.volvooncall.internal.handler;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@@ -97,7 +97,7 @@ public class VolvoOnCallBridgeHandler extends BaseBridgeHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(VolvoVehicleDiscoveryService.class);
return Set.of(VolvoVehicleDiscoveryService.class);
}
@Override