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

@@ -24,7 +24,7 @@ import org.openhab.binding.freeboxos.internal.api.rest.LoginManager;
*/
@NonNullByDefault
public class Response<ResultType> {
public static enum ErrorCode {
public enum ErrorCode {
AUTH_REQUIRED,
BAD_LOGIN,
TOO_SHORT,
@@ -91,7 +91,7 @@ public class Response<ResultType> {
ERR_030,
ERR_031,
NONE,
UNKNOWN;
UNKNOWN
}
private ErrorCode errorCode = ErrorCode.NONE;

View File

@@ -57,10 +57,10 @@ public class APManager extends ListableRest<APManager.WifiAp, APManager.APRespon
}
}
private static enum State {
private enum State {
ASSOCIATED,
AUTHENTICATED,
UNKNOWN;
UNKNOWN
}
public static record Station(String id, MACAddress mac, String bssid, @Nullable String hostname, LanHost host,
@@ -83,7 +83,7 @@ public class APManager extends ListableRest<APManager.WifiAp, APManager.APRespon
protected static record ApStatus(ApState state, int channelWidth, int primaryChannel, int secondaryChannel,
int dfsCacRemainingTime, boolean dfsDisabled) {
private static enum ApState {
private enum ApState {
SCANNING, // Ap is probing wifi channels
NO_PARAM, // Ap is not configured
BAD_PARAM, // Ap has an invalid configuration
@@ -96,7 +96,7 @@ public class APManager extends ListableRest<APManager.WifiAp, APManager.APRespon
DFS, // Ap is performing dynamic frequency selection
ACTIVE, // Ap is active
FAILED, // Ap has failed to start
UNKNOWN;
UNKNOWN
}
}

View File

@@ -33,7 +33,7 @@ public class AfpManager extends ConfigurableRest<AfpManager.Afp, AfpManager.Conf
protected static record Afp(boolean enabled, boolean guestAllow, ServerType serverType, @Nullable String loginName,
@Nullable String loginPassword) {
private static enum ServerType {
private enum ServerType {
POWERBOOK,
POWERMAC,
MACMINI,
@@ -45,7 +45,7 @@ public class AfpManager extends ConfigurableRest<AfpManager.Afp, AfpManager.Conf
APPLETV,
AIRPORT,
XSERVE,
UNKNOWN;
UNKNOWN
}
}

View File

@@ -37,12 +37,12 @@ public class CallManager extends RestManager {
private static class Calls extends Response<Call> {
}
public static enum Type {
public enum Type {
ACCEPTED,
MISSED,
OUTGOING,
INCOMING,
UNKNOWN;
UNKNOWN
}
public static record Call(Type type, //

View File

@@ -35,27 +35,27 @@ public class ConnectionManager extends ConfigurableRest<ConnectionManager.Status
protected static class StatusResponse extends Response<Status> {
}
private static enum State {
private enum State {
GOING_UP,
UP,
GOING_DOWN,
DOWN,
UNKNOWN;
UNKNOWN
}
private static enum Type {
private enum Type {
ETHERNET,
RFC2684,
PPPOATM,
UNKNOWN;
UNKNOWN
}
private static enum Media {
private enum Media {
FTTH,
ETHERNET,
XDSL,
BACKUP_4G,
UNKNOWN;
UNKNOWN
}
public static record Status(State state, Type type, Media media, @Nullable List<Integer> ipv4PortRange,

View File

@@ -52,7 +52,7 @@ public class FreeboxOsSession {
private @Nullable Session session;
private String appToken = "";
public static enum BoxModel {
public enum BoxModel {
FBXGW_R1_FULL, // Freebox Server (v6) revision 1
FBXGW_R2_FULL, // Freebox Server (v6) revision 2
FBXGW_R1_MINI, // Freebox Mini revision 1
@@ -60,7 +60,7 @@ public class FreeboxOsSession {
FBXGW_R1_ONE, // Freebox One revision 1
FBXGW_R2_ONE, // Freebox One revision 2
FBXGW7_R1_FULL, // Freebox v7 revision 1
UNKNOWN;
UNKNOWN
}
public static record ApiVersion(String apiBaseUrl, @Nullable String apiDomain, String apiVersion, BoxModel boxModel,
@@ -156,8 +156,8 @@ public class FreeboxOsSession {
manager = addManager(clazz, managerConstructor.newInstance(this));
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof PermissionException) {
throw (PermissionException) cause;
if (cause instanceof PermissionException exception) {
throw exception;
}
throw new FreeboxException(e, "Unable to call RestManager constructor for %s", clazz.getName());
} catch (ReflectiveOperationException e) {

View File

@@ -36,11 +36,11 @@ public class FreeplugManager extends RestManager {
private static class Networks extends Response<Network> {
}
public static enum NetRole {
public enum NetRole {
STA, // Freeplug station
PCO, // Freeplug proxy coordinator
CCO, // Central Coordinator
UNKNOWN;
UNKNOWN
}
private enum Status {

View File

@@ -42,14 +42,14 @@ public class HomeManager extends RestManager {
private static class HomeNodesResponse extends Response<HomeNode> {
}
private static enum AccessType {
private enum AccessType {
R,
W,
RW,
UNKNOWN;
UNKNOWN
}
private static enum DisplayType {
private enum DisplayType {
TEXT,
ICON,
BUTTON,
@@ -57,7 +57,7 @@ public class HomeManager extends RestManager {
TOGGLE,
COLOR,
WARNING,
UNKNOWN;
UNKNOWN
}
private static record EndpointValue<T> (T value) {
@@ -66,13 +66,13 @@ public class HomeManager extends RestManager {
private static record EndpointUi(AccessType access, DisplayType display, String iconUrl, @Nullable String unit) {
}
private static enum ValueType {
private enum ValueType {
BOOL,
INT,
FLOAT,
VOID,
STRING,
UNKNOWN;
UNKNOWN
}
public static record EndpointState(@Nullable String value, ValueType valueType, long refresh) {
@@ -91,7 +91,7 @@ public class HomeManager extends RestManager {
}
}
public static enum EpType {
public enum EpType {
SIGNAL,
SLOT,
UNKNOWN;
@@ -106,23 +106,23 @@ public class HomeManager extends RestManager {
public static record Endpoint(int id, String name, String label, EpType epType, Visibility visibility, int refresh,
ValueType valueType, EndpointUi ui, @Nullable String category, Object value, List<LogEntry> history) {
private static enum Visibility {
private enum Visibility {
INTERNAL,
NORMAL,
DASHBOARD,
UNKNOWN;
UNKNOWN
}
}
private static enum Status {
private enum Status {
UNREACHABLE,
DISABLED,
ACTIVE,
UNPAIRED,
UNKNOWN;
UNKNOWN
}
public static enum Category {
public enum Category {
BASIC_SHUTTER,
SHUTTER,
ALARM,

View File

@@ -50,14 +50,14 @@ public class LanBrowserManager extends ListableRest<LanBrowserManager.Interface,
protected static class InterfacesResponse extends Response<Interface> {
}
public static enum Source {
public enum Source {
DHCP,
NETBIOS,
MDNS,
MDNS_SRV,
UPNP,
WSD,
UNKNOWN;
UNKNOWN
}
public record HostName(@Nullable String name, Source source) {
@@ -69,9 +69,9 @@ public class LanBrowserManager extends ListableRest<LanBrowserManager.Interface,
private static record WakeOnLineData(String mac, String password) {
}
private static enum Type {
private enum Type {
MAC_ADDRESS,
UNKNOWN;
UNKNOWN
}
private static record L2Ident(MACAddress id, Type type) {
@@ -80,10 +80,10 @@ public class LanBrowserManager extends ListableRest<LanBrowserManager.Interface,
private static record L3Connectivity(String addr, Af af, boolean active, boolean reachable,
ZonedDateTime lastActivity, ZonedDateTime lastTimeReachable, String model) {
private static enum Af {
private enum Af {
IPV4,
IPV6,
UNKNOWN;
UNKNOWN
}
public IPAddress getIPAddress() {
@@ -97,7 +97,7 @@ public class LanBrowserManager extends ListableRest<LanBrowserManager.Interface,
public static record HostIntf(LanHost host, Interface intf) {
}
private static enum HostType {
private enum HostType {
WORKSTATION,
LAPTOP,
SMARTPHONE,
@@ -120,7 +120,7 @@ public class LanBrowserManager extends ListableRest<LanBrowserManager.Interface,
MULTIMEDIA_DEVICE,
CAR,
OTHER,
UNKNOWN;
UNKNOWN
}
public static record LanHost(String id, @Nullable String primaryName, HostType hostType, boolean primaryNameManual,

View File

@@ -31,10 +31,10 @@ public class LanManager extends ConfigurableRest<LanManager.LanConfig, LanManage
protected static class Config extends Response<LanConfig> {
}
private static enum Mode {
private enum Mode {
ROUTER,
BRIDGE,
UNKNOWN;
UNKNOWN
}
public static record LanConfig(IPAddress ip, String name, String nameDns, String nameMdns, String nameNetbios,

View File

@@ -44,12 +44,12 @@ public class LoginManager extends RestManager {
private static final String AUTHORIZE_ACTION = "authorize";
private static final String LOGOUT = "logout";
private static enum Status {
private enum Status {
PENDING, // the user has not confirmed the autorization request yet
TIMEOUT, // the user did not confirmed the authorization within the given time
GRANTED, // the app_token is valid and can be used to open a session
DENIED, // the user denied the authorization request
UNKNOWN; // the app_token is invalid or has been revoked
UNKNOWN // the app_token is invalid or has been revoked
}
private static record AuthorizationStatus(Status status, boolean loggedIn, String challenge,
@@ -65,7 +65,7 @@ public class LoginManager extends RestManager {
private static class AuthResponse extends Response<Authorization> {
}
public static enum Permission {
public enum Permission {
PARENTAL,
CONTACTS,
EXPLORER,
@@ -81,7 +81,7 @@ public class LoginManager extends RestManager {
VM,
PLAYER,
NONE,
UNKNOWN;
UNKNOWN
}
public static record Session(Map<LoginManager.Permission, @Nullable Boolean> permissions,

View File

@@ -40,18 +40,18 @@ public class MediaReceiverManager extends ListableRest<Receiver, MediaReceiverMa
protected static class ReceiverResponse extends Response<Receiver> {
}
public static enum Action {
public enum Action {
START,
STOP,
UNKNOWN;
UNKNOWN
}
public static enum MediaType {
public enum MediaType {
VIDEO,
PHOTO,
AUDIO,
SCREEN,
UNKNOWN;
UNKNOWN
}
private static record Request(String password, Action action, MediaType mediaType, @Nullable String media,

View File

@@ -37,9 +37,9 @@ public class PhoneManager extends ConfigurableRest<PhoneManager.Config, PhoneMan
protected class StatusResponse extends Response<Status> {
}
private static enum NetworkStatus {
private enum NetworkStatus {
WORKING,
UNKNOWN;
UNKNOWN
}
public static record Config(NetworkStatus network, boolean dectEcoMode, String dectPin, int dectRingPattern,
@@ -49,7 +49,7 @@ public class PhoneManager extends ConfigurableRest<PhoneManager.Config, PhoneMan
public enum Type {
FXS,
DECT,
UNKNOWN;
UNKNOWN
}
public static record Status(int id, boolean isRinging, boolean onHook, boolean hardwareDefect, Type type,

View File

@@ -48,7 +48,7 @@ public class PlayerManager extends ListableRest<PlayerManager.Player, PlayerMana
protected static class PlayerResponse extends Response<Player> {
}
public static enum DeviceModel {
public enum DeviceModel {
FBX7HD_DELTA, // Freebox Player Devialet
TBX8AM, // Player Pop
FBX6HD,
@@ -57,18 +57,18 @@ public class PlayerManager extends ListableRest<PlayerManager.Player, PlayerMana
FBX7HD,
FBX7HD_ONE,
FBX8AM,
UNKNOWN;
UNKNOWN
}
public static record Player(MACAddress mac, StbType stbType, int id, ZonedDateTime lastTimeReachable,
boolean apiAvailable, String deviceName, DeviceModel deviceModel, boolean reachable, String uid,
@Nullable String apiVersion, List<String> lanGids) {
private static enum StbType {
private enum StbType {
STB_ANDROID,
STB_V6,
STB_V7,
STB_V8,
UNKNOWN;
UNKNOWN
}
/**
@@ -83,10 +83,10 @@ public class PlayerManager extends ListableRest<PlayerManager.Player, PlayerMana
private static class StatusResponse extends Response<Status> {
}
public static enum PowerState {
public enum PowerState {
STANDBY,
RUNNING,
UNKNOWN;
UNKNOWN
}
public static record Status(PowerState powerState, StatusInformation player,
@@ -113,7 +113,7 @@ public class PlayerManager extends ListableRest<PlayerManager.Player, PlayerMana
private enum MediaState {
READY,
UNKNOWN;
UNKNOWN
}
private static record AudioTrack(int bitrate, @SerializedName("channelCount") int channelCount,
@@ -121,10 +121,10 @@ public class PlayerManager extends ListableRest<PlayerManager.Player, PlayerMana
@SerializedName("metadataId") @Nullable String metadataId, int pid, int samplerate, long uid) {
}
private static enum Type {
private enum Type {
NORMAL,
HEARINGIMPAIRED,
UNKNOWN;
UNKNOWN
}
protected static record Metadata(@Nullable String album,
@@ -137,10 +137,10 @@ public class PlayerManager extends ListableRest<PlayerManager.Player, PlayerMana
@Nullable String title, @SerializedName("trackNumber") int trackNumber,
@SerializedName("trackTotal") int trackTotal, @Nullable String url) {
protected static enum PlaybackState {
protected enum PlaybackState {
PLAY,
PAUSE,
UNKNOWN;
UNKNOWN
}
protected static record SubtitleTrack(@Nullable String codec, @Nullable String language, @Nullable String pid,
@@ -164,14 +164,14 @@ public class PlayerManager extends ListableRest<PlayerManager.Player, PlayerMana
}
}
private static enum BouquetType {
private enum BouquetType {
ADSL,
UNKNOWN;
UNKNOWN
}
private static enum ChannelType {
private enum ChannelType {
REGULAR,
UNKNOWN;
UNKNOWN
}
private static record Service(long id, @Nullable String name,

View File

@@ -45,25 +45,25 @@ public class RepeaterManager extends ListableRest<RepeaterManager.Repeater, Repe
public static record RepeaterLed(int id, boolean ledActivated) {
}
private static enum Connection {
private enum Connection {
CONNECTED,
DISCONNECTED,
UNKNOWN;
UNKNOWN
}
private static enum Status {
private enum Status {
STARTING,
RUNNING,
REBOOTING,
UPDATING,
REBOOT_FAILURE,
UPDATE_FAILURE,
UNKNOWN;
UNKNOWN
}
public static enum Model {
public enum Model {
FBXWMR, // Répéteur Wifi
UNKNOWN;
UNKNOWN
}
public static record Repeater(int id, boolean ledActivated, boolean enabled, MACAddress mainMac,

View File

@@ -36,7 +36,7 @@ public class SystemManager extends ConfigurableRest<SystemManager.Config, System
public enum SensorKind {
FAN,
TEMP,
UNKNOWN;
UNKNOWN
}
public SensorKind getKind() {
@@ -54,13 +54,13 @@ public class SystemManager extends ConfigurableRest<SystemManager.Config, System
private static record Expansion(int slot, boolean probeDone, boolean present, boolean supported, String bundle,
Type type) {
private static enum Type {
private enum Type {
UNKNOWN, // unknown module
DSL_LTE, // xDSL + LTE
DSL_LTE_EXTERNAL_ANTENNAS, // xDSL + LTE with external antennas switch
FTTH_P2P, // FTTH P2P
FTTH_PON, // FTTH PON
SECURITY; // Security module
SECURITY // Security module
}
}
@@ -72,13 +72,13 @@ public class SystemManager extends ConfigurableRest<SystemManager.Config, System
public static record Config(String firmwareVersion, MACAddress mac, String serial, String uptime, long uptimeVal,
String boardName, boolean boxAuthenticated, DiskStatus diskStatus, String userMainStorage,
List<Sensor> sensors, ModelInfo modelInfo, List<Sensor> fans, List<Expansion> expansions) {
private static enum DiskStatus {
private enum DiskStatus {
NOT_DETECTED,
DISABLED,
INITIALIZING,
ERROR,
ACTIVE,
UNKNOWN;
UNKNOWN
}
}

View File

@@ -31,10 +31,10 @@ public class VmManager extends ListableRest<VmManager.VirtualMachine, VmManager.
protected class VirtualMachineResponse extends Response<VirtualMachine> {
}
public static enum Status {
public enum Status {
STOPPED,
RUNNING,
UNKNOWN;
UNKNOWN
}
public static record VirtualMachine(int id, String name, MACAddress mac, Status status) {

View File

@@ -63,8 +63,8 @@ public class FreeboxOsCommandExtension extends AbstractConsoleCommandExtension {
FreeboxOsHandler handler = null;
if (thing != null) {
thingHandler = thing.getHandler();
if (thingHandler instanceof FreeboxOsHandler) {
handler = (FreeboxOsHandler) thingHandler;
if (thingHandler instanceof FreeboxOsHandler osHandler) {
handler = osHandler;
}
}
if (thing == null) {

View File

@@ -15,7 +15,7 @@ package org.openhab.binding.freeboxos.internal.handler;
import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -93,7 +93,7 @@ public class ActivePlayerHandler extends PlayerHandler implements FreeDeviceIntf
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singletonList(ActivePlayerActions.class);
return List.of(ActivePlayerActions.class);
}
@Override

View File

@@ -17,10 +17,10 @@ import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.freeboxos.internal.action.CallActions;
@@ -103,6 +103,6 @@ public class CallHandler extends ApiConsumerHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(CallActions.class);
return Set.of(CallActions.class);
}
}

View File

@@ -66,15 +66,14 @@ public class DectHandler extends FxsHandler {
return true;
}
}
if (command instanceof PercentType) {
PercentType percent = (PercentType) command;
if (command instanceof PercentType percentCommand) {
if (GAIN_RX.equals(channelId)) {
phoneManager.setGainRx(getClientId(), percent.intValue());
updateIfActive(GAIN_RX, percent);
phoneManager.setGainRx(getClientId(), percentCommand.intValue());
updateIfActive(GAIN_RX, percentCommand);
return true;
} else if (GAIN_TX.equals(channelId)) {
phoneManager.setGainTx(getClientId(), percent.intValue());
updateIfActive(GAIN_RX, percent);
phoneManager.setGainTx(getClientId(), percentCommand.intValue());
updateIfActive(GAIN_RX, percentCommand);
return true;
}
}

View File

@@ -13,8 +13,8 @@
package org.openhab.binding.freeboxos.internal.handler;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@@ -126,7 +126,7 @@ public class FreeboxOsHandler extends BaseBridgeHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(FreeboxOsDiscoveryService.class);
return Set.of(FreeboxOsDiscoveryService.class);
}
@Override

View File

@@ -54,8 +54,8 @@ public class FreeplugHandler extends ApiConsumerHandler {
properties.put(ROLE, plug.netRole().name());
properties.put(NET_ID, plug.netId());
properties.put(ETHERNET_SPEED, "%d Mb/s".formatted(plug.ethSpeed()));
properties.put(LOCAL, Boolean.valueOf(plug.local()).toString());
properties.put(FULL_DUPLEX, Boolean.valueOf(plug.ethFullDuplex()).toString());
properties.put(LOCAL, Boolean.toString(plug.local()));
properties.put(FULL_DUPLEX, Boolean.toString(plug.ethFullDuplex()));
if (plug.local()) { // Plug connected to the freebox does not provide rate up or down
List<Channel> channels = new ArrayList<>(getThing().getChannels());

View File

@@ -16,7 +16,6 @@ import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.K
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -109,6 +108,6 @@ public class PlayerHandler extends HostHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singletonList(PlayerActions.class);
return List.of(PlayerActions.class);
}
}

View File

@@ -15,9 +15,9 @@ package org.openhab.binding.freeboxos.internal.handler;
import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.freeboxos.internal.action.RepeaterActions;
@@ -104,7 +104,7 @@ public class RepeaterHandler extends HostHandler implements FreeDeviceIntf {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(RepeaterActions.class);
return Set.of(RepeaterActions.class);
}
@Override

View File

@@ -73,8 +73,8 @@ public class RevolutionHandler extends ServerHandler {
}
private void setOrientation(LcdManager manager, Config config, Command command) throws FreeboxException {
if (command instanceof DecimalType) {
manager.setOrientation(((DecimalType) command).intValue());
if (command instanceof DecimalType orientation) {
manager.setOrientation(orientation.intValue());
} else {
logger.warn("Invalid command {} from channel {}", command, LCD_ORIENTATION);
}
@@ -93,8 +93,8 @@ public class RevolutionHandler extends ServerHandler {
manager.setBrightness(() -> config.brightness() + (command == IncreaseDecreaseType.INCREASE ? 1 : -1));
} else if (command instanceof OnOffType) {
manager.setBrightness(() -> command == OnOffType.ON ? 100 : 0);
} else if (command instanceof QuantityType) {
manager.setBrightness(() -> ((QuantityType<?>) command).intValue());
} else if (command instanceof QuantityType brightness) {
manager.setBrightness(() -> brightness.intValue());
} else if (command instanceof DecimalType || command instanceof PercentType) {
manager.setBrightness(() -> ((DecimalType) command).intValue());
} else {

View File

@@ -18,9 +18,9 @@ import static org.openhab.core.library.unit.Units.*;
import java.math.BigDecimal;
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 org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.freeboxos.internal.action.ServerActions;
@@ -200,7 +200,7 @@ public class ServerHandler extends ApiConsumerHandler implements FreeDeviceIntf
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(ServerActions.class);
return Set.of(ServerActions.class);
}
@Override