Use isEmpty() instead of "size() == 0" (#1151)

isEmpty() expresses the intent more clearly and is therefore preferred.
Counting the number of elements can also be an expensive operation e.g. when using linked lists.

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2019-10-20 01:27:11 +02:00 committed by Kai Kreuzer
parent 8d6d650d2e
commit 4895977966
9 changed files with 14 additions and 14 deletions

View File

@ -1140,7 +1140,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
*/
private boolean calculateConditions(WrappedRule rule) {
List<WrappedCondition> conditions = rule.getConditions();
if (conditions.size() == 0) {
if (conditions.isEmpty()) {
return true;
}
final String ruleUID = rule.getUID();
@ -1171,7 +1171,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
private void executeActions(WrappedRule rule, boolean stopOnFirstFail) {
final String ruleUID = rule.getUID();
final Collection<WrappedAction> actions = rule.getActions();
if (actions.size() == 0) {
if (actions.isEmpty()) {
return;
}
RuleStatus ruleStatus = null;

View File

@ -537,7 +537,7 @@ public class Printer {
* @return a formated string, representing the set of {@link Input}s or {@link Output}s or {@link Input}s.
*/
private static String getTagsRecord(Set<String> tags) {
if (tags == null || tags.size() == 0) {
if (tags == null || tags.isEmpty()) {
return "[ ]";
}
StringBuilder res = new StringBuilder().append("[ ");

View File

@ -50,7 +50,7 @@ public class WatchServiceUtil {
synchronized (WATCH_SERVICES) {
Map<String, AutomationWatchService> watchers = WATCH_SERVICES.get(provider);
aws = watchers.remove(watchingDir);
if (watchers.size() == 0) {
if (watchers.isEmpty()) {
WATCH_SERVICES.remove(provider);
}
}

View File

@ -55,7 +55,7 @@ public abstract class AbstractActiveBinding<P extends BindingProvider> extends A
// if there are no binding providers there is no need to run this
// refresh thread any longer ...
if (this.providers.size() == 0) {
if (this.providers.isEmpty()) {
activeService.deactivate();
}
}

View File

@ -146,7 +146,7 @@ public class ConfigUtil {
* @throws IllegalArgumentException if the type of the normalized values differ or an invalid type has been given
*/
private static Collection<Object> normalizeCollection(Collection<?> collection) throws IllegalArgumentException {
if (collection.size() == 0) {
if (collection.isEmpty()) {
return Collections.emptyList();
} else {
final List<Object> lst = new ArrayList<>(collection.size());

View File

@ -120,7 +120,7 @@ public class ProfileTypeResource implements RESTResource {
private boolean profileTypeMatchesItemType(ProfileType pt, String itemType) {
Collection<String> supportedItemTypesOnProfileType = pt.getSupportedItemTypes();
if (supportedItemTypesOnProfileType.size() == 0
if (supportedItemTypesOnProfileType.isEmpty()
|| supportedItemTypesOnProfileType.contains(ItemUtil.getMainItemType(itemType))
|| supportedItemTypesOnProfileType.contains(itemType)) {
return true;
@ -132,7 +132,7 @@ public class ProfileTypeResource implements RESTResource {
if (profileType instanceof TriggerProfileType) {
TriggerProfileType triggerProfileType = (TriggerProfileType) profileType;
if (triggerProfileType.getSupportedChannelTypeUIDs().size() == 0) {
if (triggerProfileType.getSupportedChannelTypeUIDs().isEmpty()) {
return true;
}
@ -147,7 +147,7 @@ public class ProfileTypeResource implements RESTResource {
if (profileType instanceof StateProfileType) {
StateProfileType stateProfileType = (StateProfileType) profileType;
if (stateProfileType.getSupportedItemTypesOfChannel().size() == 0) {
if (stateProfileType.getSupportedItemTypesOfChannel().isEmpty()) {
return true;
}

View File

@ -372,7 +372,7 @@ public class DefaultChartProvider implements ChartProvider {
// Add the new series to the chart - only if there's data elements to display
// The chart engine will throw an exception if there's no data
if (xData.size() == 0) {
if (xData.isEmpty()) {
return false;
}

View File

@ -623,7 +623,7 @@ public class ItemUIRegistryImpl implements ItemUIRegistry {
}
} else if (w instanceof Switch) {
Switch sw = (Switch) w;
if (sw.getMappings().size() == 0) {
if (sw.getMappings().isEmpty()) {
returnState = itemState.as(OnOffType.class);
}
}
@ -1084,7 +1084,7 @@ public class ItemUIRegistryImpl implements ItemUIRegistry {
if (colorList == null) {
return null;
}
if (colorList.size() == 0) {
if (colorList.isEmpty()) {
return null;
}
@ -1167,7 +1167,7 @@ public class ItemUIRegistryImpl implements ItemUIRegistry {
if (ruleList == null) {
return true;
}
if (ruleList.size() == 0) {
if (ruleList.isEmpty()) {
return true;
}

View File

@ -58,7 +58,7 @@ public final class ExpressionCardinality extends Expression {
break;
}
}
if (!(atLeastOne && nodes.size() == 0)) {
if (!(atLeastOne && nodes.isEmpty())) {
node.setChildren(nodes.toArray(new ASTNode[0]));
node.setRemainingTokens(list);
node.setSuccess(true);