package org.openhab.binding.atlona.internal;
import java.util.Map;
+import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
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 (oldState != null && oldState.equals(state)) {
+ if (Objects.equals(oldState, state)) {
return;
}
@Override
public boolean discoverServices() {
- if (currentProcedure != PROCEDURE_NONE) {
+ if (!PROCEDURE_NONE.equals(currentProcedure)) {
return false;
}
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"));
}
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("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("Not connected"));
}
- if (currentProcedure != PROCEDURE_NONE) {
+ if (!PROCEDURE_NONE.equals(currentProcedure)) {
return CompletableFuture.failedFuture(new BluetoothException("Another procedure is already in progress"));
}
return;
}
- if (currentProcedure == PROCEDURE_NONE) {
+ if (!PROCEDURE_NONE.equals(currentProcedure)) {
logger.debug("BlueGiga procedure completed but procedure is null with connection {}, address {}",
connection, address);
return;
}
@Override
+ @SuppressWarnings("PMD.CompareObjectsWithEquals")
protected @Nullable BluetoothDevice getDelegate() {
BluetoothDevice newDelegate = null;
int newRssi = Integer.MIN_VALUE;
import java.util.HashMap;
import java.util.Map;
+import java.util.Objects;
import org.apache.commons.lang3.StringEscapeUtils;
import org.openhab.core.types.StateOption;
public boolean equals(Object obj) {
if (obj instanceof ContentItem) {
ContentItem other = (ContentItem) obj;
- if (!isEqual(other.source, this.source)) {
+ if (!Objects.equals(other.source, this.source)) {
return false;
}
- if (!isEqual(other.sourceAccount, this.sourceAccount)) {
+ if (!Objects.equals(other.sourceAccount, this.sourceAccount)) {
return false;
}
if (other.presetable != this.presetable) {
return false;
}
- if (!isEqual(other.location, this.location)) {
+ if (!Objects.equals(other.location, this.location)) {
return false;
}
- if (!isEqual(other.itemName, this.itemName)) {
+ if (!Objects.equals(other.itemName, this.itemName)) {
return false;
}
return true;
// }
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);
- }
}
}
@Override
+ @SuppressWarnings("PMD.CompareObjectsWithEquals")
public void handleCommand(ChannelUID channelUID, Command command) {
if (RefreshType.REFRESH == command) {
ScheduledFuture<?> prevFuture = updateChannelsFutureRef.get();
logger.trace("REFRESH received. Delaying by {} ms to avoid throttle excessive REFRESH",
delayRemainingMillis);
}
+ // Compare by reference to check if the future changed
if (prevFuture == newFuture) {
logger.trace("REFRESH received. Previous refresh ongoing, will wait for it to complete in {} ms",
lastRefreshMillis + REFRESH_THROTTLE_MILLIS - System.currentTimeMillis());
SelectionKey selKey = it.next();
it.remove();
if (selKey.isValid()) {
- if (selKey.isAcceptable() && selKey == listenerKey) {
+ if (selKey.isAcceptable() && selKey.equals(listenerKey)) {
try {
SocketChannel newChannel = listenerChannel.accept();
newChannel.configureBlocking(false);
newState.startWorking();
}
+ @SuppressWarnings("PMD.CompareObjectsWithEquals")
protected boolean isStateActive(AbstractState<?, ?> otherState) {
return state == otherState; // compare by identity
}
*
* @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,
boolean doNotLog) {
if ((waitTime > 0) && (msg != null)) {
package org.openhab.binding.russound.internal.rio;
import java.util.Map;
+import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
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 (oldState != null && oldState.equals(newState)) {
+ if (Objects.equals(oldState, newState)) {
return;
}
current = channelData.get(channelId);
}
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
}
// For channels that support multiple types (like brightness) a suffix is added
protected void unsetSmartthingsHubCommand(SmartthingsHubCommand hubCommand) {
// Make sure it is this handleFactory that should be unset
- if (hubCommand == smartthingsHubCommand) {
+ if (Objects.equals(hubCommand, smartthingsHubCommand)) {
this.smartthingsHubCommand = null;
}
}
}
@Override
+ @SuppressWarnings("PMD.CompareObjectsWithEquals")
public void onStateUpdateFromHandler(State state) {
if (state instanceof UnDefType) {
// we cannot adjust UNDEF or NULL values, thus we simply apply them without reporting an error or warning
if (state instanceof StringType) {
Optional<String> match = resolveNumber(state.toString());
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) {
logger.debug("Number '{}' not found in phonebook '{}' from provider '{}'", state, phonebookName,
thingUID);
return accessory;
}
+ @Override
public Collection<Service> getServices() {
return this.services;
}
* return configuration attached to the root accessory, e.g. groupItem.
* Note: result will be casted to the type of the default value.
* The type for number is BigDecimal.
- *
+ *
* @param key configuration key
* @param defaultValue default value
* @param <T> expected type
* return configuration of the characteristic item, e.g. currentTemperature.
* Note: result will be casted to the type of the default value.
* The type for number is BigDecimal.
- *
+ *
* @param characteristicType characteristic type
* @param key configuration key
* @param defaultValue default value
* 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,
* replace the value.
- *
+ *
* @param characteristicType characteristicType to identify item
* @param map mapping to update
* @param customEnumList list to store custom state enumeration
/**
* takes item state as value and retrieves the key for that value from mapping.
* e.g. used to map StringItem value to HomeKit Enum
- *
+ *
* @param characteristicType characteristicType to identify item
* @param mapping mapping
* @param defaultValue default value if nothing found in mapping
@NonNullByDefault
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();
}
/**
* create boolean reader with ON state mapped to trueOnOffValue or trueOpenClosedValue depending of item type
- *
+ *
* @param characteristicType characteristic id
* @param trueOnOffValue ON value for switch
* @param trueOpenClosedValue ON value for contact
/**
* create boolean reader with default ON/OFF mapping considering inverted flag
- *
+ *
* @param characteristicType characteristic id
* @return boolean reader
* @throws IncompleteAccessoryException
if (state instanceof DecimalType) {
lockState = LockCurrentStateEnum.fromCode(((DecimalType) state).intValue());
} else if (state instanceof OnOffType) {
- lockState = state == securedState ? LockCurrentStateEnum.SECURED : LockCurrentStateEnum.UNSECURED;
+ lockState = state.equals(securedState) ? LockCurrentStateEnum.SECURED : LockCurrentStateEnum.UNSECURED;
}
}
return CompletableFuture.completedFuture(lockState);