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

@@ -139,7 +139,7 @@ public class HttpAuthenticationFeature implements Feature {
/**
* Feature authentication mode.
*/
static enum Mode {
enum Mode {
/**
* Basic preemptive.
**/

View File

@@ -305,13 +305,13 @@ class HttpAuthenticationFilter implements ClientRequestFilter, ClientResponseFil
}
String userName = (String) request.getProperty(usernameKey);
if (userName != null && !userName.equals("")) {
if (userName != null && !"".equals(userName)) {
byte[] pwdBytes;
Object password = request.getProperty(passwordKey);
if (password instanceof byte[]) {
pwdBytes = ((byte[]) password);
} else if (password instanceof String) {
pwdBytes = ((String) password).getBytes(CHARACTER_SET);
if (password instanceof byte[] bytes) {
pwdBytes = bytes;
} else if (password instanceof String stringValue) {
pwdBytes = stringValue.getBytes(CHARACTER_SET);
} else {
throw new RequestAuthenticationException("Passwort invalid.");
}

View File

@@ -15,7 +15,6 @@ package org.openhab.binding.lametrictime.internal.discovery;
import static org.openhab.binding.lametrictime.internal.LaMetricTimeBindingConstants.THING_TYPE_DEVICE;
import static org.openhab.binding.lametrictime.internal.config.LaMetricTimeConfiguration.HOST;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -46,7 +45,7 @@ public class LaMetricTimeDiscoveryParticipant implements UpnpDiscoveryParticipan
@Override
public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
return Collections.singleton(THING_TYPE_DEVICE);
return Set.of(THING_TYPE_DEVICE);
}
@Override

View File

@@ -214,9 +214,8 @@ public class LaMetricTimeHandler extends ConfigStatusBridgeHandler {
Audio audio = clock.getLocalApi().getAudio();
if (command instanceof RefreshType) {
updateState(channelUID, new PercentType(audio.getVolume()));
} else if (command instanceof PercentType) {
} else if (command instanceof PercentType percentTypeCommand) {
try {
PercentType percentTypeCommand = (PercentType) command;
int volume = percentTypeCommand.intValue();
if (volume >= 0 && volume != audio.getVolume()) {
audio.setVolume(volume);
@@ -256,8 +255,7 @@ public class LaMetricTimeHandler extends ConfigStatusBridgeHandler {
private void updateBluetoothValue(ChannelUID channelUID, Command command, Bluetooth bluetooth) {
try {
if (command instanceof OnOffType && channelUID.getId().equals(CHANNEL_BLUETOOTH_ACTIVE)) {
OnOffType onOffCommand = (OnOffType) command;
if (command instanceof OnOffType onOffCommand && channelUID.getId().equals(CHANNEL_BLUETOOTH_ACTIVE)) {
if (onOffCommand == OnOffType.ON && !bluetooth.isActive()) {
bluetooth.setActive(true);
clock.getLocalApi().updateBluetooth(bluetooth);
@@ -296,8 +294,8 @@ public class LaMetricTimeHandler extends ConfigStatusBridgeHandler {
private void updateDisplayValue(ChannelUID channelUID, Command command) {
try {
if (channelUID.getId().equals(CHANNEL_DISPLAY_BRIGHTNESS)) {
if (command instanceof PercentType) {
int brightness = ((PercentType) command).intValue();
if (command instanceof PercentType percentCommand) {
int brightness = percentCommand.intValue();
logger.debug("Set Brightness to {}.", brightness);
Display newDisplay = clock.setBrightness(brightness);
updateState(CHANNEL_DISPLAY_BRIGHTNESS_MODE, new StringType(newDisplay.getBrightnessMode()));

View File

@@ -64,8 +64,8 @@ public class RadioAppHandler extends AbstractLaMetricTimeAppHandler {
}
private void handleControl(final Command command) throws ApplicationActionException {
if (command instanceof PlayPauseType) {
switch ((PlayPauseType) command) {
if (command instanceof PlayPauseType playCommand) {
switch (playCommand) {
case PLAY:
play();
return;
@@ -78,8 +78,8 @@ public class RadioAppHandler extends AbstractLaMetricTimeAppHandler {
}
}
if (command instanceof NextPreviousType) {
switch ((NextPreviousType) command) {
if (command instanceof NextPreviousType nextCommand) {
switch (nextCommand) {
case NEXT:
next();
return;