Java 17 features (H-M) (#15520)

- 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:
Holger Friedrich
2023-09-08 14:36:59 +02:00
committed by GitHub
parent 3751fd0646
commit edaf17b345
519 changed files with 2703 additions and 2660 deletions

View File

@@ -168,8 +168,8 @@ public class PatchedMailcapCommandMap extends CommandMap {
if (fieldName.startsWith("x-java-") && fieldName.length() > 7) {
String command = fieldName.substring(7);
value = value.trim();
if (command.equals("fallback-entry")) {
if (value.equals("true")) {
if ("fallback-entry".equals(command)) {
if ("true".equals(value)) {
fallback = true;
}
}

View File

@@ -169,9 +169,9 @@ public class POP3IMAPHandler extends BaseThingHandler {
}
Object rawContent = message.getContent();
String contentAsString;
if (rawContent instanceof String) {
if (rawContent instanceof String str) {
logger.trace("Detected plain text message");
contentAsString = (String) rawContent;
contentAsString = str;
} else if (rawContent instanceof MimeMessage mimeMessage) {
logger.trace("Detected MIME message");
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {

View File

@@ -115,8 +115,7 @@ public class SMTPHandler extends BaseThingHandler {
Field dataField = dataSource.getClass().getDeclaredField("data");
dataField.setAccessible(true);
Object data = dataField.get(dataSource);
if (data instanceof MimeMultipart) {
MimeMultipart mimeMultipart = (MimeMultipart) data;
if (data instanceof MimeMultipart mimeMultipart) {
for (int i = 0; i < mimeMultipart.getCount(); i++) {
Part mimePart = mimeMultipart.getBodyPart(i);
mimePart.getDataHandler().setCommandMap(commandMap);

View File

@@ -230,8 +230,8 @@ public class SendMailActions implements ThingActions {
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof SMTPHandler) {
this.handler = (SMTPHandler) handler;
if (handler instanceof SMTPHandler smtpHandler) {
this.handler = smtpHandler;
}
}