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:
@@ -33,7 +33,7 @@ public final class Utils {
|
||||
* the hex value to be parsed into an integer
|
||||
* @return the given hex value as integer
|
||||
*/
|
||||
public static final int fromHex(String hex) {
|
||||
public static int fromHex(String hex) {
|
||||
return Integer.parseInt(hex, 16);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public final class Utils {
|
||||
* the integer values to be converted into hexadecimal numbers
|
||||
* @return the given numbers as hexadecimal number
|
||||
*/
|
||||
public static final String toHex(int... values) {
|
||||
public static String toHex(int... values) {
|
||||
String returnValue = "";
|
||||
for (int v : values) {
|
||||
returnValue += v < 16 ? "0" + Integer.toHexString(v).toUpperCase() : Integer.toHexString(v).toUpperCase();
|
||||
@@ -60,7 +60,7 @@ public final class Utils {
|
||||
* hexadecimal numbers
|
||||
* @return the hexadecimal number
|
||||
*/
|
||||
public static final String toHex(boolean[] bits) {
|
||||
public static String toHex(boolean[] bits) {
|
||||
int retVal = 0;
|
||||
for (int i = 0; i < bits.length; ++i) {
|
||||
retVal |= (bits[i] ? 1 : 0) << i;
|
||||
@@ -76,7 +76,7 @@ public final class Utils {
|
||||
* the byte to be converted into its integer value
|
||||
* @return the integer value represented by the given byte
|
||||
*/
|
||||
public static final int fromByte(byte b) {
|
||||
public static int fromByte(byte b) {
|
||||
return b & 0xFF;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,8 +38,8 @@ public class MaxCubeActions implements ThingActions {
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
if (handler instanceof MaxCubeBridgeHandler) {
|
||||
this.handler = (MaxCubeBridgeHandler) handler;
|
||||
if (handler instanceof MaxCubeBridgeHandler bridgeHandler) {
|
||||
this.handler = bridgeHandler;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,8 +38,8 @@ public class MaxDevicesActions implements ThingActions {
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
if (handler instanceof MaxDevicesHandler) {
|
||||
this.handler = (MaxDevicesHandler) handler;
|
||||
if (handler instanceof MaxDevicesHandler devicesHandler) {
|
||||
this.handler = devicesHandler;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,7 @@ public class CCommand extends CubeCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandString() {
|
||||
String cmd = "c:" + rfAddress + '\r' + '\n';
|
||||
return cmd;
|
||||
return "c:" + rfAddress + '\r' + '\n';
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -127,14 +127,14 @@ public class UdpCubeCommand {
|
||||
|
||||
// Check if the message is correct
|
||||
if (message.startsWith("eQ3Max") && !message.equals(MAXCUBE_COMMAND_STRING)) {
|
||||
commandResponse.put("maxCubeIP", receivePacket.getAddress().getHostAddress().toString());
|
||||
commandResponse.put("maxCubeIP", receivePacket.getAddress().getHostAddress());
|
||||
commandResponse.put("maxCubeState", message.substring(0, 8));
|
||||
commandResponse.put("serialNumber", message.substring(8, 18));
|
||||
commandResponse.put("msgValidid", message.substring(18, 19));
|
||||
String requestType = message.substring(19, 20);
|
||||
commandResponse.put("requestType", requestType);
|
||||
|
||||
if (requestType.equals("I")) {
|
||||
if ("I".equals(requestType)) {
|
||||
commandResponse.put("rfAddress",
|
||||
Utils.getHex(message.substring(21, 24).getBytes(StandardCharsets.UTF_8))
|
||||
.replace(" ", "").toLowerCase());
|
||||
|
||||
@@ -136,7 +136,7 @@ public class MaxCubeBridgeDiscovery extends AbstractDiscoveryService {
|
||||
logger.trace("Msg Valid : {}", msgValidid);
|
||||
logger.trace("Msg Type : {}", requestType);
|
||||
|
||||
if (requestType.equals("I")) {
|
||||
if ("I".equals(requestType)) {
|
||||
rfAddress = Utils.getHex(Arrays.copyOfRange(messageBuf, 21, 24)).replace(" ", "").toLowerCase();
|
||||
String firmwareVersion = Utils.getHex(Arrays.copyOfRange(messageBuf, 24, 26)).replace(" ", ".");
|
||||
logger.debug("RF Address: {}", rfAddress);
|
||||
|
||||
@@ -55,8 +55,8 @@ public class MaxDeviceDiscoveryService extends AbstractDiscoveryService
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@NonNullByDefault({}) ThingHandler handler) {
|
||||
if (handler instanceof MaxCubeBridgeHandler) {
|
||||
this.maxCubeBridgeHandler = (MaxCubeBridgeHandler) handler;
|
||||
if (handler instanceof MaxCubeBridgeHandler maxCubeBridgeHandler) {
|
||||
this.maxCubeBridgeHandler = maxCubeBridgeHandler;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@ import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -198,7 +198,7 @@ public class MaxDevicesHandler extends BaseThingHandler implements DeviceStatusL
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singleton(MaxDevicesActions.class);
|
||||
return Set.of(MaxDevicesActions.class);
|
||||
}
|
||||
|
||||
private void sendPropertyUpdate(Map<String, Object> configurationParameters, Map<String, Object> deviceProperties) {
|
||||
@@ -543,8 +543,8 @@ public class MaxDevicesHandler extends BaseThingHandler implements DeviceStatusL
|
||||
configuration.put(PROPERTY_ROOMNAME, device.getRoomName());
|
||||
config_changed = true;
|
||||
}
|
||||
if (getConfig().get(PROPERTY_ROOMID) == null || !(new BigDecimal(device.getRoomId())
|
||||
.compareTo((BigDecimal) getConfig().get(PROPERTY_ROOMID)) == 0)) {
|
||||
if (getConfig().get(PROPERTY_ROOMID) == null || new BigDecimal(device.getRoomId())
|
||||
.compareTo((BigDecimal) getConfig().get(PROPERTY_ROOMID)) != 0) {
|
||||
configuration.put(PROPERTY_ROOMID, new BigDecimal(device.getRoomId()));
|
||||
config_changed = true;
|
||||
}
|
||||
|
||||
@@ -68,8 +68,7 @@ public final class SendCommand {
|
||||
* This is can be used to find duplicated commands in the queue
|
||||
*/
|
||||
private static String getKey(String serialNumber, CubeCommand cubeCommand) {
|
||||
String key = serialNumber + "-" + cubeCommand.getClass().getSimpleName();
|
||||
return key;
|
||||
return serialNumber + "-" + cubeCommand.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -171,7 +171,7 @@ public class MessageProcessor {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ((!counter.equals(this.numberOfRequiredLines)) || (!(index == this.receivedLines.size()))) {
|
||||
if (!counter.equals(this.numberOfRequiredLines) || index != this.receivedLines.size()) {
|
||||
throw new IncorrectMultilineIndexException();
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public class MCommandTest {
|
||||
private List<Device> devices = new ArrayList<>();
|
||||
private List<RoomInformation> rooms = new ArrayList<>();
|
||||
|
||||
String deviceCMsg[] = {
|
||||
String[] deviceCMsg = {
|
||||
"C:0b0da3,0gsNowIBEABLRVEwNTQ0MjQyLCQ9CQcYAzAM/wBIYViRSP1ZFE0gTSBNIEUgRSBFIEUgRSBFIEhhWJFQ/VkVUSBRIFEgRSBFIEUgRSBFIEUgSFBYWkj+WRRNIE0gTSBFIEUgRSBFIEUgRSBIUFhaSP5ZFE0gTSBNIEUgRSBFIEUgRSBFIEhQWFpI/lkUTSBNIE0gRSBFIEUgRSBFIEUgSFBYWkj+WRRNIE0gTSBFIEUgRSBFIEUgRSBIUFhaSP5ZFE0gTSBNIEUgRSBFIEUgRSBFIA==",
|
||||
"C:08c1d6,0gjB1gEFGP9LRVEwNjQ5MzEyKyE9CQcYAzAM/wBEeFUgVSBVIFUgVSBVIEUgRSBFIEUgRSBFIER4VRZFIEUgRSBFIEUgRSBFIEUgRSBFIEUgRFFEYkTkTQ9FIEUgRSBFIEUgRSBFIEUgRSBEUURiRORND0UgRSBFIEUgRSBFIEUgRSBFIERRRGJE5E0PRSBFIEUgRSBFIEUgRSBFIEUgRFFEYkTkTQ9FIEUgRSBFIEUgRSBFIEUgRSBEUURiRORRGEUgRSBFIEUgRSBFIEUgRSBFIA==",
|
||||
"C:0e75f6,EQ519gQCEABLRVExMTA0Mzgw",
|
||||
|
||||
@@ -93,14 +93,14 @@ public class UtilsTest {
|
||||
|
||||
@Test
|
||||
public void getBitsTest() {
|
||||
boolean b1[] = Utils.getBits(0xFF);
|
||||
boolean[] b1 = Utils.getBits(0xFF);
|
||||
|
||||
assertEquals(b1.length, 8);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
assertEquals(true, b1[i]);
|
||||
}
|
||||
|
||||
boolean b2[] = Utils.getBits(0x5A);
|
||||
boolean[] b2 = Utils.getBits(0x5A);
|
||||
|
||||
assertEquals(b2.length, 8);
|
||||
assertEquals(false, b2[0]);
|
||||
|
||||
Reference in New Issue
Block a user