Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lcn] Refactor and fix null warnings #9675

Merged
merged 1 commit into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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