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:
@@ -14,9 +14,9 @@ package org.openhab.binding.nikobus.internal.discovery;
|
||||
|
||||
import static org.openhab.binding.nikobus.internal.NikobusBindingConstants.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
@@ -44,7 +44,7 @@ public class NikobusDiscoveryService extends AbstractDiscoveryService implements
|
||||
private @Nullable NikobusPcLinkHandler bridgeHandler;
|
||||
|
||||
public NikobusDiscoveryService() throws IllegalArgumentException {
|
||||
super(Collections.singleton(THING_TYPE_PUSH_BUTTON), 0);
|
||||
super(Set.of(THING_TYPE_PUSH_BUTTON), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -92,8 +92,8 @@ public class NikobusDiscoveryService extends AbstractDiscoveryService implements
|
||||
|
||||
@Override
|
||||
public void setThingHandler(ThingHandler handler) {
|
||||
if (handler instanceof NikobusPcLinkHandler) {
|
||||
bridgeHandler = (NikobusPcLinkHandler) handler;
|
||||
if (handler instanceof NikobusPcLinkHandler pcLinkHandler) {
|
||||
bridgeHandler = pcLinkHandler;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,8 +54,8 @@ public class NikobusDimmerModuleHandler extends NikobusSwitchModuleHandler {
|
||||
|
||||
@Override
|
||||
protected int valueFromCommand(String channelId, Command command) {
|
||||
if (command instanceof PercentType) {
|
||||
return Math.round(((PercentType) command).floatValue() / 100f * 255f);
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
return Math.round(percentCommand.floatValue() / 100f * 255f);
|
||||
}
|
||||
|
||||
return super.valueFromCommand(channelId, command);
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
@@ -120,7 +121,7 @@ public class NikobusPcLinkHandler extends BaseBridgeHandler {
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singleton(NikobusDiscoveryService.class);
|
||||
return Set.of(NikobusDiscoveryService.class);
|
||||
}
|
||||
|
||||
private void processReceivedValue(byte value) {
|
||||
|
||||
@@ -195,8 +195,8 @@ public class NikobusPushButtonHandler extends NikobusBaseThingHandler {
|
||||
}
|
||||
|
||||
ThingHandler thingHandler = thing.getHandler();
|
||||
if (thingHandler instanceof NikobusModuleHandler) {
|
||||
return (NikobusModuleHandler) thingHandler;
|
||||
if (thingHandler instanceof NikobusModuleHandler nikobusModuleHandler) {
|
||||
return nikobusModuleHandler;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -256,10 +256,10 @@ public class NikobusPushButtonHandler extends NikobusBaseThingHandler {
|
||||
}
|
||||
|
||||
SwitchModuleGroup getGroup() {
|
||||
if (getSegment(2).equals("1")) {
|
||||
if ("1".equals(getSegment(2))) {
|
||||
return FIRST;
|
||||
}
|
||||
if (getSegment(2).equals("2")) {
|
||||
if ("2".equals(getSegment(2))) {
|
||||
return SECOND;
|
||||
}
|
||||
throw new IllegalArgumentException("Unexpected group found " + getSegment(2));
|
||||
|
||||
@@ -87,13 +87,12 @@ public class NikobusRollershutterModuleHandler extends NikobusModuleHandler {
|
||||
@Override
|
||||
protected int valueFromCommand(String channelId, Command command) {
|
||||
Optional<PositionEstimator> positionEstimator = getPositionEstimator(channelId);
|
||||
if (command instanceof DecimalType) {
|
||||
return positionEstimator.map(estimator -> {
|
||||
return estimator.processSetPosition(((DecimalType) command).intValue());
|
||||
}).orElseThrow(() -> {
|
||||
throw new IllegalArgumentException(
|
||||
"Received position request but no estimation configured for channel " + channelId);
|
||||
});
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
return positionEstimator.map(estimator -> estimator.processSetPosition(decimalCommand.intValue()))
|
||||
.orElseThrow(() -> {
|
||||
throw new IllegalArgumentException(
|
||||
"Received position request but no estimation configured for channel " + channelId);
|
||||
});
|
||||
}
|
||||
int result = convertCommandToValue(channelId, command);
|
||||
positionEstimator.ifPresent(PositionEstimator::cancelStopMovement);
|
||||
|
||||
Reference in New Issue
Block a user