Skip to content

Commit 881100e

Browse files
committed
WIP
1 parent 39e0fd0 commit 881100e

File tree

8 files changed

+30
-24
lines changed

8 files changed

+30
-24
lines changed

pkgs/collection/lib/src/boollist.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'unmodifiable_wrappers.dart' show NonGrowableListMixin;
1010
/// A space-efficient list of boolean values.
1111
///
1212
/// Uses list of integers as internal storage to reduce memory usage.
13-
abstract /*mixin*/ class BoolList with ListMixin<bool> {
13+
abstract final class BoolList with ListMixin<bool> {
1414
static const int _entryShift = 5;
1515

1616
static const int _bitsPerEntry = 32;
@@ -180,7 +180,7 @@ abstract /*mixin*/ class BoolList with ListMixin<bool> {
180180
}
181181
}
182182

183-
class _GrowableBoolList extends BoolList {
183+
final class _GrowableBoolList extends BoolList {
184184
static const int _growthFactor = 2;
185185

186186
_GrowableBoolList._withCapacity(int length, int capacity)
@@ -228,7 +228,8 @@ class _GrowableBoolList extends BoolList {
228228
}
229229
}
230230

231-
class _NonGrowableBoolList extends BoolList with NonGrowableListMixin<bool> {
231+
final class _NonGrowableBoolList extends BoolList
232+
with NonGrowableListMixin<bool> {
232233
_NonGrowableBoolList._withCapacity(int length, int capacity)
233234
: super._(
234235
Uint32List(BoolList._lengthInWords(capacity)),

pkgs/collection/lib/src/canonicalized_map.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'dart:collection';
1010
/// more efficient than a [LinkedHashMap] with a custom equality operator
1111
/// because it only canonicalizes each key once, rather than doing so for each
1212
/// comparison.
13-
class CanonicalizedMap<C, K, V> implements Map<K, V> {
13+
final class CanonicalizedMap<C, K, V> implements Map<K, V> {
1414
final C Function(K) _canonicalize;
1515

1616
final bool Function(K)? _isValidKeyFn;

pkgs/collection/lib/src/combined_wrappers/combined_iterable.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'combined_iterator.dart';
1313
/// lazily accessing individual iterable instances. This means that if the
1414
/// underlying iterables change, the [CombinedIterableView] will reflect those
1515
/// changes.
16-
class CombinedIterableView<T> extends IterableBase<T> {
16+
final class CombinedIterableView<T> extends IterableBase<T> {
1717
/// The iterables that this combines.
1818
final Iterable<Iterable<T>> _iterables;
1919

pkgs/collection/lib/src/combined_wrappers/combined_iterator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/// The iterator for `CombinedIterableView` and `CombinedListView`.
66
///
77
/// Moves through each iterable's iterator in sequence.
8-
class CombinedIterator<T> implements Iterator<T> {
8+
final class CombinedIterator<T> implements Iterator<T> {
99
/// The iterators that this combines, or `null` if done iterating.
1010
///
1111
/// Because this comes from a call to [Iterable.map], it's lazy and will

pkgs/collection/lib/src/equality.dart

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'comparators.dart';
99
const int _hashMask = 0x7fffffff;
1010

1111
/// A generic equality relation on objects.
12-
abstract class Equality<E> {
12+
abstract interface class Equality<E> {
1313
const factory Equality() = DefaultEquality<E>;
1414

1515
/// Compare two elements for being equal.
@@ -46,7 +46,7 @@ abstract class Equality<E> {
4646
///
4747
/// It's also possible to pass an additional equality instance that should be
4848
/// used to compare the value itself.
49-
class EqualityBy<E, F> implements Equality<E> {
49+
final class EqualityBy<E, F> implements Equality<E> {
5050
final F Function(E) _comparisonKey;
5151

5252
final Equality<F> _inner;
@@ -81,7 +81,7 @@ class EqualityBy<E, F> implements Equality<E> {
8181
/// Note that [equals] and [hash] take `Object`s rather than `E`s. This allows
8282
/// `E` to be inferred as `Null` in const contexts where `E` wouldn't be a
8383
/// compile-time constant, while still allowing the class to be used at runtime.
84-
class DefaultEquality<E> implements Equality<E> {
84+
final class DefaultEquality<E> implements Equality<E> {
8585
const DefaultEquality();
8686
@override
8787
bool equals(Object? e1, Object? e2) => e1 == e2;
@@ -92,7 +92,7 @@ class DefaultEquality<E> implements Equality<E> {
9292
}
9393

9494
/// Equality of objects that compares only the identity of the objects.
95-
class IdentityEquality<E> implements Equality<E> {
95+
final class IdentityEquality<E> implements Equality<E> {
9696
const IdentityEquality();
9797
@override
9898
bool equals(E e1, E e2) => identical(e1, e2);
@@ -109,7 +109,7 @@ class IdentityEquality<E> implements Equality<E> {
109109
/// The [equals] and [hash] methods accepts `null` values,
110110
/// even if the [isValidKey] returns `false` for `null`.
111111
/// The [hash] of `null` is `null.hashCode`.
112-
class IterableEquality<E> implements Equality<Iterable<E>> {
112+
final class IterableEquality<E> implements Equality<Iterable<E>> {
113113
final Equality<E?> _elementEquality;
114114
const IterableEquality(
115115
[Equality<E> elementEquality = const DefaultEquality<Never>()])
@@ -161,7 +161,7 @@ class IterableEquality<E> implements Equality<Iterable<E>> {
161161
/// The [equals] and [hash] methods accepts `null` values,
162162
/// even if the [isValidKey] returns `false` for `null`.
163163
/// The [hash] of `null` is `null.hashCode`.
164-
class ListEquality<E> implements Equality<List<E>> {
164+
final class ListEquality<E> implements Equality<List<E>> {
165165
final Equality<E> _elementEquality;
166166
const ListEquality(
167167
[Equality<E> elementEquality = const DefaultEquality<Never>()])
@@ -202,7 +202,7 @@ class ListEquality<E> implements Equality<List<E>> {
202202
bool isValidKey(Object? o) => o is List<E>;
203203
}
204204

205-
abstract class _UnorderedEquality<E, T extends Iterable<E>>
205+
abstract final class _UnorderedEquality<E, T extends Iterable<E>>
206206
implements Equality<T> {
207207
final Equality<E> _elementEquality;
208208

@@ -251,7 +251,8 @@ abstract class _UnorderedEquality<E, T extends Iterable<E>>
251251
/// Two iterables are considered equal if they have the same number of elements,
252252
/// and the elements of one set can be paired with the elements
253253
/// of the other iterable, so that each pair are equal.
254-
class UnorderedIterableEquality<E> extends _UnorderedEquality<E, Iterable<E>> {
254+
final class UnorderedIterableEquality<E>
255+
extends _UnorderedEquality<E, Iterable<E>> {
255256
const UnorderedIterableEquality(
256257
[super.elementEquality = const DefaultEquality<Never>()]);
257258

@@ -271,7 +272,7 @@ class UnorderedIterableEquality<E> extends _UnorderedEquality<E, Iterable<E>> {
271272
/// The [equals] and [hash] methods accepts `null` values,
272273
/// even if the [isValidKey] returns `false` for `null`.
273274
/// The [hash] of `null` is `null.hashCode`.
274-
class SetEquality<E> extends _UnorderedEquality<E, Set<E>> {
275+
final class SetEquality<E> extends _UnorderedEquality<E, Set<E>> {
275276
const SetEquality([super.elementEquality = const DefaultEquality<Never>()]);
276277

277278
@override
@@ -282,7 +283,7 @@ class SetEquality<E> extends _UnorderedEquality<E, Set<E>> {
282283
///
283284
/// The class represents a map entry as a single object,
284285
/// using a combined hashCode and equality of the key and value.
285-
class _MapEntry {
286+
final class _MapEntry {
286287
final MapEquality equality;
287288
final Object? key;
288289
final Object? value;
@@ -309,7 +310,7 @@ class _MapEntry {
309310
/// The [equals] and [hash] methods accepts `null` values,
310311
/// even if the [isValidKey] returns `false` for `null`.
311312
/// The [hash] of `null` is `null.hashCode`.
312-
class MapEquality<K, V> implements Equality<Map<K, V>> {
313+
final class MapEquality<K, V> implements Equality<Map<K, V>> {
313314
final Equality<K> _keyEquality;
314315
final Equality<V> _valueEquality;
315316
const MapEquality(
@@ -372,7 +373,7 @@ class MapEquality<K, V> implements Equality<Map<K, V>> {
372373
/// for `equals(e1, e2)` and `equals(e2, e1)`. This can happen if one equality
373374
/// considers only `e1` a valid key, and not `e2`, but an equality which is
374375
/// checked later, allows both.
375-
class MultiEquality<E> implements Equality<E> {
376+
final class MultiEquality<E> implements Equality<E> {
376377
final Iterable<Equality<E>> _equalities;
377378

378379
const MultiEquality(Iterable<Equality<E>> equalities)
@@ -418,7 +419,7 @@ class MultiEquality<E> implements Equality<E> {
418419
///
419420
/// A list is only equal to another list, likewise for sets and maps. All other
420421
/// iterables are compared as iterables only.
421-
class DeepCollectionEquality implements Equality {
422+
final class DeepCollectionEquality implements Equality {
422423
final Equality _base;
423424
final bool _unordered;
424425
const DeepCollectionEquality([Equality base = const DefaultEquality<Never>()])
@@ -476,7 +477,7 @@ class DeepCollectionEquality implements Equality {
476477
/// String equality that's insensitive to differences in ASCII case.
477478
///
478479
/// Non-ASCII characters are compared as-is, with no conversion.
479-
class CaseInsensitiveEquality implements Equality<String> {
480+
final class CaseInsensitiveEquality implements Equality<String> {
480481
const CaseInsensitiveEquality();
481482

482483
@override

pkgs/collection/lib/src/priority_queue.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import 'utils.dart';
2121
/// If elements override [Object.==], the `comparison` function must
2222
/// always give equal objects the same priority,
2323
/// otherwise [contains] or [remove] might not work correctly.
24-
abstract class PriorityQueue<E> {
24+
abstract interface class PriorityQueue<E> {
2525
/// Creates an empty [PriorityQueue].
2626
///
2727
/// The created [PriorityQueue] is a plain [HeapPriorityQueue].
@@ -168,7 +168,7 @@ abstract class PriorityQueue<E> {
168168
/// and is linear, O(n).
169169
/// * The [toSet] operation effectively adds each element to the new set, taking
170170
/// an expected O(n*log(n)) time.
171-
class HeapPriorityQueue<E> implements PriorityQueue<E> {
171+
final class HeapPriorityQueue<E> implements PriorityQueue<E> {
172172
/// Initial capacity of a queue when created, or when added to after a
173173
/// [clear].
174174
///

pkgs/collection/lib/src/queue_list.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import 'dart:collection';
66

77
/// A class that efficiently implements both [Queue] and [List].
8+
// TODO(nweiz): Currently this code is copied almost verbatim from
9+
// dart:collection. The only changes are to implement List and to remove methods
10+
// that are redundant with ListMixin. Remove or simplify it when issue 21330 is
11+
// fixed.
812
interface class QueueList<E> with ListMixin<E> implements Queue<E> {
913
/// Adapts [source] to be a `QueueList<T>`.
1014
///
@@ -267,7 +271,7 @@ interface class QueueList<E> with ListMixin<E> implements Queue<E> {
267271
}
268272
}
269273

270-
class _CastQueueList<S, T> extends QueueList<T> {
274+
final class _CastQueueList<S, T> extends QueueList<T> {
271275
final QueueList<S> _delegate;
272276

273277
// Assigns invalid values for head/tail because it uses the delegate to hold

pkgs/collection/lib/src/union_set_controller.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import 'union_set.dart';
2121
/// }
2222
/// }
2323
/// ```
24-
class UnionSetController<E> {
24+
interface class UnionSetController<E> {
2525
/// The [UnionSet] that provides a view of the union of sets in `this`.
2626
final UnionSet<E> set;
2727

0 commit comments

Comments
 (0)