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:
@@ -171,9 +171,9 @@ public class PJLinkDeviceHandler extends BaseThingHandler {
|
||||
if (command == RefreshType.REFRESH) {
|
||||
StringType input = new StringType(device.getInputStatus().getResult().getValue());
|
||||
updateState(PJLinkDeviceBindingConstants.CHANNEL_INPUT, input);
|
||||
} else if (command instanceof StringType) {
|
||||
} else if (command instanceof StringType stringCommand) {
|
||||
logger.trace("Received input command {}", command);
|
||||
Input input = new Input(((StringType) command).toString());
|
||||
Input input = new Input(stringCommand.toString());
|
||||
device.setInput(input);
|
||||
} else {
|
||||
logger.debug("Received unknown channel command {}", command);
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.openhab.binding.pjlinkdevice.internal;
|
||||
|
||||
import static org.openhab.binding.pjlinkdevice.internal.PJLinkDeviceBindingConstants.THING_TYPE_PJLINK;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@@ -38,7 +37,7 @@ import org.osgi.service.component.annotations.Reference;
|
||||
@Component(configurationPid = "binding.pjlinkdevice", service = { ThingHandlerFactory.class })
|
||||
public class PJLinkDeviceHandlerFactory extends BaseThingHandlerFactory {
|
||||
private InputChannelStateDescriptionProvider stateDescriptionProvider;
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_PJLINK);
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_PJLINK);
|
||||
|
||||
@Activate
|
||||
public PJLinkDeviceHandlerFactory(@Reference InputChannelStateDescriptionProvider provider) {
|
||||
|
||||
@@ -171,9 +171,6 @@ public class PJLinkDevice {
|
||||
} else {
|
||||
try {
|
||||
authenticate(rawHeader.substring("PJLINK 1 ".length()));
|
||||
} catch (AuthenticationException e) {
|
||||
// propagate AuthenticationException
|
||||
throw e;
|
||||
} catch (ResponseException e) {
|
||||
// maybe only the test command is broken on the device
|
||||
// as long as we don't get an AuthenticationException, we'll just ignore it for now
|
||||
@@ -236,16 +233,16 @@ public class PJLinkDevice {
|
||||
String response = null;
|
||||
while ((response = getReader().readLine()) != null && preprocessResponse(response).isEmpty()) {
|
||||
logger.debug("Got empty string response for request '{}' from {}, waiting for another line", response,
|
||||
fullCommand.replaceAll("\r", "\\\\r"));
|
||||
fullCommand.replace("\r", "\\\\r"));
|
||||
}
|
||||
if (response == null) {
|
||||
throw new ResponseException(MessageFormat.format("Response to request ''{0}'' was null",
|
||||
fullCommand.replaceAll("\r", "\\\\r")));
|
||||
throw new ResponseException(
|
||||
MessageFormat.format("Response to request ''{0}'' was null", fullCommand.replace("\r", "\\\\r")));
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Got response '{}' ({}) for request '{}' from {}", response,
|
||||
Arrays.toString(response.getBytes()), fullCommand.replaceAll("\r", "\\\\r"), ipAddress);
|
||||
Arrays.toString(response.getBytes()), fullCommand.replace("\r", "\\\\r"), ipAddress);
|
||||
}
|
||||
return preprocessResponse(response);
|
||||
}
|
||||
|
||||
@@ -59,14 +59,14 @@ public class CachedCommand<ResponseType extends Response<?>> implements Command<
|
||||
} catch (CacheException e) {
|
||||
// try to unwrap RuntimeException thrown in ExpiringCache
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof ResponseException) {
|
||||
throw (ResponseException) cause;
|
||||
if (cause instanceof ResponseException responseException) {
|
||||
throw responseException;
|
||||
}
|
||||
if (cause instanceof IOException) {
|
||||
throw (IOException) cause;
|
||||
if (cause instanceof IOException ioException) {
|
||||
throw ioException;
|
||||
}
|
||||
if (cause instanceof AuthenticationException) {
|
||||
throw (AuthenticationException) cause;
|
||||
if (cause instanceof AuthenticationException authenticationException) {
|
||||
throw authenticationException;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class LampStatesResponse extends PrefixedResponse<List<LampStatesResponse
|
||||
Matcher matcher = RESPONSE_PARSING_PATTERN.matcher(responseWithoutPrefix);
|
||||
while (matcher.find()) {
|
||||
int lampHours = Integer.parseInt(matcher.group("hours"));
|
||||
boolean active = matcher.group("active").equals("1");
|
||||
boolean active = "1".equals(matcher.group("active"));
|
||||
result.add(new LampState(active, lampHours));
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -101,8 +101,7 @@ public abstract class AbstractDiscoveryParticipant extends AbstractDiscoveryServ
|
||||
|
||||
public static ThingUID createServiceUID(String ip, int tcpPort) {
|
||||
// uid must not contains dots
|
||||
return new ThingUID(PJLinkDeviceBindingConstants.THING_TYPE_PJLINK,
|
||||
ip.replace('.', '_') + "_" + String.valueOf(tcpPort));
|
||||
return new ThingUID(PJLinkDeviceBindingConstants.THING_TYPE_PJLINK, ip.replace('.', '_') + "_" + tcpPort);
|
||||
}
|
||||
|
||||
protected abstract void checkAddress(InetAddress ip, int tcpPort, int timeout);
|
||||
|
||||
@@ -17,7 +17,6 @@ import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InterfaceAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -42,7 +41,7 @@ import org.osgi.service.component.annotations.Component;
|
||||
@NonNullByDefault
|
||||
public class DiscoveryParticipantClass1 extends AbstractDiscoveryParticipant {
|
||||
public DiscoveryParticipantClass1() throws IllegalArgumentException {
|
||||
super(Collections.singleton(PJLinkDeviceBindingConstants.THING_TYPE_PJLINK), 60, true);
|
||||
super(Set.of(PJLinkDeviceBindingConstants.THING_TYPE_PJLINK), 60, true);
|
||||
|
||||
logger.trace("PJLinkProjectorDiscoveryParticipant constructor");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user