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:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user