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

@@ -41,8 +41,7 @@ public class FreeboxBindingConstants {
public static final ThingTypeUID FREEBOX_THING_TYPE_AIRPLAY = new ThingTypeUID(BINDING_ID, "airplay");
// All supported Bridge types
public static final Set<ThingTypeUID> SUPPORTED_BRIDGE_TYPES_UIDS = Collections
.singleton(FREEBOX_BRIDGE_TYPE_SERVER);
public static final Set<ThingTypeUID> SUPPORTED_BRIDGE_TYPES_UIDS = Set.of(FREEBOX_BRIDGE_TYPE_SERVER);
// All supported Thing types
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections

View File

@@ -464,8 +464,7 @@ public class FreeboxApiManager {
// Parse the full response in case of success
T fullResponse = gson.fromJson(jsonResponse, responseClass);
fullResponse.evaluate();
F result = fullResponse.getResult();
return result;
return fullResponse.getResult();
}
private String encodeUrl(String url) throws FreeboxException {

View File

@@ -21,7 +21,7 @@ package org.openhab.binding.freebox.internal.api.model;
*/
public class FreeboxAirMediaReceiverRequest {
private static enum MediaAction {
private enum MediaAction {
START("start"),
STOP("stop");
@@ -36,7 +36,7 @@ public class FreeboxAirMediaReceiverRequest {
}
}
private static enum MediaType {
private enum MediaType {
VIDEO("video"),
PHOTO("photo");

View File

@@ -21,7 +21,7 @@ package org.openhab.binding.freebox.internal.api.model;
*/
public class FreeboxAuthorizationStatus {
private static enum AuthorizationStatus {
private enum AuthorizationStatus {
UNKNOWN("unknown"),
PENDING("pending"),
TIMEOUT("timeout"),

View File

@@ -62,8 +62,8 @@ public class FreeboxCommandExtension extends AbstractConsoleCommandExtension imp
FreeboxHandler handler = null;
if (thing != null) {
thingHandler = thing.getHandler();
if (thingHandler instanceof FreeboxHandler) {
handler = (FreeboxHandler) thingHandler;
if (thingHandler instanceof FreeboxHandler freeboxHandler) {
handler = freeboxHandler;
}
}
if (thing == null) {

View File

@@ -79,8 +79,8 @@ public class FreeboxDiscoveryService extends AbstractDiscoveryService
@Override
public void setThingHandler(ThingHandler handler) {
if (handler instanceof FreeboxHandler) {
bridgeHandler = (FreeboxHandler) handler;
if (handler instanceof FreeboxHandler freeboxHandler) {
bridgeHandler = freeboxHandler;
}
}

View File

@@ -16,9 +16,9 @@ import static org.openhab.binding.freebox.internal.FreeboxBindingConstants.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@@ -92,7 +92,7 @@ public class FreeboxHandler extends BaseBridgeHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(FreeboxDiscoveryService.class);
return Set.of(FreeboxDiscoveryService.class);
}
@Override
@@ -494,8 +494,8 @@ public class FreeboxHandler extends BaseBridgeHandler {
continue;
}
ThingHandler handler = thing.getHandler();
if (handler instanceof FreeboxThingHandler) {
((FreeboxThingHandler) handler).updateNetInfo(hosts);
if (handler instanceof FreeboxThingHandler thingHandler) {
thingHandler.updateNetInfo(hosts);
}
}
@@ -519,8 +519,8 @@ public class FreeboxHandler extends BaseBridgeHandler {
continue;
}
ThingHandler handler = thing.getHandler();
if (handler instanceof FreeboxThingHandler) {
((FreeboxThingHandler) handler).updateAirPlayDevice(devices);
if (handler instanceof FreeboxThingHandler thingHandler) {
thingHandler.updateAirPlayDevice(devices);
}
}
@@ -542,12 +542,10 @@ public class FreeboxHandler extends BaseBridgeHandler {
} else if (command instanceof OnOffType) {
updateChannelDecimalState(LCDBRIGHTNESS,
apiManager.setLcdBrightness((command == OnOffType.ON) ? 100 : 0));
} else if (command instanceof DecimalType) {
updateChannelDecimalState(LCDBRIGHTNESS,
apiManager.setLcdBrightness(((DecimalType) command).intValue()));
} else if (command instanceof PercentType) {
updateChannelDecimalState(LCDBRIGHTNESS,
apiManager.setLcdBrightness(((PercentType) command).intValue()));
} else if (command instanceof DecimalType decimalCommand) {
updateChannelDecimalState(LCDBRIGHTNESS, apiManager.setLcdBrightness(decimalCommand.intValue()));
} else if (command instanceof PercentType percentCommand) {
updateChannelDecimalState(LCDBRIGHTNESS, apiManager.setLcdBrightness(percentCommand.intValue()));
} else {
logger.debug("Thing {}: invalid command {} from channel {}", getThing().getUID(), command,
channelUID.getId());
@@ -559,9 +557,9 @@ public class FreeboxHandler extends BaseBridgeHandler {
}
private void setOrientation(ChannelUID channelUID, Command command) {
if (command instanceof DecimalType) {
if (command instanceof DecimalType orientation) {
try {
FreeboxLcdConfig config = apiManager.setLcdOrientation(((DecimalType) command).intValue());
FreeboxLcdConfig config = apiManager.setLcdOrientation(orientation.intValue());
updateChannelDecimalState(LCDORIENTATION, config.getOrientation());
updateChannelSwitchState(LCDFORCED, config.isOrientationForced());
} catch (FreeboxException e) {