Commit 9eaaa91d authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by Ian Hickson

use isEmpty and isNotEmpty (#7207)

parent 778b30ac
...@@ -39,7 +39,7 @@ class Expression extends EquationMember { ...@@ -39,7 +39,7 @@ class Expression extends EquationMember {
Expression asExpression() => this; Expression asExpression() => this;
@override @override
bool get isConstant => terms.length == 0; bool get isConstant => terms.isEmpty;
@override @override
double get value => terms.fold(constant, (double value, Term term) => value + term.value); double get value => terms.fold(constant, (double value, Term term) => value + term.value);
......
...@@ -773,7 +773,7 @@ class Solver { ...@@ -773,7 +773,7 @@ class Solver {
} }
Result _dualOptimize() { Result _dualOptimize() {
while (_infeasibleRows.length != 0) { while (_infeasibleRows.isNotEmpty) {
_Symbol leaving = _infeasibleRows.removeLast(); _Symbol leaving = _infeasibleRows.removeLast();
_Row row = _rows[leaving]; _Row row = _rows[leaving];
......
...@@ -62,12 +62,12 @@ void _debugPrintTask() { ...@@ -62,12 +62,12 @@ void _debugPrintTask() {
_debugPrintStopwatch.reset(); _debugPrintStopwatch.reset();
_debugPrintedCharacters = 0; _debugPrintedCharacters = 0;
} }
while (_debugPrintedCharacters < _kDebugPrintCapacity && _debugPrintBuffer.length > 0) { while (_debugPrintedCharacters < _kDebugPrintCapacity && _debugPrintBuffer.isNotEmpty) {
String line = _debugPrintBuffer.removeFirst(); String line = _debugPrintBuffer.removeFirst();
_debugPrintedCharacters += line.length; // TODO(ianh): Use the UTF-8 byte length instead _debugPrintedCharacters += line.length; // TODO(ianh): Use the UTF-8 byte length instead
print(line); print(line);
} }
if (_debugPrintBuffer.length > 0) { if (_debugPrintBuffer.isNotEmpty) {
_debugPrintScheduled = true; _debugPrintScheduled = true;
_debugPrintedCharacters = 0; _debugPrintedCharacters = 0;
new Timer(_kDebugPrintPauseTime, _debugPrintTask); new Timer(_kDebugPrintPauseTime, _debugPrintTask);
......
...@@ -259,7 +259,7 @@ class DataTable extends StatelessWidget { ...@@ -259,7 +259,7 @@ class DataTable extends StatelessWidget {
}) : columns = columns, }) : columns = columns,
_onlyTextColumn = _initOnlyTextColumn(columns), super(key: key) { _onlyTextColumn = _initOnlyTextColumn(columns), super(key: key) {
assert(columns != null); assert(columns != null);
assert(columns.length > 0); assert(columns.isNotEmpty);
assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length)); assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length));
assert(sortAscending != null); assert(sortAscending != null);
assert(rows != null); assert(rows != null);
......
...@@ -100,7 +100,7 @@ class IconThemeData { ...@@ -100,7 +100,7 @@ class IconThemeData {
result.add('opacity: $_opacity'); result.add('opacity: $_opacity');
if (size != null) if (size != null)
result.add('size: $size'); result.add('size: $size');
if (result.length == 0) if (result.isEmpty)
return '<no theme>'; return '<no theme>';
return result.join(', '); return result.join(', ');
} }
......
...@@ -69,7 +69,7 @@ class PaginatedDataTable extends StatefulWidget { ...@@ -69,7 +69,7 @@ class PaginatedDataTable extends StatefulWidget {
}) : super(key: key) { }) : super(key: key) {
assert(header != null); assert(header != null);
assert(columns != null); assert(columns != null);
assert(columns.length > 0); assert(columns.isNotEmpty);
assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length)); assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length));
assert(sortAscending != null); assert(sortAscending != null);
assert(rowsPerPage != null); assert(rowsPerPage != null);
......
...@@ -445,7 +445,7 @@ Future<dynamic/*=T*/> showMenu/*<T>*/({ ...@@ -445,7 +445,7 @@ Future<dynamic/*=T*/> showMenu/*<T>*/({
int elevation: 8 int elevation: 8
}) { }) {
assert(context != null); assert(context != null);
assert(items != null && items.length > 0); assert(items != null && items.isNotEmpty);
return Navigator.push(context, new _PopupMenuRoute<dynamic/*=T*/>( return Navigator.push(context, new _PopupMenuRoute<dynamic/*=T*/>(
position: position, position: position,
items: items, items: items,
......
...@@ -930,7 +930,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin { ...@@ -930,7 +930,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
if (!config.resizeToAvoidBottomPadding) if (!config.resizeToAvoidBottomPadding)
padding = new EdgeInsets.fromLTRB(padding.left, padding.top, padding.right, 0.0); padding = new EdgeInsets.fromLTRB(padding.left, padding.top, padding.right, 0.0);
if (_snackBars.length > 0) { if (_snackBars.isNotEmpty) {
final ModalRoute<dynamic> route = ModalRoute.of(context); final ModalRoute<dynamic> route = ModalRoute.of(context);
if (route == null || route.isCurrent) { if (route == null || route.isCurrent) {
if (_snackBarController.isCompleted && _snackBarTimer == null) if (_snackBarController.isCompleted && _snackBarTimer == null)
......
...@@ -476,7 +476,7 @@ class TabBarSelection<T> extends StatefulWidget { ...@@ -476,7 +476,7 @@ class TabBarSelection<T> extends StatefulWidget {
this.onChanged, this.onChanged,
@required this.child @required this.child
}) : super(key: key) { }) : super(key: key) {
assert(values != null && values.length > 0); assert(values != null && values.isNotEmpty);
assert(new Set<T>.from(values).length == values.length); assert(new Set<T>.from(values).length == values.length);
assert(value == null ? true : values.where((T e) => e == value).length == 1); assert(value == null ? true : values.where((T e) => e == value).length == 1);
assert(child != null); assert(child != null);
...@@ -847,7 +847,7 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect ...@@ -847,7 +847,7 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect
@override @override
void handleStatusChange(AnimationStatus status) { void handleStatusChange(AnimationStatus status) {
if (config.labels.length == 0) if (config.labels.isEmpty)
return; return;
if (_valueIsChanging && status == AnimationStatus.completed) { if (_valueIsChanging && status == AnimationStatus.completed) {
...@@ -861,7 +861,7 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect ...@@ -861,7 +861,7 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect
@override @override
void handleProgressChange() { void handleProgressChange() {
if (config.labels.length == 0 || _selection == null) if (config.labels.isEmpty || _selection == null)
return; return;
if (_lastSelectedIndex != _selection.index) { if (_lastSelectedIndex != _selection.index) {
......
...@@ -380,7 +380,7 @@ class BoxConstraints extends Constraints { ...@@ -380,7 +380,7 @@ class BoxConstraints extends Constraints {
affectedFieldsList.add('minHeight'); affectedFieldsList.add('minHeight');
if (maxHeight.isNaN) if (maxHeight.isNaN)
affectedFieldsList.add('maxHeight'); affectedFieldsList.add('maxHeight');
assert(affectedFieldsList.length > 0); assert(affectedFieldsList.isNotEmpty);
if (affectedFieldsList.length > 1) if (affectedFieldsList.length > 1)
affectedFieldsList.add('and ${affectedFieldsList.removeLast()}'); affectedFieldsList.add('and ${affectedFieldsList.removeLast()}');
String whichFields = ''; String whichFields = '';
......
...@@ -1022,7 +1022,7 @@ class PipelineOwner { ...@@ -1022,7 +1022,7 @@ class PipelineOwner {
if (node._needsPaint && node.owner == this) if (node._needsPaint && node.owner == this)
PaintingContext.repaintCompositedChild(node); PaintingContext.repaintCompositedChild(node);
} }
assert(_nodesNeedingPaint.length == 0); assert(_nodesNeedingPaint.isEmpty);
} finally { } finally {
_debugDoingPaint = false; _debugDoingPaint = false;
Timeline.finishSync(); Timeline.finishSync();
......
...@@ -492,7 +492,7 @@ class RenderTable extends RenderBox { ...@@ -492,7 +492,7 @@ class RenderTable extends RenderBox {
assert(rows == null || children == null); assert(rows == null || children == null);
assert(defaultColumnWidth != null); assert(defaultColumnWidth != null);
assert(configuration != null); assert(configuration != null);
_columns = columns ?? (children != null && children.length > 0 ? children.first.length : 0); _columns = columns ?? (children != null && children.isNotEmpty ? children.first.length : 0);
_rows = rows ?? 0; _rows = rows ?? 0;
_children = new List<RenderBox>()..length = _columns * _rows; _children = new List<RenderBox>()..length = _columns * _rows;
_columnWidths = columnWidths ?? new HashMap<int, TableColumnWidth>(); _columnWidths = columnWidths ?? new HashMap<int, TableColumnWidth>();
...@@ -691,10 +691,10 @@ class RenderTable extends RenderBox { ...@@ -691,10 +691,10 @@ class RenderTable extends RenderBox {
return; return;
assert(columns >= 0); assert(columns >= 0);
// consider the case of a newly empty table // consider the case of a newly empty table
if (columns == 0 || cells.length == 0) { if (columns == 0 || cells.isEmpty) {
assert(cells == null || cells.length == 0); assert(cells == null || cells.isEmpty);
_columns = columns; _columns = columns;
if (_children.length == 0) { if (_children.isEmpty) {
assert(_rows == 0); assert(_rows == 0);
return; return;
} }
...@@ -757,7 +757,7 @@ class RenderTable extends RenderBox { ...@@ -757,7 +757,7 @@ class RenderTable extends RenderBox {
dropChild(oldChild); dropChild(oldChild);
} }
_children.clear(); _children.clear();
_columns = cells.length > 0 ? cells.first.length : 0; _columns = cells.isNotEmpty ? cells.first.length : 0;
_rows = 0; _rows = 0;
for (List<RenderBox> row in cells) for (List<RenderBox> row in cells)
addRow(row); addRow(row);
...@@ -1282,7 +1282,7 @@ class RenderTable extends RenderBox { ...@@ -1282,7 +1282,7 @@ class RenderTable extends RenderBox {
super.debugFillDescription(description); super.debugFillDescription(description);
if (border != null) if (border != null)
description.add('border: $border'); description.add('border: $border');
if (_columnWidths.length > 0) if (_columnWidths.isNotEmpty)
description.add('specified column widths: $_columnWidths'); description.add('specified column widths: $_columnWidths');
description.add('default column width: $defaultColumnWidth'); description.add('default column width: $defaultColumnWidth');
description.add('table size: $columns\u00D7$rows'); description.add('table size: $columns\u00D7$rows');
......
...@@ -2365,7 +2365,7 @@ abstract class Element implements BuildContext { ...@@ -2365,7 +2365,7 @@ abstract class Element implements BuildContext {
assert(widget != null); assert(widget != null);
assert(depth != null); assert(depth != null);
assert(_active); assert(_active);
if (_dependencies != null && _dependencies.length > 0) { if (_dependencies != null && _dependencies.isNotEmpty) {
for (InheritedElement dependency in _dependencies) for (InheritedElement dependency in _dependencies)
dependency._dependents.remove(this); dependency._dependents.remove(this);
// For expediency, we don't actually clear the list here, even though it's // For expediency, we don't actually clear the list here, even though it's
...@@ -2629,7 +2629,7 @@ abstract class Element implements BuildContext { ...@@ -2629,7 +2629,7 @@ abstract class Element implements BuildContext {
String result = '$prefixLineOne$this\n'; String result = '$prefixLineOne$this\n';
List<Element> children = <Element>[]; List<Element> children = <Element>[];
visitChildren(children.add); visitChildren(children.add);
if (children.length > 0) { if (children.isNotEmpty) {
Element last = children.removeLast(); Element last = children.removeLast();
for (Element child in children) for (Element child in children)
result += '${child.toStringDeep("$prefixOtherLines\u251C", "$prefixOtherLines\u2502")}'; result += '${child.toStringDeep("$prefixOtherLines\u251C", "$prefixOtherLines\u2502")}';
...@@ -2803,7 +2803,7 @@ abstract class BuildableElement extends Element { ...@@ -2803,7 +2803,7 @@ abstract class BuildableElement extends Element {
@override @override
void activate() { void activate() {
final bool hadDependencies = ((_dependencies != null && _dependencies.length > 0) || _hadUnsatisfiedDependencies); final bool hadDependencies = ((_dependencies != null && _dependencies.isNotEmpty) || _hadUnsatisfiedDependencies);
super.activate(); // clears _dependencies, and sets active to true super.activate(); // clears _dependencies, and sets active to true
if (_dirty) { if (_dirty) {
if (_inDirtyList) { if (_inDirtyList) {
......
...@@ -432,7 +432,7 @@ class _HeroParty { ...@@ -432,7 +432,7 @@ class _HeroParty {
} }
void setAnimation(Animation<double> animation) { void setAnimation(Animation<double> animation) {
assert(animation != null || _heroes.length == 0); assert(animation != null || _heroes.isEmpty);
if (animation != _currentAnimation) { if (animation != _currentAnimation) {
_clearCurrentAnimation(); _clearCurrentAnimation();
_currentAnimation = animation; _currentAnimation = animation;
......
...@@ -644,7 +644,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin { ...@@ -644,7 +644,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
/// The only route that cannot be popped off the navigator is the initial /// The only route that cannot be popped off the navigator is the initial
/// route. /// route.
bool canPop() { bool canPop() {
assert(_history.length > 0); assert(_history.isNotEmpty);
return _history.length > 1 || _history[0].willHandlePopInternally; return _history.length > 1 || _history[0].willHandlePopInternally;
} }
......
...@@ -319,7 +319,7 @@ abstract class LocalHistoryRoute<T> extends Route<T> { ...@@ -319,7 +319,7 @@ abstract class LocalHistoryRoute<T> extends Route<T> {
@override @override
bool didPop(T result) { bool didPop(T result) {
if (_localHistory != null && _localHistory.length > 0) { if (_localHistory != null && _localHistory.isNotEmpty) {
LocalHistoryEntry entry = _localHistory.removeLast(); LocalHistoryEntry entry = _localHistory.removeLast();
assert(entry._owner == this); assert(entry._owner == this);
entry._owner = null; entry._owner = null;
...@@ -331,7 +331,7 @@ abstract class LocalHistoryRoute<T> extends Route<T> { ...@@ -331,7 +331,7 @@ abstract class LocalHistoryRoute<T> extends Route<T> {
@override @override
bool get willHandlePopInternally { bool get willHandlePopInternally {
return _localHistory != null && _localHistory.length > 0; return _localHistory != null && _localHistory.isNotEmpty;
} }
} }
......
...@@ -59,7 +59,7 @@ class TableRow { ...@@ -59,7 +59,7 @@ class TableRow {
result.write('$decoration, '); result.write('$decoration, ');
if (children == null) { if (children == null) {
result.write('child list is null'); result.write('child list is null');
} else if (children.length == 0) { } else if (children.isEmpty) {
result.write('no children'); result.write('no children');
} else { } else {
result.write('$children'); result.write('$children');
...@@ -137,7 +137,7 @@ class Table extends RenderObjectWidget { ...@@ -137,7 +137,7 @@ class Table extends RenderObjectWidget {
return true; return true;
}); });
assert(() { assert(() {
if (children.length > 0) { if (children.isNotEmpty) {
final int cellCount = children.first.children.length; final int cellCount = children.first.children.length;
if (children.any((TableRow row) => row.children.length != cellCount)) { if (children.any((TableRow row) => row.children.length != cellCount)) {
throw new FlutterError( throw new FlutterError(
...@@ -195,7 +195,7 @@ class Table extends RenderObjectWidget { ...@@ -195,7 +195,7 @@ class Table extends RenderObjectWidget {
@override @override
RenderTable createRenderObject(BuildContext context) { RenderTable createRenderObject(BuildContext context) {
return new RenderTable( return new RenderTable(
columns: children.length > 0 ? children[0].children.length : 0, columns: children.isNotEmpty ? children[0].children.length : 0,
rows: children.length, rows: children.length,
columnWidths: columnWidths, columnWidths: columnWidths,
defaultColumnWidth: defaultColumnWidth, defaultColumnWidth: defaultColumnWidth,
...@@ -209,7 +209,7 @@ class Table extends RenderObjectWidget { ...@@ -209,7 +209,7 @@ class Table extends RenderObjectWidget {
@override @override
void updateRenderObject(BuildContext context, RenderTable renderObject) { void updateRenderObject(BuildContext context, RenderTable renderObject) {
assert(renderObject.columns == (children.length > 0 ? children[0].children.length : 0)); assert(renderObject.columns == (children.isNotEmpty ? children[0].children.length : 0));
assert(renderObject.rows == children.length); assert(renderObject.rows == children.length);
renderObject renderObject
..columnWidths = columnWidths ..columnWidths = columnWidths
...@@ -318,7 +318,7 @@ class _TableElement extends RenderObjectElement { ...@@ -318,7 +318,7 @@ class _TableElement extends RenderObjectElement {
void _updateRenderObjectChildren() { void _updateRenderObjectChildren() {
assert(renderObject != null); assert(renderObject != null);
renderObject.setFlatChildren( renderObject.setFlatChildren(
_children.length > 0 ? _children[0].children.length : 0, _children.isNotEmpty ? _children[0].children.length : 0,
_children.expand((_TableElementRow row) => row.children.map((Element child) => child.renderObject)).toList() _children.expand((_TableElementRow row) => row.children.map((Element child) => child.renderObject)).toList()
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment