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:
@@ -16,11 +16,11 @@ import static org.openhab.binding.yamahareceiver.internal.YamahaReceiverBindingC
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
@@ -49,7 +49,7 @@ public class ChannelsTypeProviderAvailableInputs implements ChannelTypeProvider,
|
||||
|
||||
@Override
|
||||
public Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
|
||||
return Collections.singleton(channelType);
|
||||
return Set.of(channelType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,9 +16,9 @@ import static java.util.stream.Collectors.toList;
|
||||
import static org.openhab.binding.yamahareceiver.internal.YamahaReceiverBindingConstants.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@@ -49,7 +49,7 @@ public class ChannelsTypeProviderPreset implements ChannelTypeProvider, ThingHan
|
||||
|
||||
@Override
|
||||
public Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
|
||||
return Collections.singleton(channelType);
|
||||
return Set.of(channelType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,8 +35,8 @@ public class YamahaReceiverBindingConstants {
|
||||
public static final ThingTypeUID BRIDGE_THING_TYPE = new ThingTypeUID(BINDING_ID, "yamahaAV");
|
||||
public static final ThingTypeUID ZONE_THING_TYPE = new ThingTypeUID(BINDING_ID, "zone");
|
||||
|
||||
public static final Set<ThingTypeUID> BRIDGE_THING_TYPES_UIDS = Collections.singleton(BRIDGE_THING_TYPE);
|
||||
public static final Set<ThingTypeUID> ZONE_THING_TYPES_UIDS = Collections.singleton(ZONE_THING_TYPE);
|
||||
public static final Set<ThingTypeUID> BRIDGE_THING_TYPES_UIDS = Set.of(BRIDGE_THING_TYPE);
|
||||
public static final Set<ThingTypeUID> ZONE_THING_TYPES_UIDS = Set.of(ZONE_THING_TYPE);
|
||||
|
||||
// List of channel IDs for zone control (except power which is also a non-zone/bridge channel)
|
||||
public static final String CHANNEL_POWER = "power";
|
||||
|
||||
@@ -16,7 +16,6 @@ import static org.openhab.binding.yamahareceiver.internal.YamahaReceiverBindingC
|
||||
import static org.openhab.binding.yamahareceiver.internal.YamahaReceiverBindingConstants.Configs.CONFIG_HOST_NAME;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -46,7 +45,7 @@ public class YamahaDiscoveryParticipant implements UpnpDiscoveryParticipant {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(YamahaDiscoveryParticipant.class);
|
||||
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(BRIDGE_THING_TYPE);
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(BRIDGE_THING_TYPE);
|
||||
|
||||
@Override
|
||||
public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
|
||||
|
||||
@@ -16,10 +16,10 @@ import static org.openhab.binding.yamahareceiver.internal.YamahaReceiverBindingC
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -316,7 +316,7 @@ public class YamahaBridgeHandler extends BaseBridgeHandler
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singleton(ZoneDiscoveryService.class);
|
||||
return Set.of(ZoneDiscoveryService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -336,7 +336,7 @@ public class YamahaBridgeHandler extends BaseBridgeHandler
|
||||
bridgeConfig.getPort());
|
||||
|
||||
Optional<String> host = bridgeConfig.getHostWithPort();
|
||||
if (!host.isPresent()) {
|
||||
if (host.isEmpty()) {
|
||||
String msg = "Host or port not set. Double check your thing settings.";
|
||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, msg);
|
||||
logger.warn(msg);
|
||||
|
||||
@@ -145,8 +145,7 @@ public class DeviceInformationXML implements DeviceInformation {
|
||||
|
||||
private boolean isFeatureSupported(Node node, String name) {
|
||||
String value = getNodeContentOrEmpty(node, name);
|
||||
boolean supported = "1".equals(value) || "Available".equals(value);
|
||||
return supported;
|
||||
return "1".equals(value) || "Available".equals(value);
|
||||
}
|
||||
|
||||
private <T> void checkFeature(Node node, String name, T value, Set<T> set) {
|
||||
|
||||
@@ -205,8 +205,7 @@ public class InputWithNavigationControlXML extends AbstractInputControlXML imple
|
||||
if (sameMenu) {
|
||||
if (!selectItem(selectItemName)) {
|
||||
observer.navigationError("Item '" + selectItemName + "' doesn't exist in menu " + state.menuName
|
||||
+ " at level " + String.valueOf(state.menuLayer) + ". Available options are: "
|
||||
+ state.getAllItemLabels());
|
||||
+ " at level " + state.menuLayer + ". Available options are: " + state.getAllItemLabels());
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -220,8 +219,7 @@ public class InputWithNavigationControlXML extends AbstractInputControlXML imple
|
||||
for (String pathElement : pathArr) {
|
||||
if (!selectItem(pathElement)) {
|
||||
observer.navigationError("Item '" + pathElement + "' doesn't exist in menu " + state.menuName
|
||||
+ " at level " + String.valueOf(state.menuLayer) + ". Available options are: "
|
||||
+ state.getAllItemLabels());
|
||||
+ " at level " + state.menuLayer + ". Available options are: " + state.getAllItemLabels());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -258,8 +256,7 @@ public class InputWithNavigationControlXML extends AbstractInputControlXML imple
|
||||
|
||||
int index = findItemOnCurrentPage(name);
|
||||
if (index > 0) {
|
||||
com.send(wrInput(
|
||||
"<List_Control><Direct_Sel>Line_" + String.valueOf(index) + "</Direct_Sel></List_Control>"));
|
||||
com.send(wrInput("<List_Control><Direct_Sel>Line_" + index + "</Direct_Sel></List_Control>"));
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -84,8 +84,7 @@ public class XMLProtocolService {
|
||||
if (doc.getFirstChild() == null) {
|
||||
throw new ReceivedMessageParseException("The command '" + cmd + "' failed: " + response);
|
||||
}
|
||||
Node content = XMLUtils.getNode(doc.getFirstChild(), path);
|
||||
return content;
|
||||
return XMLUtils.getNode(doc.getFirstChild(), path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,7 @@ public class NavigationControlState implements Invalidateable {
|
||||
public int menuLayer = -1;
|
||||
public int currentLine = 0;
|
||||
public int maxLine = -1;
|
||||
public String items[] = new String[InputWithNavigationControlXML.MAX_PER_PAGE];
|
||||
public String[] items = new String[InputWithNavigationControlXML.MAX_PER_PAGE];
|
||||
|
||||
public String getCurrentItemName() {
|
||||
if (currentLine < 1 || currentLine > items.length) {
|
||||
|
||||
Reference in New Issue
Block a user