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:
Holger Friedrich
2023-09-21 07:58:53 +02:00
committed by GitHub
parent bf1aa3deb2
commit 1b122a53b9
277 changed files with 1402 additions and 1298 deletions

View File

@@ -22,12 +22,12 @@ import java.time.ZonedDateTime;
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.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@@ -473,7 +473,7 @@ public class TelegramHandler extends BaseThingHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(TelegramActions.class);
return Set.of(TelegramActions.class);
}
/**

View File

@@ -14,7 +14,6 @@ package org.openhab.binding.telegram.internal;
import static org.openhab.binding.telegram.internal.TelegramBindingConstants.TELEGRAM_THING;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -40,7 +39,7 @@ import org.osgi.service.component.annotations.Reference;
@Component(configurationPid = "binding.telegram", service = ThingHandlerFactory.class)
public class TelegramHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(TELEGRAM_THING);
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(TELEGRAM_THING);
private final HttpClient httpClient;

View File

@@ -672,11 +672,11 @@ public class TelegramActions implements ThingActions {
public static boolean sendTelegramAnswer(ThingActions actions, @Nullable String chatId, @Nullable String replyId,
@Nullable String message) {
if (actions instanceof TelegramActions) {
if (actions instanceof TelegramActions telegramActions) {
if (chatId == null) {
return false;
}
return ((TelegramActions) actions).sendTelegramAnswer(Long.valueOf(chatId), replyId, message);
return telegramActions.sendTelegramAnswer(Long.valueOf(chatId), replyId, message);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
@@ -689,11 +689,11 @@ public class TelegramActions implements ThingActions {
public static boolean sendTelegramAnswer(ThingActions actions, @Nullable String chatId, @Nullable String callbackId,
@Nullable String messageId, @Nullable String message) {
if (actions instanceof TelegramActions) {
if (actions instanceof TelegramActions telegramActions) {
if (chatId == null) {
return false;
}
return ((TelegramActions) actions).sendTelegramAnswer(Long.valueOf(chatId), callbackId,
return telegramActions.sendTelegramAnswer(Long.valueOf(chatId), callbackId,
messageId != null ? Long.parseLong(messageId) : null, message);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");