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

Side by Side 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, 5 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library barback.asset_set;
6
7 import 'dart:async';
8 import 'dart:collection';
9 import 'dart:io';
10
11 import 'asset.dart';
12 import 'asset_id.dart';
13
14 /// A [Set] of [Asset]s with distinct IDs.
15 ///
16 /// This uses the [AssetId] of each asset to determine uniqueness, so no two
17 /// assets with the same ID can be in the set.
18 class AssetSet extends IterableBase<Asset> implements Set<Asset> {
19 final _assets = new Map<AssetId, Asset>();
20
21 Iterator<Asset> get iterator => _assets.values.iterator;
22
23 int get length => _assets.length;
24
25 /// Gets the [Asset] in the set with [id], or returns `null` if no asset with
26 /// that ID is present.
27 Asset operator[](AssetId id) => _assets[id];
28
29 /// Adds [asset] to the set.
30 ///
31 /// If there is already an asset with that ID in the set, it is replaced by
32 /// the new one. Returns [asset].
33 Asset add(Asset asset) {
34 _assets[asset.id] = asset;
35 return asset;
36 }
37
38 /// Adds [assets] to the set.
39 void addAll(Iterable<Asset> assets) {
40 assets.forEach(add);
41 }
42
43 /// Returns `true` if the set contains [asset].
44 bool contains(Asset asset) {
45 var other = _assets[asset.id];
46 return other == asset;
47 }
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
48
49 /// Returns `true` if the set contains an [Asset] with [id].
50 bool containsId(AssetId id) {
51 return _assets.containsKey(id);
52 }
53
54 /// Removes all assets from the set.
55 void clear() {
56 _assets.clear();
57 }
58
59 // 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.
60 bool containsAll(Iterable<Asset> other) => throw new UnimplementedError();
61 AssetSet difference(Set<Asset> other) => throw new UnimplementedError();
62 AssetSet intersection(Set<Asset> other) => throw new UnimplementedError();
63 bool remove(Object value) => throw new UnimplementedError();
64 void removeAll(Iterable elements) => throw new UnimplementedError();
65 void removeWhere(bool test(Asset element)) => throw new UnimplementedError();
66 void retainAll(Iterable elements) => throw new UnimplementedError();
67 void retainWhere(bool test(Asset element)) => throw new UnimplementedError();
68 AssetSet union(Set<Asset> other) => throw new UnimplementedError();
69 }
OLDNEW
« 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