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

[max] add @notnullbydefault to eliminate warnings from commands classes #8427

Merged
merged 1 commit into from
Sep 8, 2020
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 @@ -12,11 +12,14 @@
*/
package org.openhab.binding.max.internal.command;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* The {@link ACommand} deletes the device and room configuration from the Cube.
*
* @author Marcel Verpaalen - Initial Contribution
*/
@NonNullByDefault
public class ACommand extends CubeCommand {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
*/
package org.openhab.binding.max.internal.command;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* The {@link C_CubeCommand} to request configuration of a new MAX! device after inclusion.
*
* @author Marcel Verpaalen - Initial Contribution
*/
@NonNullByDefault
public class CCommand extends CubeCommand {
private final String rfAddress;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
*/
package org.openhab.binding.max.internal.command;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* {@link CubeCommand} is the base class for commands to be send to the MAX! Cube.
*
* @author Marcel Verpaalen - Initial contribution
*
*/
@NonNullByDefault
public abstract class CubeCommand {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
*/
package org.openhab.binding.max.internal.command;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;

/**
* The {@link F_CubeCommand} is used to query and update the NTP servers used by the Cube.
*
* @author Marcel Verpaalen - Initial Contribution
*/
@NonNullByDefault
public class FCommand extends CubeCommand {

private String ntpServer1 = "";
Expand All @@ -31,7 +35,7 @@ public FCommand() {
/**
* Updates the Cube the NTP info
*/
public FCommand(String ntpServer1, String ntpServer2) {
public FCommand(@Nullable String ntpServer1, @Nullable String ntpServer2) {
this.ntpServer1 = ntpServer1 != null ? ntpServer1 : "";
this.ntpServer2 = ntpServer2 != null ? ntpServer2 : "";
}
Expand All @@ -44,7 +48,6 @@ public String getCommandString() {
} else {
servers = ntpServer1 + ntpServer2;
}

return "f:" + servers + '\r' + '\n';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
*/
package org.openhab.binding.max.internal.command;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* The {@link LCommand} request a status update for MAX! devices.
*
* @author Marcel Verpaalen - Initial Contribution
*/
@NonNullByDefault
public class LCommand extends CubeCommand {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.apache.commons.lang.StringUtils;
import org.apache.commons.net.util.Base64;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.max.internal.Utils;
import org.openhab.binding.max.internal.device.Device;
import org.openhab.binding.max.internal.device.RoomInformation;
Expand All @@ -33,6 +34,7 @@
*
* @author Marcel Verpaalen - Initial Contribution
*/
@NonNullByDefault
public class MCommand extends CubeCommand {
private final Logger logger = LoggerFactory.getLogger(MCommand.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
*/
package org.openhab.binding.max.internal.command;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* The {@link N_CubeCommand} starts the inclusion mode for new MAX! devices.
*
*
* @author Marcel Verpaalen - Initial Contribution
*/
@NonNullByDefault
public class NCommand extends CubeCommand {
// Example n:003c = start inclusion, timeout 003c = 60 sec

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
*/
package org.openhab.binding.max.internal.command;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* The {@link QCommand} Quits the connection to the MAX! Cube.
*
* @author Marcel Verpaalen - Initial Contribution
*/
@NonNullByDefault
public class QCommand extends CubeCommand {

@Override
Expand All @@ -26,6 +29,6 @@ public String getCommandString() {

@Override
public String getReturnStrings() {
return null;
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.openhab.binding.max.internal.command;

import org.apache.commons.net.util.Base64;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.max.internal.Utils;
import org.openhab.binding.max.internal.device.ThermostatModeType;

Expand All @@ -22,6 +23,7 @@
* @author Andreas Heil (info@aheil.de) - Initial contribution
* @author Marcel Verpaalen - OH2 update + simplification
*/
@NonNullByDefault
public class SCommand extends CubeCommand {

private static final String BASE_STRING_S = "000040000000"; // for single devices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.openhab.binding.max.internal.command;

import org.apache.commons.net.util.Base64;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.max.internal.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -22,13 +23,14 @@
*
* @author Marcel Verpaalen - Initial contribution
*/
@NonNullByDefault
public class SConfigCommand extends CubeCommand {

private String baseString;
private String baseString = "";
private final String rfAddress;
private final int roomId;

private byte[] commandBytes;
private byte[] commandBytes = new byte[0];

private final Logger logger = LoggerFactory.getLogger(SConfigCommand.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.net.util.Base64;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.max.internal.Utils;

/**
* The {@link T_CubeCommand} is used to unlink MAX! devices from the Cube.
*
* @author Marcel Verpaalen - Initial Contribution
*/
@NonNullByDefault
public class TCommand extends CubeCommand {

private static final int FORCE_UPDATE = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.HashMap;
import java.util.Map;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.max.internal.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -34,6 +36,7 @@
*
* @author Marcel Verpaalen - Initial contribution
*/
@NonNullByDefault
public class UdpCubeCommand {

private static final String MAXCUBE_COMMAND_STRING = "eQ3Max*\0";
Expand All @@ -45,9 +48,10 @@ public class UdpCubeCommand {
private final UdpCommandType commandType;
private final String serialNumber;
private Map<String, String> commandResponse = new HashMap<>();
@Nullable
private String ipAddress;

public UdpCubeCommand(UdpCommandType commandType, String serialNumber) {
public UdpCubeCommand(UdpCommandType commandType, @Nullable String serialNumber) {
this.commandType = commandType;
if (serialNumber == null || serialNumber.isEmpty()) {
this.serialNumber = "**********";
Expand Down Expand Up @@ -168,7 +172,7 @@ private void receiveUdpCommandResponse() {
* @param ipAddress IP address of the MAX! Cube
*
*/
private void sendUdpCommand(String commandString, String ipAddress) {
private void sendUdpCommand(String commandString, @Nullable String ipAddress) {
DatagramSocket bcSend = null;
try {
bcSend = new DatagramSocket();
Expand All @@ -184,7 +188,6 @@ private void sendUdpCommand(String commandString, String ipAddress) {
continue;
}
for (InterfaceAddress interfaceAddress : networkInterface.getInterfaceAddresses()) {

InetAddress[] broadcast = new InetAddress[3];
if (ipAddress != null && !ipAddress.isEmpty()) {
broadcast[0] = InetAddress.getByName(ipAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
*/
package org.openhab.binding.max.internal.command;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.max.internal.Utils;

/**
* The {@link ZCommand} send a wakeup request to MAX! devices.
*
* @author Marcel Verpaalen - Initial Contribution
*/
@NonNullByDefault
public class ZCommand extends CubeCommand {

public enum WakeUpType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ private synchronized boolean sendCubeCommand(CubeCommand command) {
writer.write(command.getCommandString());
logger.trace("Write string to Max! Cube {}: {}", ipAddress, command.getCommandString());
writer.flush();
if (command.getReturnStrings() != null) {
if (!command.getReturnStrings().isEmpty()) {
readLines(command.getReturnStrings());
} else {
socketClose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
*/
package org.openhab.binding.max.internal.handler;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.types.Command;
import org.openhab.binding.max.internal.command.CubeCommand;
Expand All @@ -22,14 +23,15 @@
*
* @author Marcel Verpaalen - Initial contribution
*/
@NonNullByDefault
public final class SendCommand {

private int id;
private static int commandId = -1;

private ChannelUID channelUID;
private Command command;
private CubeCommand cubeCommand;
private @Nullable ChannelUID channelUID;
private @Nullable Command command;
private @Nullable CubeCommand cubeCommand;
private String serialNumber;
private String key;
private String commandText;
Expand All @@ -41,7 +43,7 @@ public SendCommand(String serialNumber, ChannelUID channelUID, Command command)
this.channelUID = channelUID;
this.command = command;
key = getKey(serialNumber, channelUID);
this.setCommandText(command.toString());
this.commandText = command.toString();
}

public SendCommand(String serialNumber, CubeCommand cubeCommand, String commandText) {
Expand All @@ -50,7 +52,7 @@ public SendCommand(String serialNumber, CubeCommand cubeCommand, String commandT
this.serialNumber = serialNumber;
this.cubeCommand = cubeCommand;
key = getKey(serialNumber, cubeCommand);
this.setCommandText(commandText);
this.commandText = commandText;
}

/**
Expand Down Expand Up @@ -82,7 +84,7 @@ public int getId() {
return id;
}

public ChannelUID getChannelUID() {
public @Nullable ChannelUID getChannelUID() {
return channelUID;
}

Expand All @@ -91,15 +93,15 @@ public void setChannelUID(ChannelUID channelUID) {
key = getKey(serialNumber, channelUID);
}

public Command getCommand() {
public @Nullable Command getCommand() {
return command;
}

public void setCommand(Command command) {
this.command = command;
}

public CubeCommand getCubeCommand() {
public @Nullable CubeCommand getCubeCommand() {
return cubeCommand;
}

Expand All @@ -109,7 +111,10 @@ public String getDeviceSerial() {

public void setDeviceSerial(String device) {
this.serialNumber = device;
key = getKey(serialNumber, channelUID);
final ChannelUID channelUID = this.channelUID;
if (channelUID != null) {
key = getKey(serialNumber, channelUID);
}
}

public String getCommandText() {
Expand All @@ -122,8 +127,10 @@ public void setCommandText(String commandText) {

@Override
public String toString() {
return new ToStringBuilder(this).append("id", id).append("channelUID", channelUID).append("command", command)
.append("cubeCommand", cubeCommand).append("serialNumber", serialNumber).append("key", key)
.append("commandText", commandText).toString();
StringBuilder sb = new StringBuilder();
return sb.append("id: ").append(id).append(", channelUID: ").append(channelUID).append(", command: ")
.append(command).append(", cubeCommand: ").append(cubeCommand).append(", serialNumber: ")
.append(serialNumber).append(", key: ").append(key).append(", commandText: ").append(commandText)
.toString();
}
}