mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
Code cleanup: Use Java 17 features (#3585)
* Code cleanup: Use Java 17 features Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
+1
-1
@@ -71,7 +71,7 @@ public class AutomationCommandList extends AutomationCommand {
|
||||
*/
|
||||
@Override
|
||||
public String execute() {
|
||||
if (parsingResult != SUCCESS) {
|
||||
if (!parsingResult.equals(SUCCESS)) {
|
||||
return parsingResult;
|
||||
}
|
||||
if (providerType == AutomationCommands.MODULE_TYPE_PROVIDER) {
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ import org.slf4j.LoggerFactory;
|
||||
@NonNullByDefault
|
||||
public abstract class AbstractAuthPageServlet extends HttpServlet {
|
||||
|
||||
protected static final long serialVersionUID = 5340598701104679840L;
|
||||
private static final long serialVersionUID = 5340598701104679840L;
|
||||
|
||||
private static final String MESSAGES_BUNDLE_NAME = "messages";
|
||||
|
||||
|
||||
+1
-1
@@ -319,7 +319,7 @@ public class HttpUtil {
|
||||
if (host.contains("*")) {
|
||||
// the nonProxyHots-pattern allows wildcards '*' which must
|
||||
// be masked to be used with regular expressions
|
||||
String hostRegexp = host.replaceAll("\\.", "\\\\.");
|
||||
String hostRegexp = host.replace(".", "\\.");
|
||||
hostRegexp = hostRegexp.replaceAll("\\*", ".*");
|
||||
if (givenHost.matches(hostRegexp)) {
|
||||
return false;
|
||||
|
||||
+1
-2
@@ -113,8 +113,7 @@ public class BitArray implements Iterable<Boolean> {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("BitArray(bits=").append(length == 0 ? "<empty>" : toBinaryString()).append(")")
|
||||
.toString();
|
||||
return "BitArray(bits=" + (length == 0 ? "<empty>" : toBinaryString()) + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-2
@@ -94,8 +94,7 @@ public class ModbusRegisterArray {
|
||||
if (bytes.length == 0) {
|
||||
return "ModbusRegisterArray(<empty>)";
|
||||
}
|
||||
return new StringBuilder(bytes.length).append("ModbusRegisterArray(").append(toHexString()).append(')')
|
||||
.toString();
|
||||
return "ModbusRegisterArray(" + toHexString() + ')';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+8
-8
@@ -249,7 +249,7 @@ public class GenericItemProvider extends AbstractProvider<Item>
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (item instanceof ActiveItem) {
|
||||
if (item instanceof ActiveItem activeItem) {
|
||||
String label = modelItem.getLabel();
|
||||
String format = extractFormat(label);
|
||||
if (format != null) {
|
||||
@@ -257,9 +257,9 @@ public class GenericItemProvider extends AbstractProvider<Item>
|
||||
stateDescriptionFragments.put(modelItem.getName(),
|
||||
StateDescriptionFragmentBuilder.create().withPattern(format).build());
|
||||
}
|
||||
((ActiveItem) item).setLabel(label);
|
||||
((ActiveItem) item).setCategory(modelItem.getIcon());
|
||||
assignTags(modelItem, (ActiveItem) item);
|
||||
activeItem.setLabel(label);
|
||||
activeItem.setCategory(modelItem.getIcon());
|
||||
assignTags(modelItem, activeItem);
|
||||
return item;
|
||||
} else {
|
||||
return null;
|
||||
@@ -444,11 +444,11 @@ public class GenericItemProvider extends AbstractProvider<Item>
|
||||
GroupItem gItem1 = null;
|
||||
GroupItem gItem2 = null;
|
||||
|
||||
if (item1 instanceof GroupItem) {
|
||||
gItem1 = (GroupItem) item1;
|
||||
if (item1 instanceof GroupItem item) {
|
||||
gItem1 = item;
|
||||
}
|
||||
if (item2 instanceof GroupItem) {
|
||||
gItem2 = (GroupItem) item2;
|
||||
if (item2 instanceof GroupItem item) {
|
||||
gItem2 = item;
|
||||
}
|
||||
|
||||
if (gItem1 == null && gItem2 == null) {
|
||||
|
||||
+1
-2
@@ -200,8 +200,7 @@ public class BusEvent {
|
||||
Map<Item, State> statesMap = new HashMap<>();
|
||||
if (items != null) {
|
||||
for (Item item : items) {
|
||||
if (item instanceof GroupItem) {
|
||||
GroupItem groupItem = (GroupItem) item;
|
||||
if (item instanceof GroupItem groupItem) {
|
||||
for (Item member : groupItem.getAllMembers()) {
|
||||
statesMap.put(member, member.getState());
|
||||
}
|
||||
|
||||
+2
-4
@@ -38,11 +38,9 @@ public class ScriptParsingException extends ScriptException {
|
||||
|
||||
public ScriptParsingException addDiagnosticErrors(List<Diagnostic> errors) {
|
||||
for (Diagnostic emfDiagnosticError : errors) {
|
||||
if (emfDiagnosticError instanceof AbstractDiagnostic) {
|
||||
AbstractDiagnostic e = (AbstractDiagnostic) emfDiagnosticError;
|
||||
if (emfDiagnosticError instanceof AbstractDiagnostic e) {
|
||||
this.getErrors().add(new ScriptError(e.getMessage(), e.getLine(), e.getOffset(), e.getLength()));
|
||||
} else if (emfDiagnosticError instanceof ExceptionDiagnostic) {
|
||||
ExceptionDiagnostic e = (ExceptionDiagnostic) emfDiagnosticError;
|
||||
} else if (emfDiagnosticError instanceof ExceptionDiagnostic e) {
|
||||
this.getErrors().add(new ScriptError(e.getMessage(), e.getLine(), e.getOffset(), e.getLength()));
|
||||
} else {
|
||||
this.getErrors().add(new ScriptError(emfDiagnosticError.getMessage(), -1, -1, -1));
|
||||
|
||||
+24
-24
@@ -175,22 +175,22 @@ public class NumberExtensions {
|
||||
// Comparison operators between types and numbers
|
||||
|
||||
public static boolean operator_equals(Type type, Number x) {
|
||||
if (type instanceof QuantityType && x instanceof QuantityType) {
|
||||
return operator_equals((QuantityType<?>) type, (QuantityType<?>) x);
|
||||
if (type instanceof QuantityType qtype && x instanceof QuantityType qx) {
|
||||
return operator_equals(qtype, qx);
|
||||
}
|
||||
if (type != null && type instanceof DecimalType && x != null) {
|
||||
return ((DecimalType) type).toBigDecimal().compareTo(numberToBigDecimal(x)) == 0;
|
||||
if (type != null && type instanceof DecimalType decimalType && x != null) {
|
||||
return decimalType.toBigDecimal().compareTo(numberToBigDecimal(x)) == 0;
|
||||
} else {
|
||||
return type == x; // both might be null, then we should return true
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean operator_notEquals(Type type, Number x) {
|
||||
if (type instanceof QuantityType && x instanceof QuantityType) {
|
||||
return operator_notEquals((QuantityType<?>) type, (QuantityType<?>) x);
|
||||
if (type instanceof QuantityType qtype && x instanceof QuantityType qx) {
|
||||
return operator_notEquals(qtype, qx);
|
||||
}
|
||||
if (type != null && type instanceof DecimalType && x != null) {
|
||||
return ((DecimalType) type).toBigDecimal().compareTo(numberToBigDecimal(x)) != 0;
|
||||
if (type != null && type instanceof DecimalType decimalType && x != null) {
|
||||
return decimalType.toBigDecimal().compareTo(numberToBigDecimal(x)) != 0;
|
||||
} else {
|
||||
return type != x; // both might be null, then we should return
|
||||
// false, otherwise true
|
||||
@@ -198,44 +198,44 @@ public class NumberExtensions {
|
||||
}
|
||||
|
||||
public static boolean operator_greaterThan(Type type, Number x) {
|
||||
if (type instanceof QuantityType && x instanceof QuantityType) {
|
||||
return operator_greaterThan((QuantityType<?>) type, (QuantityType<?>) x);
|
||||
if (type instanceof QuantityType qtype && x instanceof QuantityType qx) {
|
||||
return operator_greaterThan(qtype, qx);
|
||||
}
|
||||
if (type != null && type instanceof DecimalType && x != null) {
|
||||
return ((DecimalType) type).toBigDecimal().compareTo(numberToBigDecimal(x)) > 0;
|
||||
if (type != null && type instanceof DecimalType decimalType && x != null) {
|
||||
return decimalType.toBigDecimal().compareTo(numberToBigDecimal(x)) > 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean operator_greaterEqualsThan(Type type, Number x) {
|
||||
if (type instanceof QuantityType && x instanceof QuantityType) {
|
||||
return operator_greaterEqualsThan((QuantityType<?>) type, (QuantityType<?>) x);
|
||||
if (type instanceof QuantityType qtype && x instanceof QuantityType qx) {
|
||||
return operator_greaterEqualsThan(qtype, qx);
|
||||
}
|
||||
if (type != null && type instanceof DecimalType && x != null) {
|
||||
return ((DecimalType) type).toBigDecimal().compareTo(numberToBigDecimal(x)) >= 0;
|
||||
if (type != null && type instanceof DecimalType decimalType && x != null) {
|
||||
return decimalType.toBigDecimal().compareTo(numberToBigDecimal(x)) >= 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean operator_lessThan(Type type, Number x) {
|
||||
if (type instanceof QuantityType && x instanceof QuantityType) {
|
||||
return operator_lessThan((QuantityType<?>) type, (QuantityType<?>) x);
|
||||
if (type instanceof QuantityType qtype && x instanceof QuantityType qx) {
|
||||
return operator_lessThan(qtype, qx);
|
||||
}
|
||||
if (type != null && type instanceof DecimalType && x != null) {
|
||||
return ((DecimalType) type).toBigDecimal().compareTo(numberToBigDecimal(x)) < 0;
|
||||
if (type != null && type instanceof DecimalType decimalType && x != null) {
|
||||
return decimalType.toBigDecimal().compareTo(numberToBigDecimal(x)) < 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean operator_lessEqualsThan(Type type, Number x) {
|
||||
if (type instanceof QuantityType && x instanceof QuantityType) {
|
||||
return operator_lessEqualsThan((QuantityType<?>) type, (QuantityType<?>) x);
|
||||
if (type instanceof QuantityType qtype && x instanceof QuantityType qx) {
|
||||
return operator_lessEqualsThan(qtype, qx);
|
||||
}
|
||||
if (type != null && type instanceof DecimalType && x != null) {
|
||||
return ((DecimalType) type).toBigDecimal().compareTo(numberToBigDecimal(x)) <= 0;
|
||||
if (type != null && type instanceof DecimalType decimalType && x != null) {
|
||||
return decimalType.toBigDecimal().compareTo(numberToBigDecimal(x)) <= 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
+1
@@ -63,6 +63,7 @@ public class ManagedThingProvider extends AbstractManagedProvider<Thing, ThingUI
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ThingStorageEntity toPersistableElement(Thing element) {
|
||||
return new ThingStorageEntity(ThingDTOMapper.map(element), element instanceof BridgeImpl);
|
||||
}
|
||||
|
||||
+2
@@ -27,6 +27,8 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@NonNullByDefault
|
||||
public class ThingDescriptionList extends ArrayList {
|
||||
|
||||
private static final long serialVersionUID = -1579556977347296301L;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public ThingDescriptionList(Collection list) {
|
||||
super(list);
|
||||
|
||||
+1
-3
@@ -117,9 +117,7 @@ public class StartLevelService {
|
||||
|
||||
if (openHABStartLevel >= 10) {
|
||||
for (Integer level : new TreeSet<>(startlevels.keySet())) {
|
||||
if (openHABStartLevel >= level) {
|
||||
continue;
|
||||
} else {
|
||||
if (openHABStartLevel < level) {
|
||||
boolean reached = isStartLevelReached(startlevels.get(level));
|
||||
if (reached) {
|
||||
setStartLevel(level);
|
||||
|
||||
Reference in New Issue
Block a user