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

Side by Side Diff: sdk/lib/collection/maps.dart

Issue 1360053003: Fix some cases where Map.containsValue did not accept Object as argument. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « sdk/lib/_internal/js_runtime/lib/constant_map.dart ('k') | sdk/lib/collection/splay_tree.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of dart.collection; 5 part of dart.collection;
6 6
7 /** 7 /**
8 * Base class for implementing a [Map]. 8 * Base class for implementing a [Map].
9 * 9 *
10 * This class has a basic implementation of all but five of the members of 10 * This class has a basic implementation of all but five of the members of
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 action(key, this[key]); 53 action(key, this[key]);
54 } 54 }
55 } 55 }
56 56
57 void addAll(Map<K, V> other) { 57 void addAll(Map<K, V> other) {
58 for (K key in other.keys) { 58 for (K key in other.keys) {
59 this[key] = other[key]; 59 this[key] = other[key];
60 } 60 }
61 } 61 }
62 62
63 bool containsValue(V value) { 63 bool containsValue(Object value) {
64 for (K key in keys) { 64 for (K key in keys) {
65 if (this[key] == value) return true; 65 if (this[key] == value) return true;
66 } 66 }
67 return false; 67 return false;
68 } 68 }
69 69
70 V putIfAbsent(K key, V ifAbsent()) { 70 V putIfAbsent(K key, V ifAbsent()) {
71 if (keys.contains(key)) { 71 if (keys.contains(key)) {
72 return this[key]; 72 return this[key];
73 } 73 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 class UnmodifiableMapView<K, V> = 211 class UnmodifiableMapView<K, V> =
212 MapView<K, V> with _UnmodifiableMapMixin<K, V>; 212 MapView<K, V> with _UnmodifiableMapMixin<K, V>;
213 213
214 /** 214 /**
215 * Helper class which implements complex [Map] operations 215 * Helper class which implements complex [Map] operations
216 * in term of basic ones ([Map.keys], [Map.operator []], 216 * in term of basic ones ([Map.keys], [Map.operator []],
217 * [Map.operator []=] and [Map.remove].) Not all methods are 217 * [Map.operator []=] and [Map.remove].) Not all methods are
218 * necessary to implement each particular operation. 218 * necessary to implement each particular operation.
219 */ 219 */
220 class Maps { 220 class Maps {
221 static bool containsValue(Map map, value) { 221 static bool containsValue(Map map, Object value) {
222 for (final v in map.values) { 222 for (final v in map.values) {
223 if (value == v) { 223 if (v == value) {
224 return true; 224 return true;
225 } 225 }
226 } 226 }
227 return false; 227 return false;
228 } 228 }
229 229
230 static bool containsKey(Map map, key) { 230 static bool containsKey(Map map, Object key) {
231 for (final k in map.keys) { 231 for (final k in map.keys) {
232 if (key == k) { 232 if (k == key) {
233 return true; 233 return true;
234 } 234 }
235 } 235 }
236 return false; 236 return false;
237 } 237 }
238 238
239 static putIfAbsent(Map map, key, ifAbsent()) { 239 static putIfAbsent(Map map, key, ifAbsent()) {
240 if (map.containsKey(key)) { 240 if (map.containsKey(key)) {
241 return map[key]; 241 return map[key];
242 } 242 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 map[keyIterator.current] = valueIterator.current; 344 map[keyIterator.current] = valueIterator.current;
345 hasNextKey = keyIterator.moveNext(); 345 hasNextKey = keyIterator.moveNext();
346 hasNextValue = valueIterator.moveNext(); 346 hasNextValue = valueIterator.moveNext();
347 } 347 }
348 348
349 if (hasNextKey || hasNextValue) { 349 if (hasNextKey || hasNextValue) {
350 throw new ArgumentError("Iterables do not have same length."); 350 throw new ArgumentError("Iterables do not have same length.");
351 } 351 }
352 } 352 }
353 } 353 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/js_runtime/lib/constant_map.dart ('k') | sdk/lib/collection/splay_tree.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698