Java 17 features (A-G) (#15516)

- 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-05 22:30:16 +02:00
committed by GitHub
parent a0dc5c05f2
commit cf10b3e9c7
486 changed files with 2053 additions and 1955 deletions

View File

@@ -61,8 +61,7 @@ public final class Utils {
formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssX");
}
LOGGER.trace("parsing: {}", date);
ZonedDateTime zdt = ZonedDateTime.parse(date, formatter);
return zdt;
return ZonedDateTime.parse(date, formatter);
}
/**

View File

@@ -52,14 +52,14 @@ import com.google.gson.ToNumberPolicy;
@NonNullByDefault
public abstract class AbstractCommand extends BufferingResponseListener implements EaseeCommand {
public static enum RetryOnFailure {
public enum RetryOnFailure {
YES,
NO;
NO
}
public static enum ProcessFailureResponse {
public enum ProcessFailureResponse {
YES,
NO;
NO
}
/**

View File

@@ -60,9 +60,9 @@ public abstract class AbstractWriteCommand extends AbstractCommand {
* @return value as String without unit.
*/
protected String getCommandValue() {
if (command instanceof QuantityType<?>) {
if (command instanceof QuantityType<?> quantityCommand) {
// this is necessary because we must not send the unit to the backend
return String.valueOf(((QuantityType<?>) command).doubleValue());
return String.valueOf(quantityCommand.doubleValue());
} else if (command instanceof OnOffType) {
// this is necessary because we must send booleans and not ON/OFF to the backend
return String.valueOf(command.equals(OnOffType.ON));

View File

@@ -57,8 +57,8 @@ public class EaseeSiteDiscoveryService extends AbstractDiscoveryService implemen
@Override
public void setThingHandler(ThingHandler handler) {
if (handler instanceof EaseeSiteHandler) {
this.bridgeHandler = (EaseeSiteHandler) handler;
if (handler instanceof EaseeSiteHandler siteHandler) {
this.bridgeHandler = siteHandler;
this.bridgeHandler.setDiscoveryService(this);
}
}

View File

@@ -15,9 +15,9 @@ package org.openhab.binding.easee.internal.handler;
import static org.openhab.binding.easee.internal.EaseeBindingConstants.*;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
@@ -181,7 +181,7 @@ public class EaseeSiteHandler extends BaseBridgeHandler implements EaseeBridgeHa
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(EaseeSiteDiscoveryService.class);
return Set.of(EaseeSiteDiscoveryService.class);
}
public void setDiscoveryService(EaseeSiteDiscoveryService discoveryService) {

View File

@@ -130,7 +130,6 @@ public interface EaseeThingHandler extends ThingHandler, ChannelProvider {
default @Nullable Channel getChannel(String groupId, String channelId) {
ThingUID thingUID = this.getThing().getUID();
ChannelGroupUID channelGroupUID = new ChannelGroupUID(thingUID, groupId);
Channel channel = getThing().getChannel(new ChannelUID(channelGroupUID, channelId));
return channel;
return getThing().getChannel(new ChannelUID(channelGroupUID, channelId));
}
}

View File

@@ -122,9 +122,9 @@ class CustomResponseTransformer {
String phase2 = Utils.getAsString(rawData, channelPhase2);
String phase3 = Utils.getAsString(rawData, channelPhase3);
if (channel != null && phase1 != null && phase2 != null && phase3 != null) {
phase1 = phase1.replaceAll("\\.0", "");
phase2 = phase2.replaceAll("\\.0", "");
phase3 = phase3.replaceAll("\\.0", "");
phase1 = phase1.replace(".0", "");
phase2 = phase2.replace(".0", "");
phase3 = phase3.replace(".0", "");
result.put(channel, new StringType(phase1 + ";" + phase2 + ";" + phase3));
}
}