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

@@ -42,7 +42,7 @@ public class OnOffTypeConverter extends AbstractTypeConverter<OnOffType> {
@Override
protected OnOffType fromBinding(HmDatapoint dp) throws ConverterException {
return (((Boolean) dp.getValue()) == Boolean.FALSE) != isInvert(dp) ? OnOffType.OFF : OnOffType.ON;
return Boolean.FALSE.equals(dp.getValue()) != isInvert(dp) ? OnOffType.OFF : OnOffType.ON;
}
/**

View File

@@ -42,8 +42,7 @@ public class OpenClosedTypeConverter extends AbstractTypeConverter<OpenClosedTyp
@Override
protected OpenClosedType fromBinding(HmDatapoint dp) throws ConverterException {
return (((Boolean) dp.getValue()) == Boolean.FALSE) != isInvert(dp) ? OpenClosedType.CLOSED
: OpenClosedType.OPEN;
return Boolean.FALSE.equals(dp.getValue()) != isInvert(dp) ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
}
/**

View File

@@ -71,9 +71,9 @@ public class PercentTypeConverter extends AbstractTypeConverter<PercentType> {
Double number = (type.doubleValue() / 100) * maxValue;
if (MetadataUtils.isRollerShutter(dp)) {
if (type == PercentType.HUNDRED) { // means DOWN
if (PercentType.HUNDRED.equals(type)) { // means DOWN
return dp.getMinValue().doubleValue();
} else if (type == PercentType.ZERO) { // means UP
} else if (PercentType.ZERO.equals(type)) { // means UP
return maxValue;
}
return maxValue - number;

View File

@@ -41,14 +41,14 @@ public class MiscUtils {
* Returns true, if the value is not null and true.
*/
public static boolean isTrueValue(Object value) {
return value != null && value == Boolean.TRUE;
return Boolean.TRUE.equals(value);
}
/**
* Returns true, if the value is not null and false.
*/
public static boolean isFalseValue(Object value) {
return value != null && value == Boolean.FALSE;
return Boolean.FALSE.equals(value);
}
/**

View File

@@ -175,7 +175,7 @@ public class MetadataUtils {
if ("%%".equals(unit)) {
return "%d %%";
}
if (unit != null && unit != "") {
if (unit != null && !unit.isEmpty()) {
String pattern = getPattern(dp);
if (pattern != null) {
return String.format("%s %s", pattern, "%unit%");