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

Side by Side Diff: pkg/barback/lib/src/asset_set.dart

Issue 21226004: Refactor the barback tests somewhat. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes. Created 7 years, 4 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 | « no previous file | pkg/barback/lib/src/cancelable_future.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /// Creates a new AssetSet from the contents of [other].
24 ///
25 /// If multiple assets in [other] have the same id, the last one takes
26 /// precedence.
27 AssetSet.from(Iterable<Asset> other) {
28 for (var asset in other) {
29 _assets[asset.id] = asset;
30 }
31 }
32
21 Iterator<Asset> get iterator => _assets.values.iterator; 33 Iterator<Asset> get iterator => _assets.values.iterator;
22 34
23 int get length => _assets.length; 35 int get length => _assets.length;
24 36
25 /// Gets the [Asset] in the set with [id], or returns `null` if no asset with 37 /// Gets the [Asset] in the set with [id], or returns `null` if no asset with
26 /// that ID is present. 38 /// that ID is present.
27 Asset operator[](AssetId id) => _assets[id]; 39 Asset operator[](AssetId id) => _assets[id];
28 40
29 /// Adds [asset] to the set. 41 /// Adds [asset] to the set.
30 /// 42 ///
(...skipping 13 matching lines...) Expand all
44 bool contains(Asset asset) { 56 bool contains(Asset asset) {
45 var other = _assets[asset.id]; 57 var other = _assets[asset.id];
46 return other == asset; 58 return other == asset;
47 } 59 }
48 60
49 /// Returns `true` if the set contains an [Asset] with [id]. 61 /// Returns `true` if the set contains an [Asset] with [id].
50 bool containsId(AssetId id) { 62 bool containsId(AssetId id) {
51 return _assets.containsKey(id); 63 return _assets.containsKey(id);
52 } 64 }
53 65
66 /// If the set contains an [Asset] with [id], removes and returns it.
67 Asset removeId(AssetId id) => _assets.remove(id);
68
54 /// Removes all assets from the set. 69 /// Removes all assets from the set.
55 void clear() { 70 void clear() {
56 _assets.clear(); 71 _assets.clear();
57 } 72 }
58 } 73 }
OLDNEW
« no previous file with comments | « no previous file | pkg/barback/lib/src/cancelable_future.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698