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>pull/1160/head
parent
8d6d650d2e
commit
4895977966
|
@ -1140,7 +1140,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
||||||
*/
|
*/
|
||||||
private boolean calculateConditions(WrappedRule rule) {
|
private boolean calculateConditions(WrappedRule rule) {
|
||||||
List<WrappedCondition> conditions = rule.getConditions();
|
List<WrappedCondition> conditions = rule.getConditions();
|
||||||
if (conditions.size() == 0) {
|
if (conditions.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final String ruleUID = rule.getUID();
|
final String ruleUID = rule.getUID();
|
||||||
|
@ -1171,7 +1171,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
||||||
private void executeActions(WrappedRule rule, boolean stopOnFirstFail) {
|
private void executeActions(WrappedRule rule, boolean stopOnFirstFail) {
|
||||||
final String ruleUID = rule.getUID();
|
final String ruleUID = rule.getUID();
|
||||||
final Collection<WrappedAction> actions = rule.getActions();
|
final Collection<WrappedAction> actions = rule.getActions();
|
||||||
if (actions.size() == 0) {
|
if (actions.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RuleStatus ruleStatus = null;
|
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.
|
* @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) {
|
private static String getTagsRecord(Set<String> tags) {
|
||||||
if (tags == null || tags.size() == 0) {
|
if (tags == null || tags.isEmpty()) {
|
||||||
return "[ ]";
|
return "[ ]";
|
||||||
}
|
}
|
||||||
StringBuilder res = new StringBuilder().append("[ ");
|
StringBuilder res = new StringBuilder().append("[ ");
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class WatchServiceUtil {
|
||||||
synchronized (WATCH_SERVICES) {
|
synchronized (WATCH_SERVICES) {
|
||||||
Map<String, AutomationWatchService> watchers = WATCH_SERVICES.get(provider);
|
Map<String, AutomationWatchService> watchers = WATCH_SERVICES.get(provider);
|
||||||
aws = watchers.remove(watchingDir);
|
aws = watchers.remove(watchingDir);
|
||||||
if (watchers.size() == 0) {
|
if (watchers.isEmpty()) {
|
||||||
WATCH_SERVICES.remove(provider);
|
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
|
// if there are no binding providers there is no need to run this
|
||||||
// refresh thread any longer ...
|
// refresh thread any longer ...
|
||||||
if (this.providers.size() == 0) {
|
if (this.providers.isEmpty()) {
|
||||||
activeService.deactivate();
|
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
|
* @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 {
|
private static Collection<Object> normalizeCollection(Collection<?> collection) throws IllegalArgumentException {
|
||||||
if (collection.size() == 0) {
|
if (collection.isEmpty()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
} else {
|
} else {
|
||||||
final List<Object> lst = new ArrayList<>(collection.size());
|
final List<Object> lst = new ArrayList<>(collection.size());
|
||||||
|
|
|
@ -120,7 +120,7 @@ public class ProfileTypeResource implements RESTResource {
|
||||||
|
|
||||||
private boolean profileTypeMatchesItemType(ProfileType pt, String itemType) {
|
private boolean profileTypeMatchesItemType(ProfileType pt, String itemType) {
|
||||||
Collection<String> supportedItemTypesOnProfileType = pt.getSupportedItemTypes();
|
Collection<String> supportedItemTypesOnProfileType = pt.getSupportedItemTypes();
|
||||||
if (supportedItemTypesOnProfileType.size() == 0
|
if (supportedItemTypesOnProfileType.isEmpty()
|
||||||
|| supportedItemTypesOnProfileType.contains(ItemUtil.getMainItemType(itemType))
|
|| supportedItemTypesOnProfileType.contains(ItemUtil.getMainItemType(itemType))
|
||||||
|| supportedItemTypesOnProfileType.contains(itemType)) {
|
|| supportedItemTypesOnProfileType.contains(itemType)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -132,7 +132,7 @@ public class ProfileTypeResource implements RESTResource {
|
||||||
if (profileType instanceof TriggerProfileType) {
|
if (profileType instanceof TriggerProfileType) {
|
||||||
TriggerProfileType triggerProfileType = (TriggerProfileType) profileType;
|
TriggerProfileType triggerProfileType = (TriggerProfileType) profileType;
|
||||||
|
|
||||||
if (triggerProfileType.getSupportedChannelTypeUIDs().size() == 0) {
|
if (triggerProfileType.getSupportedChannelTypeUIDs().isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ public class ProfileTypeResource implements RESTResource {
|
||||||
if (profileType instanceof StateProfileType) {
|
if (profileType instanceof StateProfileType) {
|
||||||
StateProfileType stateProfileType = (StateProfileType) profileType;
|
StateProfileType stateProfileType = (StateProfileType) profileType;
|
||||||
|
|
||||||
if (stateProfileType.getSupportedItemTypesOfChannel().size() == 0) {
|
if (stateProfileType.getSupportedItemTypesOfChannel().isEmpty()) {
|
||||||
return true;
|
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
|
// 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
|
// The chart engine will throw an exception if there's no data
|
||||||
if (xData.size() == 0) {
|
if (xData.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -623,7 +623,7 @@ public class ItemUIRegistryImpl implements ItemUIRegistry {
|
||||||
}
|
}
|
||||||
} else if (w instanceof Switch) {
|
} else if (w instanceof Switch) {
|
||||||
Switch sw = (Switch) w;
|
Switch sw = (Switch) w;
|
||||||
if (sw.getMappings().size() == 0) {
|
if (sw.getMappings().isEmpty()) {
|
||||||
returnState = itemState.as(OnOffType.class);
|
returnState = itemState.as(OnOffType.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1084,7 +1084,7 @@ public class ItemUIRegistryImpl implements ItemUIRegistry {
|
||||||
if (colorList == null) {
|
if (colorList == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (colorList.size() == 0) {
|
if (colorList.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1167,7 +1167,7 @@ public class ItemUIRegistryImpl implements ItemUIRegistry {
|
||||||
if (ruleList == null) {
|
if (ruleList == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (ruleList.size() == 0) {
|
if (ruleList.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ public final class ExpressionCardinality extends Expression {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!(atLeastOne && nodes.size() == 0)) {
|
if (!(atLeastOne && nodes.isEmpty())) {
|
||||||
node.setChildren(nodes.toArray(new ASTNode[0]));
|
node.setChildren(nodes.toArray(new ASTNode[0]));
|
||||||
node.setRemainingTokens(list);
|
node.setRemainingTokens(list);
|
||||||
node.setSuccess(true);
|
node.setSuccess(true);
|
||||||
|
|
Loading…
Reference in New Issue