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:
@@ -82,9 +82,7 @@ public class EleroTransmitterStickHandlerFactory extends BaseThingHandlerFactory
|
||||
|
||||
return bridgeHandler;
|
||||
} else if (thingTypeUID.equals(THING_TYPE_ELERO_CHANNEL)) {
|
||||
EleroChannelHandler h = new EleroChannelHandler(thing);
|
||||
|
||||
return h;
|
||||
return new EleroChannelHandler(thing);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -15,7 +15,7 @@ package org.openhab.binding.elerotransmitterstick.internal.discovery;
|
||||
import static org.openhab.binding.elerotransmitterstick.internal.EleroTransmitterStickBindingConstants.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class EleroChannelDiscoveryService extends AbstractDiscoveryService {
|
||||
* Creates the discovery service for the given handler and converter.
|
||||
*/
|
||||
public EleroChannelDiscoveryService(EleroTransmitterStickHandler stickHandler) {
|
||||
super(Collections.singleton(THING_TYPE_ELERO_CHANNEL), DISCOVER_TIMEOUT_SECONDS, true);
|
||||
super(Set.of(THING_TYPE_ELERO_CHANNEL), DISCOVER_TIMEOUT_SECONDS, true);
|
||||
|
||||
bridge = stickHandler;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ package org.openhab.binding.elerotransmitterstick.internal.handler;
|
||||
|
||||
import static org.openhab.binding.elerotransmitterstick.internal.EleroTransmitterStickBindingConstants.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.openhab.binding.elerotransmitterstick.internal.config.EleroChannelConfig;
|
||||
import org.openhab.binding.elerotransmitterstick.internal.stick.CommandType;
|
||||
@@ -88,20 +88,20 @@ public class EleroChannelHandler extends BaseThingHandler implements StatusListe
|
||||
|
||||
if (channelUID.getIdWithoutGroup().equals(CONTROL_CHANNEL)) {
|
||||
if (command == UpDownType.UP) {
|
||||
bridge.getStick().sendCommand(CommandType.UP, Collections.singletonList(channelId));
|
||||
bridge.getStick().sendCommand(CommandType.UP, List.of(channelId));
|
||||
} else if (command == UpDownType.DOWN) {
|
||||
bridge.getStick().sendCommand(CommandType.DOWN, Collections.singletonList(channelId));
|
||||
bridge.getStick().sendCommand(CommandType.DOWN, List.of(channelId));
|
||||
} else if (command == StopMoveType.STOP) {
|
||||
bridge.getStick().sendCommand(CommandType.STOP, Collections.singletonList(channelId));
|
||||
} else if (command instanceof PercentType) {
|
||||
CommandType cmd = CommandType.getForPercent(((PercentType) command).intValue());
|
||||
bridge.getStick().sendCommand(CommandType.STOP, List.of(channelId));
|
||||
} else if (command instanceof PercentType pt) {
|
||||
CommandType cmd = CommandType.getForPercent(pt.intValue());
|
||||
if (cmd != null) {
|
||||
bridge.getStick().sendCommand(cmd, Collections.singletonList(channelId));
|
||||
bridge.getStick().sendCommand(cmd, List.of(channelId));
|
||||
} else {
|
||||
logger.debug("Unhandled command {}.", command);
|
||||
}
|
||||
} else if (command == RefreshType.REFRESH) {
|
||||
bridge.getStick().requestUpdate(Collections.singletonList(channelId));
|
||||
bridge.getStick().requestUpdate(List.of(channelId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@@ -226,7 +225,7 @@ public class TransmitterStick {
|
||||
// handle commands that are sent to multiple channels correctly
|
||||
if (channelIds.size() > 1) {
|
||||
for (int channelId : channelIds) {
|
||||
requestUpdates(Collections.singletonList(channelId));
|
||||
requestUpdates(List.of(channelId));
|
||||
}
|
||||
} else if (!channelIds.isEmpty()) {
|
||||
final Integer[] ids = channelIds.toArray(new Integer[channelIds.size()]);
|
||||
@@ -241,7 +240,7 @@ public class TransmitterStick {
|
||||
// handle commands that are sent to multiple channels correctly
|
||||
if (channelIds.size() > 1) {
|
||||
for (int channelId : channelIds) {
|
||||
executeCommand(command, Collections.singletonList(channelId));
|
||||
executeCommand(command, List.of(channelId));
|
||||
}
|
||||
} else if (!channelIds.isEmpty()) {
|
||||
final Integer[] ids = channelIds.toArray(new Integer[channelIds.size()]);
|
||||
@@ -307,8 +306,8 @@ public class TransmitterStick {
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd instanceof TimedCommand) {
|
||||
long delay = 1000 * ((TimedCommand) cmd).getDuration();
|
||||
if (cmd instanceof TimedCommand timedCommand) {
|
||||
long delay = 1000 * timedCommand.getDuration();
|
||||
logger.debug("adding timed command STOP for channel ids {} to queue with delay {}...",
|
||||
cmd.getChannelIds(), delay);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user