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:
@@ -299,8 +299,8 @@ public abstract class CommandHandler {
|
||||
@Override
|
||||
public void handleCommand(InsteonChannelConfiguration conf, Command cmd, InsteonDevice dev) {
|
||||
try {
|
||||
if (cmd instanceof DecimalType) {
|
||||
int v = ((DecimalType) cmd).intValue();
|
||||
if (cmd instanceof DecimalType decimalCommand) {
|
||||
int v = decimalCommand.intValue();
|
||||
int cmd1 = (v != 1) ? 0x17 : 0x18; // start or stop
|
||||
int cmd2 = (v == 2) ? 0x01 : 0; // up or down
|
||||
Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) cmd1, (byte) cmd2, getGroup(conf));
|
||||
|
||||
@@ -64,7 +64,7 @@ import org.slf4j.LoggerFactory;
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class DeviceFeature {
|
||||
public static enum QueryStatus {
|
||||
public enum QueryStatus {
|
||||
NEVER_QUERIED,
|
||||
QUERY_PENDING,
|
||||
QUERY_ANSWERED
|
||||
@@ -300,8 +300,7 @@ public class DeviceFeature {
|
||||
}
|
||||
logger.trace("{} making poll msg for {} using handler {}", getName(), getDevice().getAddress(),
|
||||
pollHandler.getClass().getSimpleName());
|
||||
Msg m = pollHandler.makeMsg(device);
|
||||
return m;
|
||||
return pollHandler.makeMsg(device);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -90,7 +90,7 @@ public class DeviceTypeLoader {
|
||||
NodeList nodes = root.getChildNodes();
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
Node node = nodes.item(i);
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals("device")) {
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE && "device".equals(node.getNodeName())) {
|
||||
processDevice((Element) node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public class FeatureTemplateLoader {
|
||||
|
||||
private static FeatureTemplate parseFeature(Element e) throws ParsingException {
|
||||
String name = e.getAttribute("name");
|
||||
boolean statusFeature = e.getAttribute("statusFeature").equals("true");
|
||||
boolean statusFeature = "true".equals(e.getAttribute("statusFeature"));
|
||||
FeatureTemplate feature = new FeatureTemplate(name, statusFeature, e.getAttribute("timeout"));
|
||||
|
||||
NodeList nodes = e.getChildNodes();
|
||||
@@ -94,13 +94,13 @@ public class FeatureTemplateLoader {
|
||||
Node node = nodes.item(i);
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element child = (Element) node;
|
||||
if (child.getTagName().equals("message-handler")) {
|
||||
if ("message-handler".equals(child.getTagName())) {
|
||||
parseMessageHandler(child, feature);
|
||||
} else if (child.getTagName().equals("command-handler")) {
|
||||
} else if ("command-handler".equals(child.getTagName())) {
|
||||
parseCommandHandler(child, feature);
|
||||
} else if (child.getTagName().equals("message-dispatcher")) {
|
||||
} else if ("message-dispatcher".equals(child.getTagName())) {
|
||||
parseMessageDispatcher(child, feature);
|
||||
} else if (child.getTagName().equals("poll-handler")) {
|
||||
} else if ("poll-handler".equals(child.getTagName())) {
|
||||
parsePollHandler(child, feature);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public class GroupMessageStateMachine {
|
||||
enum GroupMessage {
|
||||
BCAST,
|
||||
CLEAN,
|
||||
SUCCESS;
|
||||
SUCCESS
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,7 +49,7 @@ import org.slf4j.LoggerFactory;
|
||||
public class InsteonDevice {
|
||||
private final Logger logger = LoggerFactory.getLogger(InsteonDevice.class);
|
||||
|
||||
public static enum DeviceStatus {
|
||||
public enum DeviceStatus {
|
||||
INITIALIZED,
|
||||
POLLING
|
||||
}
|
||||
|
||||
@@ -170,8 +170,8 @@ public abstract class MessageHandler {
|
||||
protected boolean getBooleanDeviceConfig(String key, boolean def) {
|
||||
Object o = feature.getDevice().getDeviceConfigMap().get(key);
|
||||
if (o != null) {
|
||||
if (o instanceof Boolean) {
|
||||
return (Boolean) o;
|
||||
if (o instanceof Boolean booleanValue) {
|
||||
return booleanValue;
|
||||
} else {
|
||||
logger.warn("{} {}: The value for the '{}' key is not boolean in the device configuration parameter.",
|
||||
nm(), feature.getDevice().getAddress(), key);
|
||||
|
||||
@@ -73,8 +73,10 @@ public class ModemDBBuilder implements MsgListener {
|
||||
if (System.currentTimeMillis() - lastMessageTimestamp > MESSAGE_TIMEOUT) {
|
||||
String s = "";
|
||||
if (messageCount == 0) {
|
||||
s = " No messages were received, the PLM or hub might be broken. If this continues see "
|
||||
+ "'Known Limitations and Issues' in the Insteon binding documentation.";
|
||||
s = """
|
||||
No messages were received, the PLM or hub might be broken. If this continues see \
|
||||
'Known Limitations and Issues' in the Insteon binding documentation.\
|
||||
""";
|
||||
}
|
||||
logger.warn("Modem database download was unsuccessful, restarting!{}", s);
|
||||
startDownload();
|
||||
|
||||
@@ -252,7 +252,7 @@ public class InsteonDeviceHandler extends BaseThingHandler {
|
||||
feature = DATA;
|
||||
}
|
||||
} else if (productKey.equals(PLM_PRODUCT_KEY)) {
|
||||
String parts[] = feature.split("#");
|
||||
String[] parts = feature.split("#");
|
||||
if (parts.length == 2 && parts[0].equalsIgnoreCase(InsteonBindingConstants.BROADCAST_ON_OFF)
|
||||
&& parts[1].matches("^\\d+$")) {
|
||||
feature = BROADCAST_ON_OFF;
|
||||
@@ -282,9 +282,9 @@ public class InsteonDeviceHandler extends BaseThingHandler {
|
||||
Object groups = deviceConfigMap.get(BROADCAST_GROUPS);
|
||||
if (groups != null) {
|
||||
boolean valid = false;
|
||||
if (groups instanceof List<?>) {
|
||||
if (groups instanceof List<?> list) {
|
||||
valid = true;
|
||||
for (Object o : (List<?>) groups) {
|
||||
for (Object o : list) {
|
||||
if (o instanceof Double && (Double) o % 1 == 0) {
|
||||
String id = InsteonBindingConstants.BROADCAST_ON_OFF + "#"
|
||||
+ ((Double) o).intValue();
|
||||
@@ -444,10 +444,10 @@ public class InsteonDeviceHandler extends BaseThingHandler {
|
||||
Map<String, Object> channelProperties = channel.getConfiguration().getProperties();
|
||||
for (String key : channelProperties.keySet()) {
|
||||
Object value = channelProperties.get(key);
|
||||
if (value instanceof String) {
|
||||
params.put(key, (String) value);
|
||||
} else if (value instanceof BigDecimal) {
|
||||
String s = ((BigDecimal) value).toPlainString();
|
||||
if (value instanceof String stringValue) {
|
||||
params.put(key, stringValue);
|
||||
} else if (value instanceof BigDecimal decimalValue) {
|
||||
String s = decimalValue.toPlainString();
|
||||
params.put(key, s);
|
||||
} else {
|
||||
logger.warn("not a string or big decimal value key '{}' value '{}' {}", key, value,
|
||||
@@ -493,7 +493,7 @@ public class InsteonDeviceHandler extends BaseThingHandler {
|
||||
feature = DATA;
|
||||
}
|
||||
} else if (productKey.equals(PLM_PRODUCT_KEY)) {
|
||||
String parts[] = feature.split("#");
|
||||
String[] parts = feature.split("#");
|
||||
if (parts.length == 2 && parts[0].equalsIgnoreCase(InsteonBindingConstants.BROADCAST_ON_OFF)
|
||||
&& parts[1].matches("^\\d+$")) {
|
||||
params.put(GROUP, parts[1]);
|
||||
|
||||
@@ -176,8 +176,7 @@ public final class Field {
|
||||
byte b2 = array[offset + 1];
|
||||
byte b3 = array[offset + 2];
|
||||
byte b4 = array[offset + 3];
|
||||
int value = ((b1 << 24) + (b2 << 16) + (b3 << 8) + (b4 << 0));
|
||||
return value;
|
||||
return ((b1 << 24) + (b2 << 16) + (b3 << 8) + (b4 << 0));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,8 +198,7 @@ public final class Field {
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(@Nullable Object o) {
|
||||
if (o instanceof Field) {
|
||||
Field f = (Field) o;
|
||||
if (o instanceof Field f) {
|
||||
return (f.getName().equals(getName())) && (f.getOffset() == getOffset());
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -73,7 +73,7 @@ public class XMLMessageReader {
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
Node node = nodes.item(i);
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
if (node.getNodeName().equals("msg")) {
|
||||
if ("msg".equals(node.getNodeName())) {
|
||||
Pair<String, Msg> msgDef = readMessageDefinition((Element) node);
|
||||
messageMap.put(msgDef.getKey(), msgDef.getValue());
|
||||
}
|
||||
@@ -106,7 +106,7 @@ public class XMLMessageReader {
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
Node node = nodes.item(i);
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
if (node.getNodeName().equals("header")) {
|
||||
if ("header".equals(node.getNodeName())) {
|
||||
int o = readHeaderElement((Element) node, fieldMap);
|
||||
hlength = o;
|
||||
// Increment the offset by the header length
|
||||
@@ -158,8 +158,7 @@ public class XMLMessageReader {
|
||||
// Now we have field, only need value
|
||||
String sVal = field.getTextContent();
|
||||
Object val = DataTypeParser.parseDataType(dType, sVal);
|
||||
Pair<Field, Object> pair = new Pair<>(f, val);
|
||||
return pair;
|
||||
return new Pair<>(f, val);
|
||||
}
|
||||
|
||||
private static Msg createMsg(HashMap<Field, Object> values, int length, int headerLength, Msg.Direction dir)
|
||||
@@ -173,7 +172,7 @@ public class XMLMessageReader {
|
||||
} else {
|
||||
throw new FieldException("data is null");
|
||||
}
|
||||
if (!f.getName().equals("")) {
|
||||
if (!"".equals(f.getName())) {
|
||||
msg.addField(f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,7 @@ import org.openhab.binding.insteon.internal.message.DataType;
|
||||
@NonNullByDefault
|
||||
public class Utils {
|
||||
public static String getHexString(int b) {
|
||||
String result = String.format("%02X", b & 0xFF);
|
||||
return result;
|
||||
return String.format("%02X", b & 0xFF);
|
||||
}
|
||||
|
||||
public static String getHexString(byte[] b) {
|
||||
@@ -86,7 +85,7 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static byte parseByte(@Nullable String val) {
|
||||
if (val != null && !val.trim().equals("")) {
|
||||
if (val != null && !"".equals(val.trim())) {
|
||||
return (byte) Utils.from0xHexString(val.trim());
|
||||
} else {
|
||||
return 0x00;
|
||||
@@ -94,7 +93,7 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static int parseInt(@Nullable String val) {
|
||||
if (val != null && !val.trim().equals("")) {
|
||||
if (val != null && !"".equals(val.trim())) {
|
||||
return Integer.parseInt(val);
|
||||
} else {
|
||||
return 0x00;
|
||||
@@ -102,7 +101,7 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static float parseFloat(@Nullable String val) {
|
||||
if (val != null && !val.trim().equals("")) {
|
||||
if (val != null && !"".equals(val.trim())) {
|
||||
return Float.parseFloat(val.trim());
|
||||
} else {
|
||||
return 0;
|
||||
@@ -110,7 +109,7 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static InsteonAddress parseAddress(@Nullable String val) {
|
||||
if (val != null && !val.trim().equals("")) {
|
||||
if (val != null && !"".equals(val.trim())) {
|
||||
return InsteonAddress.parseAddress(val.trim());
|
||||
} else {
|
||||
return new InsteonAddress();
|
||||
|
||||
Reference in New Issue
Block a user