Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Unified Diff: pkg/barback/lib/src/asset_set.dart

Issue 18650004: Make Assets know their ID. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add AssetSet and revise. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/barback/lib/src/asset_node.dart ('k') | pkg/barback/lib/src/phase.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/barback/lib/src/asset_set.dart
diff --git a/pkg/barback/lib/src/asset_set.dart b/pkg/barback/lib/src/asset_set.dart
new file mode 100644
index 0000000000000000000000000000000000000000..cbbf6c2788a2d271567ee8ac08d9a3c1b31e0b26
--- /dev/null
+++ b/pkg/barback/lib/src/asset_set.dart
@@ -0,0 +1,69 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library barback.asset_set;
+
+import 'dart:async';
+import 'dart:collection';
+import 'dart:io';
+
+import 'asset.dart';
+import 'asset_id.dart';
+
+/// A [Set] of [Asset]s with distinct IDs.
+///
+/// This uses the [AssetId] of each asset to determine uniqueness, so no two
+/// assets with the same ID can be in the set.
+class AssetSet extends IterableBase<Asset> implements Set<Asset> {
+ final _assets = new Map<AssetId, Asset>();
+
+ Iterator<Asset> get iterator => _assets.values.iterator;
+
+ int get length => _assets.length;
+
+ /// Gets the [Asset] in the set with [id], or returns `null` if no asset with
+ /// that ID is present.
+ Asset operator[](AssetId id) => _assets[id];
+
+ /// Adds [asset] to the set.
+ ///
+ /// If there is already an asset with that ID in the set, it is replaced by
+ /// the new one. Returns [asset].
+ Asset add(Asset asset) {
+ _assets[asset.id] = asset;
+ return asset;
+ }
+
+ /// Adds [assets] to the set.
+ void addAll(Iterable<Asset> assets) {
+ assets.forEach(add);
+ }
+
+ /// Returns `true` if the set contains [asset].
+ bool contains(Asset asset) {
+ var other = _assets[asset.id];
+ return other == asset;
+ }
nweiz 2013/07/03 22:58:33 If [contains] has a different notion of equality t
Bob Nystrom 2013/07/08 17:54:01 It does have the same notion of equality. It looks
+
+ /// Returns `true` if the set contains an [Asset] with [id].
+ bool containsId(AssetId id) {
+ return _assets.containsKey(id);
+ }
+
+ /// Removes all assets from the set.
+ void clear() {
+ _assets.clear();
+ }
+
+ // TODO(rnystrom): Implement and test these as needed.
nweiz 2013/07/03 22:58:33 This may be another reason not to implement Set.
Bob Nystrom 2013/07/08 17:54:01 Done.
+ bool containsAll(Iterable<Asset> other) => throw new UnimplementedError();
+ AssetSet difference(Set<Asset> other) => throw new UnimplementedError();
+ AssetSet intersection(Set<Asset> other) => throw new UnimplementedError();
+ bool remove(Object value) => throw new UnimplementedError();
+ void removeAll(Iterable elements) => throw new UnimplementedError();
+ void removeWhere(bool test(Asset element)) => throw new UnimplementedError();
+ void retainAll(Iterable elements) => throw new UnimplementedError();
+ void retainWhere(bool test(Asset element)) => throw new UnimplementedError();
+ AssetSet union(Set<Asset> other) => throw new UnimplementedError();
+}
« no previous file with comments | « pkg/barback/lib/src/asset_node.dart ('k') | pkg/barback/lib/src/phase.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698