Index: sdk/lib/collection/queue.dart |
diff --git a/sdk/lib/collection/queue.dart b/sdk/lib/collection/queue.dart |
index b648bc58833426101b0cad1472721b4a340a9aba..72c4e959459752fea930646827888f70089d38cd 100644 |
--- a/sdk/lib/collection/queue.dart |
+++ b/sdk/lib/collection/queue.dart |
@@ -31,14 +31,16 @@ abstract class Queue<E> implements Iterable<E>, EfficientLength { |
factory Queue.from(Iterable<E> other) = ListQueue<E>.from; |
/** |
- * Removes and returns the first element of this queue. Throws an |
- * [StateError] exception if this queue is empty. |
+ * Removes and returns the first element of this queue. |
+ * |
+ * The queue must not be empty when this method is called. |
*/ |
E removeFirst(); |
/** |
- * Removes and returns the last element of the queue. Throws an |
- * [StateError] exception if this queue is empty. |
+ * Removes and returns the last element of the queue. |
+ * |
+ * The queue must not be empty when this method is called. |
*/ |
E removeLast(); |
@@ -162,7 +164,7 @@ class _DoubleLinkedQueueEntrySentinel<E> extends DoubleLinkedQueueEntry<E> { |
} |
E remove() { |
- throw new StateError("Empty queue"); |
+ throw IterableElementError.noElement(); |
} |
DoubleLinkedQueueEntry<E> _asNonSentinelEntry() { |
@@ -176,7 +178,7 @@ class _DoubleLinkedQueueEntrySentinel<E> extends DoubleLinkedQueueEntry<E> { |
} |
E get element { |
- throw new StateError("Empty queue"); |
+ throw IterableElementError.noElement(); |
} |
} |
@@ -279,11 +281,11 @@ class DoubleLinkedQueue<E> extends IterableBase<E> implements Queue<E> { |
} |
E get single { |
- // Note that this also covers the case where the queue is empty. |
+ // Note that this throws correctly if the queue is empty. |
if (identical(_sentinel._next, _sentinel._previous)) { |
return _sentinel._next.element; |
} |
- throw new StateError("More than one element"); |
+ throw IterableElementError.tooMany(); |
} |
DoubleLinkedQueueEntry<E> lastEntry() { |
@@ -317,7 +319,7 @@ class DoubleLinkedQueue<E> extends IterableBase<E> implements Queue<E> { |
return new _DoubleLinkedQueueIterator<E>(_sentinel); |
} |
- String toString() => _collectionToString(this, '{', '}'); |
+ String toString() => IterableBase.iterableToFullString(this, '{', '}'); |
} |
class _DoubleLinkedQueueIterator<E> implements Iterator<E> { |
@@ -409,18 +411,18 @@ class ListQueue<E> extends IterableBase<E> implements Queue<E> { |
int get length => (_tail - _head) & (_table.length - 1); |
E get first { |
- if (_head == _tail) throw new StateError("No elements"); |
+ if (_head == _tail) throw IterableElementError.noElement(); |
return _table[_head]; |
} |
E get last { |
- if (_head == _tail) throw new StateError("No elements"); |
+ if (_head == _tail) throw IterableElementError.noElement(); |
return _table[(_tail - 1) & (_table.length - 1)]; |
} |
E get single { |
- if (_head == _tail) throw new StateError("No elements"); |
- if (length > 1) throw new StateError("Too many elements"); |
+ if (_head == _tail) throw IterableElementError.noElement(); |
+ if (length > 1) throw IterableElementError.tooMany(); |
return _table[_head]; |
} |
@@ -536,7 +538,7 @@ class ListQueue<E> extends IterableBase<E> implements Queue<E> { |
} |
} |
- String toString() => _collectionToString(this, '{', '}'); |
+ String toString() => IterableBase.iterableToFullString(this, "{", "}"); |
// Queue interface. |
@@ -550,7 +552,7 @@ class ListQueue<E> extends IterableBase<E> implements Queue<E> { |
} |
E removeFirst() { |
- if (_head == _tail) throw new StateError("No elements"); |
+ if (_head == _tail) throw IterableElementError.noElement(); |
_modificationCount++; |
E result = _table[_head]; |
_table[_head] = null; |
@@ -559,7 +561,7 @@ class ListQueue<E> extends IterableBase<E> implements Queue<E> { |
} |
E removeLast() { |
- if (_head == _tail) throw new StateError("No elements"); |
+ if (_head == _tail) throw IterableElementError.noElement(); |
_modificationCount++; |
_tail = (_tail - 1) & (_table.length - 1); |
E result = _table[_tail]; |