mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-10 21:31:53 +01:00
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:
parent
8d6d650d2e
commit
4895977966
@ -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;
|
||||
|
@ -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("[ ");
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user