| OLD | NEW |
| 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 /* | 5 /* |
| 6 * Helper class which implements complex [Map] operations | 6 * Helper class which implements complex [Map] operations |
| 7 * in term of basic ones ([Map.getKeys], [Map.operator []], | 7 * in term of basic ones ([Map.keys], [Map.operator []], |
| 8 * [Map.operator []=] and [Map.remove].) Not all methods are | 8 * [Map.operator []=] and [Map.remove].) Not all methods are |
| 9 * necessary to implement each particular operation. | 9 * necessary to implement each particular operation. |
| 10 */ | 10 */ |
| 11 class Maps { | 11 class Maps { |
| 12 static bool containsValue(Map map, value) { | 12 static bool containsValue(Map map, value) { |
| 13 for (final v in map.getValues()) { | 13 for (final v in map.values) { |
| 14 if (value == v) { | 14 if (value == v) { |
| 15 return true; | 15 return true; |
| 16 } | 16 } |
| 17 } | 17 } |
| 18 return false; | 18 return false; |
| 19 } | 19 } |
| 20 | 20 |
| 21 static bool containsKey(Map map, key) { | 21 static bool containsKey(Map map, key) { |
| 22 for (final k in map.getKeys()) { | 22 for (final k in map.keys) { |
| 23 if (key == k) { | 23 if (key == k) { |
| 24 return true; | 24 return true; |
| 25 } | 25 } |
| 26 } | 26 } |
| 27 return false; | 27 return false; |
| 28 } | 28 } |
| 29 | 29 |
| 30 static putIfAbsent(Map map, key, ifAbsent()) { | 30 static putIfAbsent(Map map, key, ifAbsent()) { |
| 31 if (map.containsKey(key)) { | 31 if (map.containsKey(key)) { |
| 32 return map[key]; | 32 return map[key]; |
| 33 } | 33 } |
| 34 final v = ifAbsent(); | 34 final v = ifAbsent(); |
| 35 map[key] = v; | 35 map[key] = v; |
| 36 return v; | 36 return v; |
| 37 } | 37 } |
| 38 | 38 |
| 39 static clear(Map map) { | 39 static clear(Map map) { |
| 40 for (final k in map.getKeys()) { | 40 for (final k in map.keys) { |
| 41 map.remove(k); | 41 map.remove(k); |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 static forEach(Map map, void f(key, value)) { | 45 static forEach(Map map, void f(key, value)) { |
| 46 for (final k in map.getKeys()) { | 46 for (final k in map.keys) { |
| 47 f(k, map[k]); | 47 f(k, map[k]); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 static Collection getValues(Map map) { | 51 static Collection getValues(Map map) { |
| 52 final result = []; | 52 final result = []; |
| 53 for (final k in map.getKeys()) { | 53 for (final k in map.keys) { |
| 54 result.add(map[k]); | 54 result.add(map[k]); |
| 55 } | 55 } |
| 56 return result; | 56 return result; |
| 57 } | 57 } |
| 58 | 58 |
| 59 static int length(Map map) => map.getKeys().length; | 59 static int length(Map map) => map.keys.length; |
| 60 | 60 |
| 61 static bool isEmpty(Map map) => length(map) == 0; | 61 static bool isEmpty(Map map) => length(map) == 0; |
| 62 | 62 |
| 63 /** | 63 /** |
| 64 * Returns a string representing the specified map. The returned string | 64 * Returns a string representing the specified map. The returned string |
| 65 * looks like this: [:'{key0: value0, key1: value1, ... keyN: valueN}':]. | 65 * looks like this: [:'{key0: value0, key1: value1, ... keyN: valueN}':]. |
| 66 * The value returned by its [toString] method is used to represent each | 66 * The value returned by its [toString] method is used to represent each |
| 67 * key or value. | 67 * key or value. |
| 68 * | 68 * |
| 69 * If the map collection contains a reference to itself, either | 69 * If the map collection contains a reference to itself, either |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 first = false; | 104 first = false; |
| 105 Collections._emitObject(k, result, visiting); | 105 Collections._emitObject(k, result, visiting); |
| 106 result.add(': '); | 106 result.add(': '); |
| 107 Collections._emitObject(v, result, visiting); | 107 Collections._emitObject(v, result, visiting); |
| 108 }); | 108 }); |
| 109 | 109 |
| 110 result.add('}'); | 110 result.add('}'); |
| 111 visiting.removeLast(); | 111 visiting.removeLast(); |
| 112 } | 112 } |
| 113 } | 113 } |
| OLD | NEW |