Fix/suppress PMD CompareObjectsWithEquals findings (#11476)

Newer PMD versions discover more CompareObjectsWithEquals findings.

Related to https://github.com/openhab/static-code-analysis/pull/423

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born
2021-11-02 10:43:53 +01:00
committed by GitHub
parent b67b9fcb25
commit 589400e223
82 changed files with 175 additions and 141 deletions

View File

@@ -322,7 +322,7 @@ public abstract class DSCAlarmBaseThingHandler extends BaseThingHandler {
List<Channel> channels = getThing().getChannels();
for (Channel ch : channels) {
if (channelUID == ch.getUID()) {
if (ch.getUID().equals(channelUID)) {
channel = ch;
break;
}

View File

@@ -100,40 +100,34 @@ public class KeypadThingHandler extends DSCAlarmBaseThingHandler {
String[] channelTypes = { KEYPAD_READY_LED, KEYPAD_ARMED_LED, KEYPAD_MEMORY_LED, KEYPAD_BYPASS_LED,
KEYPAD_TROUBLE_LED, KEYPAD_PROGRAM_LED, KEYPAD_FIRE_LED, KEYPAD_BACKLIGHT_LED };
String channel;
ChannelUID channelUID = null;
DSCAlarmCode dscAlarmCode = DSCAlarmCode
.getDSCAlarmCodeValue(dscAlarmMessage.getMessageInfo(DSCAlarmMessageInfoType.CODE));
int bitCount = 8;
int bitField = Integer.decode("0x" + dscAlarmMessage.getMessageInfo(DSCAlarmMessageInfoType.DATA));
int[] masks = { 1, 2, 4, 8, 16, 32, 64, 128 };
int[] bits = new int[8];
int[] bits = new int[bitCount];
for (int i = 0; i < 8; i++) {
for (int i = 0; i < bitCount; i++) {
bits[i] = bitField & masks[i];
channel = channelTypes[i];
if (channel != "") {
channelUID = new ChannelUID(getThing().getUID(), channel);
switch (dscAlarmCode) {
case KeypadLEDState: /* 510 */
updateChannel(channelUID, bits[i] != 0 ? 1 : 0, "");
break;
case KeypadLEDFlashState: /* 511 */
if (bits[i] != 0) {
updateChannel(channelUID, 2, "");
}
break;
default:
break;
}
ChannelUID channelUID = new ChannelUID(getThing().getUID(), channelTypes[i]);
switch (dscAlarmCode) {
case KeypadLEDState: /* 510 */
updateChannel(channelUID, bits[i] != 0 ? 1 : 0, "");
break;
case KeypadLEDFlashState: /* 511 */
if (bits[i] != 0) {
updateChannel(channelUID, 2, "");
}
break;
default:
break;
}
}
}
@Override
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public void dscAlarmEventReceived(EventObject event, Thing thing) {
if (thing != null) {
if (getThing() == thing) {

View File

@@ -257,19 +257,11 @@ public class PanelThingHandler extends DSCAlarmBaseThingHandler {
* @param timeStamp
*/
private void setTimeStampState(String timeStamp) {
int state = 0;
ChannelUID channelUID = new ChannelUID(getThing().getUID(), PANEL_TIME_STAMP);
boolean isTimeStamp = timeStamp != "";
if ((timeStamp == "" && !isTimeStamp) || (timeStamp != "" && isTimeStamp)) {
logger.debug("setTimeStampState(): Already Set: {}", timeStamp);
return;
} else if (timeStamp != "") {
state = 1;
if (timeStamp != null) {
ChannelUID channelUID = new ChannelUID(getThing().getUID(), PANEL_TIME_STAMP);
int state = timeStamp.isEmpty() ? 0 : 1;
updateChannel(channelUID, state, "");
}
updateChannel(channelUID, state, "");
}
/**
@@ -391,19 +383,15 @@ public class PanelThingHandler extends DSCAlarmBaseThingHandler {
String channel;
ChannelUID channelUID = null;
int bitCount = 8;
int bitField = Integer.decode("0x" + dscAlarmMessage.getMessageInfo(DSCAlarmMessageInfoType.DATA));
int[] masks = { 1, 2, 4, 8, 16, 32, 64, 128 };
int[] bits = new int[8];
int[] bits = new int[bitCount];
for (int i = 0; i < 8; i++) {
for (int i = 0; i < bitCount; i++) {
channelUID = new ChannelUID(getThing().getUID(), channelTypes[i]);
bits[i] = bitField & masks[i];
channel = channelTypes[i];
if (channel != "") {
channelUID = new ChannelUID(getThing().getUID(), channel);
updateChannel(channelUID, bits[i] != 0 ? 1 : 0, "");
}
updateChannel(channelUID, bits[i] != 0 ? 1 : 0, "");
}
}
@@ -436,6 +424,7 @@ public class PanelThingHandler extends DSCAlarmBaseThingHandler {
}
@Override
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public void dscAlarmEventReceived(EventObject event, Thing thing) {
if (thing != null) {
DSCAlarmEvent dscAlarmEvent = (DSCAlarmEvent) event;

View File

@@ -184,6 +184,7 @@ public class PartitionThingHandler extends DSCAlarmBaseThingHandler {
}
@Override
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public void dscAlarmEventReceived(EventObject event, Thing thing) {
if (thing != null) {
if (getThing() == thing) {