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:
Holger Friedrich
2023-09-13 08:03:31 +02:00
committed by GitHub
parent 641b482551
commit ab58f4ffb4
471 changed files with 1624 additions and 1868 deletions

View File

@@ -94,7 +94,7 @@ public class PlugwiseMessageProcessor implements SerialPortEventListener {
*/
private void parseAndQueue(ByteBuffer readBuffer) {
String response = new String(readBuffer.array(), 0, readBuffer.limit());
response = response.replaceAll("\r", "").replaceAll("\n", "");
response = response.replace("\r", "").replace("\n", "");
Matcher matcher = RESPONSE_PATTERN.matcher(response);
@@ -123,10 +123,10 @@ public class PlugwiseMessageProcessor implements SerialPortEventListener {
try {
Message message = messageFactory.createMessage(messageType, sequenceNumber, payload);
if (message instanceof AcknowledgementMessage
&& !((AcknowledgementMessage) message).isExtended()) {
if (message instanceof AcknowledgementMessage acknowledgementMessage
&& !acknowledgementMessage.isExtended()) {
logger.debug("Adding to acknowledgedQueue: {}", message);
context.getAcknowledgedQueue().put((AcknowledgementMessage) message);
context.getAcknowledgedQueue().put(acknowledgementMessage);
} else {
logger.debug("Adding to receivedQueue: {}", message);
context.getReceivedQueue().put(message);

View File

@@ -289,8 +289,8 @@ public class PlugwiseThingDiscoveryService extends AbstractDiscoveryService
@Override
public void setThingHandler(ThingHandler handler) {
if (handler instanceof PlugwiseStickHandler) {
stickHandler = (PlugwiseStickHandler) handler;
if (handler instanceof PlugwiseStickHandler plugwiseStickHandler) {
stickHandler = plugwiseStickHandler;
stickHandler.addStickStatusListener(this);
}
}

View File

@@ -353,11 +353,10 @@ public class PlugwiseRelayDeviceHandler extends AbstractPlugwiseThingHandler {
public void handleCommand(ChannelUID channelUID, Command command) {
logger.debug("Handling command '{}' for {} ({}) channel '{}'", command, deviceType, macAddress,
channelUID.getId());
if (CHANNEL_STATE.equals(channelUID.getId()) && (command instanceof OnOffType)) {
if (CHANNEL_STATE.equals(channelUID.getId()) && (command instanceof OnOffType onOffCommand)) {
if (configuration.getPowerStateChanging() == PowerStateChanging.COMMAND_SWITCHING) {
OnOffType onOff = (OnOffType) command;
pendingPowerStateChange = new PendingPowerStateChange(onOff);
handleOnOffCommand(onOff);
pendingPowerStateChange = new PendingPowerStateChange(onOffCommand);
handleOnOffCommand(onOffCommand);
} else {
OnOffType onOff = configuration.getPowerStateChanging() == PowerStateChanging.ALWAYS_ON ? OnOffType.ON
: OnOffType.OFF;

View File

@@ -50,7 +50,7 @@ public class BroadcastGroupSwitchResponseMessage extends Message {
if (matcher.matches()) {
macAddress = new MACAddress(matcher.group(1));
portMask = Integer.parseInt(matcher.group(2));
powerState = (matcher.group(3).equals("01"));
powerState = ("01".equals(matcher.group(3)));
} else {
throw new PlugwisePayloadMismatchException(BROADCAST_GROUP_SWITCH_RESPONSE, PAYLOAD_PATTERN, payload);
}

View File

@@ -113,7 +113,7 @@ public class InformationResponseMessage extends Message {
month = Integer.parseInt(matcher.group(3), 16);
minutes = Integer.parseInt(matcher.group(4), 16);
logAddress = (Integer.parseInt(matcher.group(5), 16) - 278528) / 32;
powerState = (matcher.group(6).equals("01"));
powerState = ("01".equals(matcher.group(6)));
hertz = Integer.parseInt(matcher.group(7), 16);
hardwareVersion = matcher.group(8).substring(0, 4) + "-" + matcher.group(8).substring(4, 8) + "-"
+ matcher.group(8).substring(8, 12);