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

@@ -218,7 +218,7 @@ public class Forecast {
// generic getter
public Object getDatapoint(String datapointName) {
if (datapointName.equals("condition")) {
if ("condition".equals(datapointName)) {
return String.valueOf(pictocode);
}

View File

@@ -13,7 +13,6 @@
package org.openhab.binding.meteoblue.internal;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -32,7 +31,7 @@ public class MeteoBlueBindingConstants {
public static final ThingTypeUID THING_TYPE_WEATHER = new ThingTypeUID(BINDING_ID, "weather");
public static final ThingTypeUID THING_TYPE_BRIDGE = new ThingTypeUID(BINDING_ID, "bridge");
public static final Set<ThingTypeUID> BRIDGE_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_BRIDGE);
public static final Set<ThingTypeUID> BRIDGE_THING_TYPES_UIDS = Set.of(THING_TYPE_BRIDGE);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = new HashSet<>(Arrays.asList(THING_TYPE_WEATHER));
// Bridge configuration settings

View File

@@ -14,7 +14,6 @@ package org.openhab.binding.meteoblue.internal.handler;
import static org.openhab.binding.meteoblue.internal.MeteoBlueBindingConstants.THING_TYPE_BRIDGE;
import java.util.Collections;
import java.util.Set;
import org.openhab.binding.meteoblue.internal.MeteoBlueBridgeConfig;
@@ -36,7 +35,7 @@ import org.slf4j.LoggerFactory;
* @author Chris Carman - Initial contribution
*/
public class MeteoBlueBridgeHandler extends BaseBridgeHandler {
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 final Logger logger = LoggerFactory.getLogger(MeteoBlueBridgeHandler.class);
private String apiKey;

View File

@@ -230,9 +230,8 @@ public class MeteoBlueHandler extends BaseThingHandler {
// Build a State from this value
State state = null;
if (datapoint instanceof Calendar) {
state = new DateTimeType(
ZonedDateTime.ofInstant(((Calendar) datapoint).toInstant(), ZoneId.systemDefault()));
if (datapoint instanceof Calendar calendar) {
state = new DateTimeType(ZonedDateTime.ofInstant(calendar.toInstant(), ZoneId.systemDefault()));
} else if (datapoint instanceof Integer) {
state = getStateForType(channel.getAcceptedItemType(), (Integer) datapoint);
} else if (datapoint instanceof Number) {
@@ -240,9 +239,9 @@ public class MeteoBlueHandler extends BaseThingHandler {
state = getStateForType(channel.getAcceptedItemType(), decimalValue);
} else if (datapoint instanceof String) {
state = new StringType(datapoint.toString());
} else if (datapoint instanceof BufferedImage) {
} else if (datapoint instanceof BufferedImage image) {
ImageItem item = new ImageItem("rain area");
state = new RawType(renderImage((BufferedImage) datapoint), "image/png");
state = new RawType(renderImage(image), "image/png");
item.setState(state);
} else {
logger.debug("Unsupported value type {}", datapoint.getClass().getSimpleName());
@@ -263,13 +262,13 @@ public class MeteoBlueHandler extends BaseThingHandler {
private State getStateForType(String type, BigDecimal value) {
State state = new DecimalType(value);
if (type.equals("Number:Temperature")) {
if ("Number:Temperature".equals(type)) {
state = new QuantityType<>(value, SIUnits.CELSIUS);
} else if (type.equals("Number:Length")) {
} else if ("Number:Length".equals(type)) {
state = new QuantityType<>(value, MILLI(SIUnits.METRE));
} else if (type.equals("Number:Pressure")) {
} else if ("Number:Pressure".equals(type)) {
state = new QuantityType<>(value, HECTO(SIUnits.PASCAL));
} else if (type.equals("Number:Speed")) {
} else if ("Number:Speed".equals(type)) {
state = new QuantityType<>(value, Units.METRE_PER_SECOND);
}
@@ -335,9 +334,9 @@ public class MeteoBlueHandler extends BaseThingHandler {
String errorMessage = jsonResult.getErrorMessage();
if (errorMessage != null) {
if (errorMessage.equals("MB_REQUEST::DISPATCH: Invalid api key")) {
if ("MB_REQUEST::DISPATCH: Invalid api key".equals(errorMessage)) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Invalid API Key");
} else if (errorMessage.equals("MB_REQUEST::DISPATCH: This datafeed is not authorized for your api key")) {
} else if ("MB_REQUEST::DISPATCH: This datafeed is not authorized for your api key".equals(errorMessage)) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"API Key not authorized for this datafeed");
} else {