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 * @return the desired result
*/ */
public ConfigDescriptionParameterGroup build() throws IllegalArgumentException { public ConfigDescriptionParameterGroup build() throws IllegalArgumentException {
return new ConfigDescriptionParameterGroup(name, context, advanced != null ? advanced : false, label, return new ConfigDescriptionParameterGroup(name, context, advanced != null && advanced, label, description);
description);
} }
} }

View File

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

View File

@ -41,7 +41,7 @@ public abstract class BaseAddonFinder implements AddonFinder {
protected static boolean propertyMatches(Map<String, Pattern> propertyPatternMap, String propertyName, protected static boolean propertyMatches(Map<String, Pattern> propertyPatternMap, String propertyName,
@Nullable String propertyValue) { @Nullable String propertyValue) {
Pattern pattern = propertyPatternMap.get(propertyName); 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(); protected volatile List<AddonInfo> addonCandidates = List.of();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -169,8 +169,7 @@ public class StateDescriptionFragmentImpl implements StateDescriptionFragment {
return null; return null;
} }
final Boolean ro = readOnly; final Boolean ro = readOnly;
return new StateDescriptionImpl(minimum, maximum, step, pattern, ro == null ? false : ro.booleanValue(), return new StateDescriptionImpl(minimum, maximum, step, pattern, ro != null && ro.booleanValue(), options);
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."); "Please either set the environment variable ${OPENHAB_USERDATA} or provide a directory through the --dir option.");
System.exit(0); System.exit(0);
} else { } else {
boolean force = commandLine.hasOption(OPT_FORCE) ? true : false; boolean force = commandLine.hasOption(OPT_FORCE);
Upgrader upgrader = new Upgrader(baseDir, force); Upgrader upgrader = new Upgrader(baseDir, force);
if (!commandLine.hasOption(OPT_COMMAND) if (!commandLine.hasOption(OPT_COMMAND)