OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library barback.asset_set; | 5 library barback.asset_set; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 | 10 |
11 import 'asset.dart'; | 11 import 'asset.dart'; |
12 import 'asset_id.dart'; | 12 import 'asset_id.dart'; |
13 | 13 |
14 /// A set of [Asset]s with distinct IDs. | 14 /// A set of [Asset]s with distinct IDs. |
15 /// | 15 /// |
16 /// This uses the [AssetId] of each asset to determine uniqueness, so no two | 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. | 17 /// assets with the same ID can be in the set. |
18 class AssetSet extends IterableBase<Asset> { | 18 class AssetSet extends IterableBase<Asset> { |
19 final _assets = new Map<AssetId, Asset>(); | 19 final _assets = new Map<AssetId, Asset>(); |
20 | 20 |
21 AssetSet(); | |
22 | |
23 AssetSet.from(Iterable<Asset> other) { | |
Bob Nystrom
2013/07/30 22:25:02
Document, especially that later Assets take preced
nweiz
2013/07/30 22:46:21
Done.
| |
24 for (var asset in other) { | |
25 _assets[asset.id] = asset; | |
26 } | |
27 } | |
28 | |
21 Iterator<Asset> get iterator => _assets.values.iterator; | 29 Iterator<Asset> get iterator => _assets.values.iterator; |
22 | 30 |
23 int get length => _assets.length; | 31 int get length => _assets.length; |
24 | 32 |
25 /// Gets the [Asset] in the set with [id], or returns `null` if no asset with | 33 /// Gets the [Asset] in the set with [id], or returns `null` if no asset with |
26 /// that ID is present. | 34 /// that ID is present. |
27 Asset operator[](AssetId id) => _assets[id]; | 35 Asset operator[](AssetId id) => _assets[id]; |
28 | 36 |
29 /// Adds [asset] to the set. | 37 /// Adds [asset] to the set. |
30 /// | 38 /// |
(...skipping 13 matching lines...) Expand all Loading... | |
44 bool contains(Asset asset) { | 52 bool contains(Asset asset) { |
45 var other = _assets[asset.id]; | 53 var other = _assets[asset.id]; |
46 return other == asset; | 54 return other == asset; |
47 } | 55 } |
48 | 56 |
49 /// Returns `true` if the set contains an [Asset] with [id]. | 57 /// Returns `true` if the set contains an [Asset] with [id]. |
50 bool containsId(AssetId id) { | 58 bool containsId(AssetId id) { |
51 return _assets.containsKey(id); | 59 return _assets.containsKey(id); |
52 } | 60 } |
53 | 61 |
62 Asset removeId(AssetId id) => _assets.remove(id); | |
Bob Nystrom
2013/07/30 22:25:02
Document.
nweiz
2013/07/30 22:46:21
Done.
| |
63 | |
54 /// Removes all assets from the set. | 64 /// Removes all assets from the set. |
55 void clear() { | 65 void clear() { |
56 _assets.clear(); | 66 _assets.clear(); |
57 } | 67 } |
58 } | 68 } |
OLD | NEW |