| OLD | NEW |
| (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> { |
| 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 } |
| 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 } |
| OLD | NEW |