Java 17 features (A-G) (#15516)

- 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-05 22:30:16 +02:00
committed by GitHub
parent a0dc5c05f2
commit cf10b3e9c7
486 changed files with 2053 additions and 1955 deletions

View File

@@ -14,7 +14,6 @@ package org.openhab.binding.automower.internal.bridge;
import static org.openhab.binding.automower.internal.AutomowerBindingConstants.THING_TYPE_BRIDGE;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ScheduledFuture;
@@ -49,7 +48,7 @@ public class AutomowerBridgeHandler extends BaseBridgeHandler {
private static final String HUSQVARNA_API_TOKEN_URL = "https://api.authentication.husqvarnagroup.dev/v1/oauth2/token";
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_BRIDGE);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_BRIDGE);
private static final long DEFAULT_POLLING_INTERVAL_S = TimeUnit.HOURS.toSeconds(1);
private final OAuthFactory oAuthFactory;

View File

@@ -14,10 +14,10 @@ package org.openhab.binding.automower.internal.discovery;
import static org.openhab.binding.automower.internal.AutomowerBindingConstants.THING_TYPE_AUTOMOWER;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.automower.internal.AutomowerBindingConstants;
@@ -42,7 +42,7 @@ public class AutomowerDiscoveryService extends AbstractDiscoveryService {
private final AutomowerBridgeHandler bridgeHandler;
public AutomowerDiscoveryService(AutomowerBridgeHandler bridgeHandler) {
super(Collections.singleton(THING_TYPE_AUTOMOWER), 10, false);
super(Set.of(THING_TYPE_AUTOMOWER), 10, false);
this.bridgeHandler = bridgeHandler;
}

View File

@@ -18,7 +18,6 @@ import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@@ -73,7 +72,7 @@ import com.google.gson.Gson;
*/
@NonNullByDefault
public class AutomowerHandler extends BaseThingHandler {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_AUTOMOWER);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_AUTOMOWER);
private static final String NO_ID = "NO_ID";
private static final long DEFAULT_COMMAND_DURATION_MIN = 60;
private static final long DEFAULT_POLLING_INTERVAL_S = TimeUnit.MINUTES.toSeconds(10);
@@ -120,8 +119,8 @@ public class AutomowerHandler extends BaseThingHandler {
}
private Optional<Integer> getCommandValue(Type type) {
if (type instanceof DecimalType) {
return Optional.of(((DecimalType) type).intValue());
if (type instanceof DecimalType command) {
return Optional.of(command.intValue());
}
return Optional.empty();
}
@@ -132,7 +131,7 @@ public class AutomowerHandler extends BaseThingHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(AutomowerActions.class);
return Set.of(AutomowerActions.class);
}
@Override
@@ -163,8 +162,7 @@ public class AutomowerHandler extends BaseThingHandler {
Bridge bridge = getBridge();
if (bridge != null) {
ThingHandler handler = bridge.getHandler();
if (handler instanceof AutomowerBridgeHandler) {
AutomowerBridgeHandler bridgeHandler = (AutomowerBridgeHandler) handler;
if (handler instanceof AutomowerBridgeHandler bridgeHandler) {
return bridgeHandler.getAutomowerBridge();
}
}