Java 17 features (N-S) (#15565)
- 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 Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
@@ -153,7 +153,7 @@ public class BAE0910 extends AbstractOwDevice {
|
||||
Channel channel = callback.getThing().getChannel(CHANNEL_DIGITAL6);
|
||||
if (channel != null) {
|
||||
BAE091xPIOConfiguration channelConfig = channel.getConfiguration().as(BAE091xPIOConfiguration.class);
|
||||
piocRegister.set(PIOC_DD, channelConfig.mode.equals("output"));
|
||||
piocRegister.set(PIOC_DD, "output".equals(channelConfig.mode));
|
||||
switch (channelConfig.pulldevice) {
|
||||
case "pullup" -> {
|
||||
piocRegister.set(PIOC_PE);
|
||||
|
||||
@@ -52,7 +52,7 @@ public class DS2423 extends AbstractOwDevice {
|
||||
List<State> states = bridgeHandler.readDecimalTypeArray(sensorId, counterParameter);
|
||||
|
||||
if (states.size() != 2) {
|
||||
throw new OwException("Expected exactly two values, got " + String.valueOf(states.size()));
|
||||
throw new OwException("Expected exactly two values, got " + states.size());
|
||||
} else {
|
||||
callback.postUpdate(CHANNEL_COUNTER + "0", states.get(0));
|
||||
callback.postUpdate(CHANNEL_COUNTER + "1", states.get(1));
|
||||
|
||||
@@ -141,8 +141,8 @@ public class DS2438 extends AbstractOwDevice {
|
||||
if (enabledChannels.contains(CHANNEL_CURRENT)) {
|
||||
if (currentSensorType == CurrentSensorType.IBUTTONLINK) {
|
||||
State current = bridgeHandler.readDecimalType(sensorId, voltageParameter);
|
||||
if (current instanceof DecimalType) {
|
||||
double currentDouble = ((DecimalType) current).doubleValue();
|
||||
if (current instanceof DecimalType decimalCommand) {
|
||||
double currentDouble = decimalCommand.doubleValue();
|
||||
if (currentDouble >= 0.1 || currentDouble <= 3.78) {
|
||||
current = new QuantityType<>(currentDouble * 5.163 + 0.483, Units.AMPERE);
|
||||
}
|
||||
@@ -168,19 +168,17 @@ public class DS2438 extends AbstractOwDevice {
|
||||
switch (lightSensorType) {
|
||||
case ELABNET_V2:
|
||||
State light = bridgeHandler.readDecimalType(sensorId, currentParamater);
|
||||
if (light instanceof DecimalType) {
|
||||
if (light instanceof DecimalType decimalCommand) {
|
||||
light = new QuantityType<>(
|
||||
Math.round(Math.pow(10, ((DecimalType) light).doubleValue() / 47 * 1000)),
|
||||
Units.LUX);
|
||||
Math.round(Math.pow(10, decimalCommand.doubleValue() / 47 * 1000)), Units.LUX);
|
||||
callback.postUpdate(CHANNEL_LIGHT, light);
|
||||
}
|
||||
break;
|
||||
case ELABNET_V1:
|
||||
light = bridgeHandler.readDecimalType(sensorId, currentParamater);
|
||||
if (light instanceof DecimalType) {
|
||||
light = new QuantityType<>(Math.round(Math
|
||||
.exp(1.059 * Math.log(1000000 * ((DecimalType) light).doubleValue() / (4096 * 390))
|
||||
+ 4.518)
|
||||
if (light instanceof DecimalType decimalCommand) {
|
||||
light = new QuantityType<>(Math.round(Math.exp(
|
||||
1.059 * Math.log(1000000 * decimalCommand.doubleValue() / (4096 * 390)) + 4.518)
|
||||
* 20000), Units.LUX);
|
||||
callback.postUpdate(CHANNEL_LIGHT, light);
|
||||
}
|
||||
|
||||
@@ -142,8 +142,8 @@ public class OwDiscoveryService extends AbstractDiscoveryService implements Thin
|
||||
|
||||
@Override
|
||||
public void setThingHandler(ThingHandler thingHandler) {
|
||||
if (thingHandler instanceof OwserverBridgeHandler) {
|
||||
this.bridgeHandler = (OwserverBridgeHandler) thingHandler;
|
||||
if (thingHandler instanceof OwserverBridgeHandler serverBridgeHandler) {
|
||||
this.bridgeHandler = serverBridgeHandler;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ package org.openhab.binding.onewire.internal.handler;
|
||||
import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -38,7 +37,7 @@ public class EDSSensorThingHandler extends OwBaseThingHandler {
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_EDS_ENV);
|
||||
public static final Set<OwSensorType> SUPPORTED_SENSOR_TYPES = Set.of(OwSensorType.EDS0064, OwSensorType.EDS0065,
|
||||
OwSensorType.EDS0066, OwSensorType.EDS0067, OwSensorType.EDS0068);
|
||||
private static final Set<String> REQUIRED_PROPERTIES = Collections.singleton(PROPERTY_HW_REVISION);
|
||||
private static final Set<String> REQUIRED_PROPERTIES = Set.of(PROPERTY_HW_REVISION);
|
||||
|
||||
public EDSSensorThingHandler(Thing thing, OwDynamicStateDescriptionProvider dynamicStateDescriptionProvider) {
|
||||
super(thing, dynamicStateDescriptionProvider, SUPPORTED_SENSOR_TYPES, REQUIRED_PROPERTIES);
|
||||
@@ -78,7 +77,7 @@ public class EDSSensorThingHandler extends OwBaseThingHandler {
|
||||
|
||||
properties.put(PROPERTY_MODELID, sensorType.name());
|
||||
properties.put(PROPERTY_VENDOR, "Embedded Data Systems");
|
||||
properties.put(PROPERTY_HW_REVISION, String.valueOf(fwRevision));
|
||||
properties.put(PROPERTY_HW_REVISION, fwRevision);
|
||||
|
||||
updateProperties(properties);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
@@ -62,7 +61,7 @@ import org.slf4j.LoggerFactory;
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class OwserverBridgeHandler extends BaseBridgeHandler {
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_OWSERVER);
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_OWSERVER);
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(OwserverBridgeHandler.class);
|
||||
protected boolean refreshable = false;
|
||||
@@ -405,9 +404,9 @@ public class OwserverBridgeHandler extends BaseBridgeHandler {
|
||||
State value;
|
||||
try {
|
||||
synchronized (owserverConnection) {
|
||||
if (channelConfig.acceptedItemType.equals("String")) {
|
||||
if ("String".equals(channelConfig.acceptedItemType)) {
|
||||
value = new StringType(owserverConnection.readString(channelConfig.path));
|
||||
} else if (channelConfig.acceptedItemType.equals("Number")) {
|
||||
} else if ("Number".equals(channelConfig.acceptedItemType)) {
|
||||
value = owserverConnection.readDecimalType(channelConfig.path);
|
||||
} else {
|
||||
logger.debug("mismatched configuration, itemType unknown for channel {}",
|
||||
|
||||
@@ -303,7 +303,7 @@ public class OwserverConnection {
|
||||
} else {
|
||||
returnPacket = read(false);
|
||||
}
|
||||
} while (returnPacket.isPingPacket() || !(returnPacket.hasPayload() == payloadExpected));
|
||||
} while (returnPacket.isPingPacket() || returnPacket.hasPayload() != payloadExpected);
|
||||
|
||||
} catch (OwException e) {
|
||||
logger.debug("failed requesting {}->{} [{}]", requestPacket, returnPacket, e.getMessage());
|
||||
|
||||
@@ -42,7 +42,7 @@ public class OwserverPacket {
|
||||
protected int packetSize = 0;
|
||||
protected int payloadOffset = 0;
|
||||
|
||||
protected byte payload[] = new byte[0];
|
||||
protected byte[] payload = new byte[0];
|
||||
|
||||
/**
|
||||
* constructor for new packet
|
||||
|
||||
@@ -83,9 +83,7 @@ public class BasicThingHandlerTest extends AbstractThingHandlerTest {
|
||||
return;
|
||||
}
|
||||
|
||||
Mockito.doAnswer(answer -> {
|
||||
return OwSensorType.DS2401;
|
||||
}).when(secondBridgeHandler).getType(any());
|
||||
Mockito.doAnswer(answer -> OwSensorType.DS2401).when(secondBridgeHandler).getType(any());
|
||||
|
||||
thingHandler.initialize();
|
||||
|
||||
@@ -101,9 +99,7 @@ public class BasicThingHandlerTest extends AbstractThingHandlerTest {
|
||||
return;
|
||||
}
|
||||
|
||||
Mockito.doAnswer(answer -> {
|
||||
return OwSensorType.DS18B20;
|
||||
}).when(secondBridgeHandler).getType(any());
|
||||
Mockito.doAnswer(answer -> OwSensorType.DS18B20).when(secondBridgeHandler).getType(any());
|
||||
|
||||
thingHandler.initialize();
|
||||
waitForAssert(() -> assertEquals(ThingStatus.UNKNOWN, thingHandler.getThing().getStatusInfo().getStatus()));
|
||||
@@ -125,9 +121,7 @@ public class BasicThingHandlerTest extends AbstractThingHandlerTest {
|
||||
return;
|
||||
}
|
||||
|
||||
Mockito.doAnswer(answer -> {
|
||||
return OwSensorType.DS2408;
|
||||
}).when(secondBridgeHandler).getType(any());
|
||||
Mockito.doAnswer(answer -> OwSensorType.DS2408).when(secondBridgeHandler).getType(any());
|
||||
|
||||
thingHandler.initialize();
|
||||
waitForAssert(() -> assertEquals(ThingStatus.UNKNOWN, thingHandler.getThing().getStatusInfo().getStatus()));
|
||||
|
||||
@@ -87,9 +87,7 @@ public class EDSSensorThingHandlerTest extends AbstractThingHandlerTest {
|
||||
|
||||
initializeHandlerMocks();
|
||||
|
||||
Mockito.doAnswer(answer -> {
|
||||
return new OwPageBuffer("EDS0065 ".getBytes());
|
||||
}).when(secondBridgeHandler).readPages(any());
|
||||
Mockito.doAnswer(answer -> new OwPageBuffer("EDS0065 ".getBytes())).when(secondBridgeHandler).readPages(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -74,9 +74,7 @@ public class MultisensorThingHandlerTest extends AbstractThingHandlerTest {
|
||||
|
||||
initializeHandlerMocks();
|
||||
|
||||
Mockito.doAnswer(answer -> {
|
||||
return OwSensorType.DS2438;
|
||||
}).when(secondBridgeHandler).getType(any());
|
||||
Mockito.doAnswer(answer -> OwSensorType.DS2438).when(secondBridgeHandler).getType(any());
|
||||
|
||||
Mockito.doAnswer(answer -> {
|
||||
OwPageBuffer pageBuffer = new OwPageBuffer(8);
|
||||
|
||||
Reference in New Issue
Block a user