Java 17 features (N-S) (#15565)

- 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-13 08:03:31 +02:00
committed by GitHub
parent 641b482551
commit ab58f4ffb4
471 changed files with 1624 additions and 1868 deletions

View File

@@ -14,7 +14,6 @@ package org.openhab.binding.sagercaster.internal;
import static org.openhab.binding.sagercaster.internal.SagerCasterBindingConstants.THING_TYPE_SAGERCASTER;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -39,7 +38,7 @@ import org.osgi.service.component.annotations.Reference;
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.sagercaster")
@NonNullByDefault
public class SagerCasterHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_SAGERCASTER);
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_SAGERCASTER);
private final WindDirectionStateDescriptionProvider stateDescriptionProvider;
private final SagerWeatherCaster sagerWeatherCaster;

View File

@@ -318,8 +318,7 @@ public class SagerWeatherCaster {
d1 = "Z";
}
}
String forecast = forecaster.getProperty(
d1 + String.valueOf(sagerPressure) + String.valueOf(pressureEvolution) + String.valueOf(nubes));
String forecast = forecaster.getProperty(d1 + sagerPressure + pressureEvolution + nubes);
prevision = Optional.ofNullable(forecast != null ? new SagerPrediction(forecast) : null);
}

View File

@@ -114,8 +114,7 @@ public class SagerCasterHandler extends BaseThingHandler {
switch (id) {
case CHANNEL_CLOUDINESS:
logger.debug("Cloud level changed, updating forecast");
if (command instanceof QuantityType) {
QuantityType<?> cloudiness = (QuantityType<?>) command;
if (command instanceof QuantityType cloudiness) {
scheduler.submit(() -> {
sagerWeatherCaster.setCloudLevel(cloudiness.intValue());
postNewForecast();
@@ -124,8 +123,7 @@ public class SagerCasterHandler extends BaseThingHandler {
}
case CHANNEL_IS_RAINING:
logger.debug("Rain status updated, updating forecast");
if (command instanceof OnOffType) {
OnOffType isRaining = (OnOffType) command;
if (command instanceof OnOffType isRaining) {
scheduler.submit(() -> {
sagerWeatherCaster.setRaining(isRaining == OnOffType.ON);
postNewForecast();
@@ -136,18 +134,17 @@ public class SagerCasterHandler extends BaseThingHandler {
break;
case CHANNEL_RAIN_QTTY:
logger.debug("Rain status updated, updating forecast");
if (command instanceof QuantityType) {
updateRain((QuantityType<?>) command);
} else if (command instanceof DecimalType) {
updateRain((DecimalType) command);
if (command instanceof QuantityType quantityCommand) {
updateRain(quantityCommand);
} else if (command instanceof DecimalType decimalCommand) {
updateRain(decimalCommand);
} else {
logger.debug("Channel '{}' accepts Number, Number:(Speed|Length) commands.", channelUID);
}
break;
case CHANNEL_WIND_SPEED:
logger.debug("Updated wind speed, updating forecast");
if (command instanceof DecimalType) {
DecimalType newValue = (DecimalType) command;
if (command instanceof DecimalType newValue) {
scheduler.submit(() -> {
sagerWeatherCaster.setBeaufort(newValue.intValue());
postNewForecast();