Skip to content

Commit

Permalink
[lcn] Refactor and fix null warnings (#9675)
Browse files Browse the repository at this point in the history
Signed-off-by: Fabian Wolter <[email protected]>
  • Loading branch information
fwolter authored Jan 4, 2021
1 parent bebc76e commit 4f1e915
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

import static org.openhab.binding.lcn.internal.LcnBindingConstants.*;

import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
Expand All @@ -38,8 +35,8 @@
@NonNullByDefault
@Component(configurationPid = "binding.lcn", service = ThingHandlerFactory.class)
public class LcnHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.unmodifiableSet(
Stream.of(THING_TYPE_PCK_GATEWAY, THING_TYPE_MODULE, THING_TYPE_GROUP).collect(Collectors.toSet()));
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_PCK_GATEWAY,
THING_TYPE_MODULE, THING_TYPE_GROUP);

@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
package org.openhab.binding.lcn.internal;

import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
Expand All @@ -25,8 +24,6 @@
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -69,8 +66,7 @@ public class LcnModuleDiscoveryService extends AbstractDiscoveryService
private static final int MODULE_NAME_PART_COUNT = 2;
private static final int DISCOVERY_TIMEOUT_SEC = 90;
private static final int ACK_TIMEOUT_MS = 1000;
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
.unmodifiableSet(Stream.of(LcnBindingConstants.THING_TYPE_MODULE).collect(Collectors.toSet()));
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(LcnBindingConstants.THING_TYPE_MODULE);
private @Nullable PckGatewayHandler bridgeHandler;
private final Map<LcnAddrMod, @Nullable Map<Integer, String>> moduleNames = new HashMap<>();
private final Map<LcnAddrMod, DiscoveryResultBuilder> discoveryResultBuilders = new ConcurrentHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ public void initialize() {
*
* @throws LcnException when the handler is not initialized
*/
@SuppressWarnings("null")
protected void requestFirmwareVersionAndSerialNumberIfNotSet() throws LcnException {
String serialNumber = getThing().getProperties().get(Thing.PROPERTY_SERIAL_NUMBER);
if (serialNumber == null || serialNumber.isEmpty()) {
Expand Down Expand Up @@ -241,7 +240,6 @@ private Converter getConverter(ChannelUID channelUid) {
*
* @param pck the message without line termination
*/
@SuppressWarnings("null")
public void handleStatusMessage(String pck) {
for (AbstractLcnModuleSubHandler handler : subHandlers.values()) {
if (handler.tryParse(pck)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected synchronized void setState(Function<T, U> newStateFactory) {

state = newState;

state.startWorking();
newState.startWorking();
}

protected boolean isStateActive(AbstractState<?, ?> otherState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
import java.nio.channels.CompletionHandler;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Queue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -133,7 +139,10 @@ public void setLocalSegId(int localSegId) {
public void onAck(LcnAddrMod addr, int code) {
synchronized (modData) {
if (modData.containsKey(addr)) {
modData.get(addr).onAck(code, this, this.settings.getTimeout(), System.nanoTime());
ModInfo modInfo = modData.get(addr);
if (modInfo != null) {
modInfo.onAck(code, this, this.settings.getTimeout(), System.nanoTime());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.lcn.internal.LcnBindingConstants;
Expand Down Expand Up @@ -63,8 +61,8 @@ public class LcnPchkDiscoveryService extends AbstractDiscoveryService {
private static final String PCHK_DISCOVERY_MULTICAST_ADDRESS = "234.5.6.7";
private static final int PCHK_DISCOVERY_PORT = 4220;
private static final int INTERFACE_TIMEOUT_SEC = 2;
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
.unmodifiableSet(Stream.of(LcnBindingConstants.THING_TYPE_PCK_GATEWAY).collect(Collectors.toSet()));
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set
.of(LcnBindingConstants.THING_TYPE_PCK_GATEWAY);
private static final String DISCOVER_REQUEST = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ServicesRequest xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"servicesrequest.xsd\"><Version major=\"1\" minor=\"0\" /><Requester requestId=\"1\" type=\"openHAB\" major=\"1\" minor=\"0\">openHAB</Requester><Requests><Request xsi:type=\"EnumServices\" major=\"1\" minor=\"0\" name=\"LcnPchkBus\" /></Requests></ServicesRequest>";

public LcnPchkDiscoveryService() throws IllegalArgumentException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @author Fabian Wolter - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.WARN)
@MockitoSettings(strictness = Strictness.LENIENT)
@NonNullByDefault
public class AbstractTestLcnModuleSubHandler {

Expand Down

0 comments on commit 4f1e915

Please sign in to comment.