Simplify boolean expressions (#3971)

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2023-12-28 13:19:01 +01:00 committed by GitHub
parent ba5647b871
commit f376606e92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 12 additions and 14 deletions

View File

@ -94,7 +94,6 @@ public class ConfigDescriptionParameterGroupBuilder {
* @return the desired result
*/
public ConfigDescriptionParameterGroup build() throws IllegalArgumentException {
return new ConfigDescriptionParameterGroup(name, context, advanced != null ? advanced : false, label,
description);
return new ConfigDescriptionParameterGroup(name, context, advanced != null && advanced, label, description);
}
}

View File

@ -91,6 +91,6 @@ public class ConfigurableServiceUtil {
private static boolean resolveBoolean(Function<String, @Nullable Object> propertyResolver, String key) {
Boolean value = (Boolean) propertyResolver.apply(key);
return value == null ? false : value.booleanValue();
return value != null && value.booleanValue();
}
}

View File

@ -88,7 +88,7 @@ public class ConfigDescriptionParameterConverter extends GenericUnmarshaller<Con
}
private Boolean falseIfNull(@Nullable Boolean b) {
return b != null ? b : false;
return b != null && b;
}
@Override

View File

@ -41,7 +41,7 @@ public abstract class BaseAddonFinder implements AddonFinder {
protected static boolean propertyMatches(Map<String, Pattern> propertyPatternMap, String propertyName,
@Nullable String propertyValue) {
Pattern pattern = propertyPatternMap.get(propertyName);
return pattern == null ? true : propertyValue == null ? false : pattern.matcher(propertyValue).matches();
return pattern == null || (propertyValue != null && pattern.matcher(propertyValue).matches());
}
protected volatile List<AddonInfo> addonCandidates = List.of();

View File

@ -105,8 +105,8 @@ public class ModbusSlaveConnectionFactoryImpl
long reconnectAfterMillis = configuration.getReconnectAfterMillis();
long connectionAgeMillis = System.currentTimeMillis() - localLastConnected;
long disconnectIfConnectedBeforeMillis = disconnectIfConnectedBefore.getOrDefault(localEndpoint, -1L);
boolean disconnectSinceTooOldConnection = disconnectIfConnectedBeforeMillis < 0L ? false
: localLastConnected <= disconnectIfConnectedBeforeMillis;
boolean disconnectSinceTooOldConnection = disconnectIfConnectedBeforeMillis >= 0L
&& localLastConnected <= disconnectIfConnectedBeforeMillis;
boolean shouldBeDisconnected = (reconnectAfterMillis == 0
|| (reconnectAfterMillis > 0 && connectionAgeMillis > reconnectAfterMillis)
|| disconnectSinceTooOldConnection);

View File

@ -164,7 +164,7 @@ public class NumberExtensions {
BigDecimal leftValue = numberToBigDecimal(left);
BigDecimal rightValue = numberToBigDecimal(right);
if (leftValue == null) {
return (rightValue != null) ? false : true;
return rightValue == null;
} else if (rightValue == null) {
return true;
} else {

View File

@ -33,7 +33,7 @@ public class PersistenceEqualsFilter extends PersistenceFilter {
public PersistenceEqualsFilter(String name, Collection<String> values, @Nullable Boolean inverted) {
super(name);
this.values = values;
this.inverted = (inverted == null) ? false : inverted;
this.inverted = inverted != null && inverted;
}
public Collection<String> getValues() {

View File

@ -45,7 +45,7 @@ public class PersistenceIncludeFilter extends PersistenceFilter {
this.lower = lower;
this.upper = upper;
this.unit = (unit == null) ? "" : unit;
this.inverted = (inverted == null) ? false : inverted;
this.inverted = inverted != null && inverted;
}
public BigDecimal getLower() {

View File

@ -53,7 +53,7 @@ public class PersistenceThresholdFilter extends PersistenceFilter {
super(name);
this.value = value;
this.unit = (unit == null) ? "" : unit;
this.relative = (relative == null) ? false : relative;
this.relative = relative != null && relative;
}
public BigDecimal getValue() {

View File

@ -169,8 +169,7 @@ public class StateDescriptionFragmentImpl implements StateDescriptionFragment {
return null;
}
final Boolean ro = readOnly;
return new StateDescriptionImpl(minimum, maximum, step, pattern, ro == null ? false : ro.booleanValue(),
options);
return new StateDescriptionImpl(minimum, maximum, step, pattern, ro != null && ro.booleanValue(), options);
}
/**

View File

@ -71,7 +71,7 @@ public class UpgradeTool {
"Please either set the environment variable ${OPENHAB_USERDATA} or provide a directory through the --dir option.");
System.exit(0);
} else {
boolean force = commandLine.hasOption(OPT_FORCE) ? true : false;
boolean force = commandLine.hasOption(OPT_FORCE);
Upgrader upgrader = new Upgrader(baseDir, force);
if (!commandLine.hasOption(OPT_COMMAND)