Fix or suppress SAT CompareObjectsWithEquals findings (#10631)
* Fix or suppress SAT CompareObjectsWithEquals findings Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
parent
582ef280e5
commit
f5f922eaf4
@ -13,6 +13,7 @@
|
|||||||
package org.openhab.binding.atlona.internal;
|
package org.openhab.binding.atlona.internal;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
@ -93,13 +94,8 @@ public class StatefulHandlerCallback implements AtlonaHandlerCallback {
|
|||||||
|
|
||||||
final State oldState = this.state.get(channelId);
|
final State oldState = this.state.get(channelId);
|
||||||
|
|
||||||
// If both null OR the same value (enums), nothing changed
|
|
||||||
if (oldState == state) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If they are equal - nothing changed
|
// If they are equal - nothing changed
|
||||||
if (oldState != null && oldState.equals(state)) {
|
if (Objects.equals(oldState, state)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -185,7 +185,7 @@ public class BlueGigaBluetoothDevice extends BaseBluetoothDevice implements Blue
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean discoverServices() {
|
public boolean discoverServices() {
|
||||||
if (currentProcedure != PROCEDURE_NONE) {
|
if (!PROCEDURE_NONE.equals(currentProcedure)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ public class BlueGigaBluetoothDevice extends BaseBluetoothDevice implements Blue
|
|||||||
new BluetoothException("Unable to find CCC for characteristic [" + characteristic.getUuid() + "]"));
|
new BluetoothException("Unable to find CCC for characteristic [" + characteristic.getUuid() + "]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentProcedure != PROCEDURE_NONE) {
|
if (!PROCEDURE_NONE.equals(currentProcedure)) {
|
||||||
return CompletableFuture.failedFuture(new BluetoothException("Another procedure is already in progress"));
|
return CompletableFuture.failedFuture(new BluetoothException("Another procedure is already in progress"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,7 +264,7 @@ public class BlueGigaBluetoothDevice extends BaseBluetoothDevice implements Blue
|
|||||||
new BluetoothException("Unable to find CCC for characteristic [" + characteristic.getUuid() + "]"));
|
new BluetoothException("Unable to find CCC for characteristic [" + characteristic.getUuid() + "]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentProcedure != PROCEDURE_NONE) {
|
if (!PROCEDURE_NONE.equals(currentProcedure)) {
|
||||||
return CompletableFuture.failedFuture(new BluetoothException("Another procedure is already in progress"));
|
return CompletableFuture.failedFuture(new BluetoothException("Another procedure is already in progress"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,7 +311,7 @@ public class BlueGigaBluetoothDevice extends BaseBluetoothDevice implements Blue
|
|||||||
return CompletableFuture.failedFuture(new BluetoothException("Not connected"));
|
return CompletableFuture.failedFuture(new BluetoothException("Not connected"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentProcedure != PROCEDURE_NONE) {
|
if (!PROCEDURE_NONE.equals(currentProcedure)) {
|
||||||
return CompletableFuture.failedFuture(new BluetoothException("Another procedure is already in progress"));
|
return CompletableFuture.failedFuture(new BluetoothException("Another procedure is already in progress"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,7 +336,7 @@ public class BlueGigaBluetoothDevice extends BaseBluetoothDevice implements Blue
|
|||||||
return CompletableFuture.failedFuture(new BluetoothException("Not connected"));
|
return CompletableFuture.failedFuture(new BluetoothException("Not connected"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentProcedure != PROCEDURE_NONE) {
|
if (!PROCEDURE_NONE.equals(currentProcedure)) {
|
||||||
return CompletableFuture.failedFuture(new BluetoothException("Another procedure is already in progress"));
|
return CompletableFuture.failedFuture(new BluetoothException("Another procedure is already in progress"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -564,7 +564,7 @@ public class BlueGigaBluetoothDevice extends BaseBluetoothDevice implements Blue
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentProcedure == PROCEDURE_NONE) {
|
if (!PROCEDURE_NONE.equals(currentProcedure)) {
|
||||||
logger.debug("BlueGiga procedure completed but procedure is null with connection {}, address {}",
|
logger.debug("BlueGiga procedure completed but procedure is null with connection {}, address {}",
|
||||||
connection, address);
|
connection, address);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -68,6 +68,7 @@ public class RoamingBluetoothDevice extends DelegateBluetoothDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("PMD.CompareObjectsWithEquals")
|
||||||
protected @Nullable BluetoothDevice getDelegate() {
|
protected @Nullable BluetoothDevice getDelegate() {
|
||||||
BluetoothDevice newDelegate = null;
|
BluetoothDevice newDelegate = null;
|
||||||
int newRssi = Integer.MIN_VALUE;
|
int newRssi = Integer.MIN_VALUE;
|
||||||
|
|||||||
@ -14,6 +14,7 @@ package org.openhab.binding.bosesoundtouch.internal;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringEscapeUtils;
|
import org.apache.commons.lang3.StringEscapeUtils;
|
||||||
import org.openhab.core.types.StateOption;
|
import org.openhab.core.types.StateOption;
|
||||||
@ -90,19 +91,19 @@ public class ContentItem {
|
|||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj instanceof ContentItem) {
|
if (obj instanceof ContentItem) {
|
||||||
ContentItem other = (ContentItem) obj;
|
ContentItem other = (ContentItem) obj;
|
||||||
if (!isEqual(other.source, this.source)) {
|
if (!Objects.equals(other.source, this.source)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!isEqual(other.sourceAccount, this.sourceAccount)) {
|
if (!Objects.equals(other.sourceAccount, this.sourceAccount)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (other.presetable != this.presetable) {
|
if (other.presetable != this.presetable) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!isEqual(other.location, this.location)) {
|
if (!Objects.equals(other.location, this.location)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!isEqual(other.itemName, this.itemName)) {
|
if (!Objects.equals(other.itemName, this.itemName)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -265,14 +266,4 @@ public class ContentItem {
|
|||||||
// }
|
// }
|
||||||
return itemName;
|
return itemName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEqual(String s1, String s2) {
|
|
||||||
if (s1 == s2) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (s1 == null || s2 == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return s1.equals(s2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -80,6 +80,7 @@ public abstract class AbstractWeatherHandler extends BaseThingHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("PMD.CompareObjectsWithEquals")
|
||||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||||
if (RefreshType.REFRESH == command) {
|
if (RefreshType.REFRESH == command) {
|
||||||
ScheduledFuture<?> prevFuture = updateChannelsFutureRef.get();
|
ScheduledFuture<?> prevFuture = updateChannelsFutureRef.get();
|
||||||
@ -94,6 +95,7 @@ public abstract class AbstractWeatherHandler extends BaseThingHandler {
|
|||||||
logger.trace("REFRESH received. Delaying by {} ms to avoid throttle excessive REFRESH",
|
logger.trace("REFRESH received. Delaying by {} ms to avoid throttle excessive REFRESH",
|
||||||
delayRemainingMillis);
|
delayRemainingMillis);
|
||||||
}
|
}
|
||||||
|
// Compare by reference to check if the future changed
|
||||||
if (prevFuture == newFuture) {
|
if (prevFuture == newFuture) {
|
||||||
logger.trace("REFRESH received. Previous refresh ongoing, will wait for it to complete in {} ms",
|
logger.trace("REFRESH received. Previous refresh ongoing, will wait for it to complete in {} ms",
|
||||||
lastRefreshMillis + REFRESH_THROTTLE_MILLIS - System.currentTimeMillis());
|
lastRefreshMillis + REFRESH_THROTTLE_MILLIS - System.currentTimeMillis());
|
||||||
|
|||||||
@ -603,7 +603,7 @@ public class EthernetBridgeHandler extends BaseBridgeHandler implements Transcei
|
|||||||
SelectionKey selKey = it.next();
|
SelectionKey selKey = it.next();
|
||||||
it.remove();
|
it.remove();
|
||||||
if (selKey.isValid()) {
|
if (selKey.isValid()) {
|
||||||
if (selKey.isAcceptable() && selKey == listenerKey) {
|
if (selKey.isAcceptable() && selKey.equals(listenerKey)) {
|
||||||
try {
|
try {
|
||||||
SocketChannel newChannel = listenerChannel.accept();
|
SocketChannel newChannel = listenerChannel.accept();
|
||||||
newChannel.configureBlocking(false);
|
newChannel.configureBlocking(false);
|
||||||
|
|||||||
@ -58,6 +58,7 @@ public abstract class AbstractStateMachine<T extends AbstractStateMachine<T, U>,
|
|||||||
newState.startWorking();
|
newState.startWorking();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("PMD.CompareObjectsWithEquals")
|
||||||
protected boolean isStateActive(AbstractState<?, ?> otherState) {
|
protected boolean isStateActive(AbstractState<?, ?> otherState) {
|
||||||
return state == otherState; // compare by identity
|
return state == otherState; // compare by identity
|
||||||
}
|
}
|
||||||
|
|||||||
@ -621,6 +621,7 @@ public class PowermaxCommManager implements PowermaxMessageEventListener {
|
|||||||
*
|
*
|
||||||
* @return true if the message was sent or the sending is delayed; false in other cases
|
* @return true if the message was sent or the sending is delayed; false in other cases
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("PMD.CompareObjectsWithEquals")
|
||||||
private synchronized boolean sendMessage(PowermaxBaseMessage msg, boolean immediate, int waitTime,
|
private synchronized boolean sendMessage(PowermaxBaseMessage msg, boolean immediate, int waitTime,
|
||||||
boolean doNotLog) {
|
boolean doNotLog) {
|
||||||
if ((waitTime > 0) && (msg != null)) {
|
if ((waitTime > 0) && (msg != null)) {
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
package org.openhab.binding.russound.internal.rio;
|
package org.openhab.binding.russound.internal.rio;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
@ -94,13 +95,8 @@ public class StatefulHandlerCallback implements RioHandlerCallback {
|
|||||||
|
|
||||||
final State oldState = state.get(channelId);
|
final State oldState = state.get(channelId);
|
||||||
|
|
||||||
// If both null OR the same value (enums), nothing changed
|
|
||||||
if (oldState == newState) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If they are equal - nothing changed
|
// If they are equal - nothing changed
|
||||||
if (oldState != null && oldState.equals(newState)) {
|
if (Objects.equals(oldState, newState)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -77,7 +77,7 @@ public class ShellyChannelCache {
|
|||||||
current = channelData.get(channelId);
|
current = channelData.get(channelId);
|
||||||
}
|
}
|
||||||
if (!enabled || forceUpdate || (current == null) || !current.equals(newValue)) {
|
if (!enabled || forceUpdate || (current == null) || !current.equals(newValue)) {
|
||||||
if ((current != null) && current.getClass().isEnum() && (current == newValue)) {
|
if ((current != null) && current.getClass().isEnum() && (current.equals(newValue))) {
|
||||||
return false; // special case for OnOffType
|
return false; // special case for OnOffType
|
||||||
}
|
}
|
||||||
// For channels that support multiple types (like brightness) a suffix is added
|
// For channels that support multiple types (like brightness) a suffix is added
|
||||||
|
|||||||
@ -80,7 +80,7 @@ public class SmartthingsDiscoveryService extends AbstractDiscoveryService implem
|
|||||||
|
|
||||||
protected void unsetSmartthingsHubCommand(SmartthingsHubCommand hubCommand) {
|
protected void unsetSmartthingsHubCommand(SmartthingsHubCommand hubCommand) {
|
||||||
// Make sure it is this handleFactory that should be unset
|
// Make sure it is this handleFactory that should be unset
|
||||||
if (hubCommand == smartthingsHubCommand) {
|
if (Objects.equals(hubCommand, smartthingsHubCommand)) {
|
||||||
this.smartthingsHubCommand = null;
|
this.smartthingsHubCommand = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -131,6 +131,7 @@ public class PhonebookProfile implements StateProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("PMD.CompareObjectsWithEquals")
|
||||||
public void onStateUpdateFromHandler(State state) {
|
public void onStateUpdateFromHandler(State state) {
|
||||||
if (state instanceof UnDefType) {
|
if (state instanceof UnDefType) {
|
||||||
// we cannot adjust UNDEF or NULL values, thus we simply apply them without reporting an error or warning
|
// we cannot adjust UNDEF or NULL values, thus we simply apply them without reporting an error or warning
|
||||||
@ -139,6 +140,7 @@ public class PhonebookProfile implements StateProfile {
|
|||||||
if (state instanceof StringType) {
|
if (state instanceof StringType) {
|
||||||
Optional<String> match = resolveNumber(state.toString());
|
Optional<String> match = resolveNumber(state.toString());
|
||||||
State newState = match.map(name -> (State) new StringType(name)).orElse(state);
|
State newState = match.map(name -> (State) new StringType(name)).orElse(state);
|
||||||
|
// Compare by reference to check if the name is mapped to the same state
|
||||||
if (newState == state) {
|
if (newState == state) {
|
||||||
logger.debug("Number '{}' not found in phonebook '{}' from provider '{}'", state, phonebookName,
|
logger.debug("Number '{}' not found in phonebook '{}' from provider '{}'", state, phonebookName,
|
||||||
thingUID);
|
thingUID);
|
||||||
|
|||||||
@ -113,6 +113,7 @@ abstract class AbstractHomekitAccessoryImpl implements HomekitAccessory {
|
|||||||
return accessory;
|
return accessory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Collection<Service> getServices() {
|
public Collection<Service> getServices() {
|
||||||
return this.services;
|
return this.services;
|
||||||
}
|
}
|
||||||
@ -182,7 +183,7 @@ abstract class AbstractHomekitAccessoryImpl implements HomekitAccessory {
|
|||||||
* return configuration attached to the root accessory, e.g. groupItem.
|
* return configuration attached to the root accessory, e.g. groupItem.
|
||||||
* Note: result will be casted to the type of the default value.
|
* Note: result will be casted to the type of the default value.
|
||||||
* The type for number is BigDecimal.
|
* The type for number is BigDecimal.
|
||||||
*
|
*
|
||||||
* @param key configuration key
|
* @param key configuration key
|
||||||
* @param defaultValue default value
|
* @param defaultValue default value
|
||||||
* @param <T> expected type
|
* @param <T> expected type
|
||||||
@ -197,7 +198,7 @@ abstract class AbstractHomekitAccessoryImpl implements HomekitAccessory {
|
|||||||
* return configuration of the characteristic item, e.g. currentTemperature.
|
* return configuration of the characteristic item, e.g. currentTemperature.
|
||||||
* Note: result will be casted to the type of the default value.
|
* Note: result will be casted to the type of the default value.
|
||||||
* The type for number is BigDecimal.
|
* The type for number is BigDecimal.
|
||||||
*
|
*
|
||||||
* @param characteristicType characteristic type
|
* @param characteristicType characteristic type
|
||||||
* @param key configuration key
|
* @param key configuration key
|
||||||
* @param defaultValue default value
|
* @param defaultValue default value
|
||||||
@ -215,7 +216,7 @@ abstract class AbstractHomekitAccessoryImpl implements HomekitAccessory {
|
|||||||
* update mapping with values from item configuration.
|
* update mapping with values from item configuration.
|
||||||
* it checks for all keys from the mapping whether there is configuration at item with the same key and if yes,
|
* it checks for all keys from the mapping whether there is configuration at item with the same key and if yes,
|
||||||
* replace the value.
|
* replace the value.
|
||||||
*
|
*
|
||||||
* @param characteristicType characteristicType to identify item
|
* @param characteristicType characteristicType to identify item
|
||||||
* @param map mapping to update
|
* @param map mapping to update
|
||||||
* @param customEnumList list to store custom state enumeration
|
* @param customEnumList list to store custom state enumeration
|
||||||
@ -247,7 +248,7 @@ abstract class AbstractHomekitAccessoryImpl implements HomekitAccessory {
|
|||||||
/**
|
/**
|
||||||
* takes item state as value and retrieves the key for that value from mapping.
|
* takes item state as value and retrieves the key for that value from mapping.
|
||||||
* e.g. used to map StringItem value to HomeKit Enum
|
* e.g. used to map StringItem value to HomeKit Enum
|
||||||
*
|
*
|
||||||
* @param characteristicType characteristicType to identify item
|
* @param characteristicType characteristicType to identify item
|
||||||
* @param mapping mapping
|
* @param mapping mapping
|
||||||
* @param defaultValue default value if nothing found in mapping
|
* @param defaultValue default value if nothing found in mapping
|
||||||
@ -283,7 +284,7 @@ abstract class AbstractHomekitAccessoryImpl implements HomekitAccessory {
|
|||||||
|
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
private <T extends Quantity<T>> double convertAndRound(double value, Unit<T> from, Unit<T> to) {
|
private <T extends Quantity<T>> double convertAndRound(double value, Unit<T> from, Unit<T> to) {
|
||||||
double rawValue = from == to ? value : from.getConverterTo(to).convert(value);
|
double rawValue = from.equals(to) ? value : from.getConverterTo(to).convert(value);
|
||||||
return new BigDecimal(rawValue).setScale(1, RoundingMode.HALF_UP).doubleValue();
|
return new BigDecimal(rawValue).setScale(1, RoundingMode.HALF_UP).doubleValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,7 +303,7 @@ abstract class AbstractHomekitAccessoryImpl implements HomekitAccessory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* create boolean reader with ON state mapped to trueOnOffValue or trueOpenClosedValue depending of item type
|
* create boolean reader with ON state mapped to trueOnOffValue or trueOpenClosedValue depending of item type
|
||||||
*
|
*
|
||||||
* @param characteristicType characteristic id
|
* @param characteristicType characteristic id
|
||||||
* @param trueOnOffValue ON value for switch
|
* @param trueOnOffValue ON value for switch
|
||||||
* @param trueOpenClosedValue ON value for contact
|
* @param trueOpenClosedValue ON value for contact
|
||||||
@ -320,7 +321,7 @@ abstract class AbstractHomekitAccessoryImpl implements HomekitAccessory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* create boolean reader with default ON/OFF mapping considering inverted flag
|
* create boolean reader with default ON/OFF mapping considering inverted flag
|
||||||
*
|
*
|
||||||
* @param characteristicType characteristic id
|
* @param characteristicType characteristic id
|
||||||
* @return boolean reader
|
* @return boolean reader
|
||||||
* @throws IncompleteAccessoryException
|
* @throws IncompleteAccessoryException
|
||||||
|
|||||||
@ -60,7 +60,7 @@ public class HomekitLockImpl extends AbstractHomekitAccessoryImpl implements Loc
|
|||||||
if (state instanceof DecimalType) {
|
if (state instanceof DecimalType) {
|
||||||
lockState = LockCurrentStateEnum.fromCode(((DecimalType) state).intValue());
|
lockState = LockCurrentStateEnum.fromCode(((DecimalType) state).intValue());
|
||||||
} else if (state instanceof OnOffType) {
|
} else if (state instanceof OnOffType) {
|
||||||
lockState = state == securedState ? LockCurrentStateEnum.SECURED : LockCurrentStateEnum.UNSECURED;
|
lockState = state.equals(securedState) ? LockCurrentStateEnum.SECURED : LockCurrentStateEnum.UNSECURED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CompletableFuture.completedFuture(lockState);
|
return CompletableFuture.completedFuture(lockState);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user