[persistence] Use Java 17 features (#15486)
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
@@ -70,16 +70,16 @@ public class InfluxDBStateConvertUtils {
|
||||
value = state.toString();
|
||||
} else if (state instanceof PointType) {
|
||||
value = state.toString();
|
||||
} else if (state instanceof DecimalType) {
|
||||
value = ((DecimalType) state).toBigDecimal();
|
||||
} else if (state instanceof QuantityType<?>) {
|
||||
value = ((QuantityType<?>) state).toBigDecimal();
|
||||
} else if (state instanceof DecimalType type) {
|
||||
value = type.toBigDecimal();
|
||||
} else if (state instanceof QuantityType<?> type) {
|
||||
value = type.toBigDecimal();
|
||||
} else if (state instanceof OnOffType) {
|
||||
value = state == OnOffType.ON ? DIGITAL_VALUE_ON : DIGITAL_VALUE_OFF;
|
||||
} else if (state instanceof OpenClosedType) {
|
||||
value = state == OpenClosedType.OPEN ? DIGITAL_VALUE_ON : DIGITAL_VALUE_OFF;
|
||||
} else if (state instanceof DateTimeType) {
|
||||
value = ((DateTimeType) state).getZonedDateTime().toInstant().toEpochMilli();
|
||||
} else if (state instanceof DateTimeType type) {
|
||||
value = type.getZonedDateTime().toInstant().toEpochMilli();
|
||||
} else {
|
||||
value = state.toString();
|
||||
}
|
||||
@@ -111,8 +111,8 @@ public class InfluxDBStateConvertUtils {
|
||||
|
||||
@Nullable
|
||||
Item item = itemToSetState;
|
||||
if (item instanceof GroupItem) {
|
||||
item = ((GroupItem) item).getBaseItem();
|
||||
if (item instanceof GroupItem groupItem) {
|
||||
item = groupItem.getBaseItem();
|
||||
}
|
||||
if (item instanceof ColorItem) {
|
||||
return new HSBType(valueStr);
|
||||
@@ -143,8 +143,8 @@ public class InfluxDBStateConvertUtils {
|
||||
}
|
||||
|
||||
private static boolean toBoolean(@Nullable Object object) {
|
||||
if (object instanceof Boolean) {
|
||||
return (Boolean) object;
|
||||
if (object instanceof Boolean boolean1) {
|
||||
return boolean1;
|
||||
} else if (object != null) {
|
||||
if ("1".equals(object) || "1.0".equals(object)) {
|
||||
return true;
|
||||
|
||||
@@ -148,12 +148,12 @@ public class InfluxDB1RepositoryImpl implements InfluxDBRepository {
|
||||
Point.Builder clientPoint = Point.measurement(point.getMeasurementName()).time(point.getTime().toEpochMilli(),
|
||||
TimeUnit.MILLISECONDS);
|
||||
Object value = point.getValue();
|
||||
if (value instanceof String) {
|
||||
clientPoint.addField(FIELD_VALUE_NAME, (String) value);
|
||||
} else if (value instanceof Number) {
|
||||
clientPoint.addField(FIELD_VALUE_NAME, (Number) value);
|
||||
} else if (value instanceof Boolean) {
|
||||
clientPoint.addField(FIELD_VALUE_NAME, (Boolean) value);
|
||||
if (value instanceof String string) {
|
||||
clientPoint.addField(FIELD_VALUE_NAME, string);
|
||||
} else if (value instanceof Number number) {
|
||||
clientPoint.addField(FIELD_VALUE_NAME, number);
|
||||
} else if (value instanceof Boolean boolean1) {
|
||||
clientPoint.addField(FIELD_VALUE_NAME, boolean1);
|
||||
} else if (value == null) {
|
||||
clientPoint.addField(FIELD_VALUE_NAME, "null");
|
||||
} else {
|
||||
|
||||
@@ -186,12 +186,12 @@ public class InfluxDB2RepositoryImpl implements InfluxDBRepository {
|
||||
Point clientPoint = Point.measurement(point.getMeasurementName()).time(point.getTime(), WritePrecision.MS);
|
||||
@Nullable
|
||||
Object value = point.getValue();
|
||||
if (value instanceof String) {
|
||||
clientPoint.addField(FIELD_VALUE_NAME, (String) value);
|
||||
} else if (value instanceof Number) {
|
||||
clientPoint.addField(FIELD_VALUE_NAME, (Number) value);
|
||||
} else if (value instanceof Boolean) {
|
||||
clientPoint.addField(FIELD_VALUE_NAME, (Boolean) value);
|
||||
if (value instanceof String string) {
|
||||
clientPoint.addField(FIELD_VALUE_NAME, string);
|
||||
} else if (value instanceof Number number) {
|
||||
clientPoint.addField(FIELD_VALUE_NAME, number);
|
||||
} else if (value instanceof Boolean boolean1) {
|
||||
clientPoint.addField(FIELD_VALUE_NAME, boolean1);
|
||||
} else if (value == null) {
|
||||
clientPoint.addField(FIELD_VALUE_NAME, (String) null);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user