| 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 part of $LIBRARYNAME; | 5 part of $LIBRARYNAME; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The type used by the | 8 * The type used by the |
| 9 * [Window.localStorage] and [Window.sessionStorage] properties. | 9 * [Window.localStorage] and [Window.sessionStorage] properties. |
| 10 * Storage is implemented as a Map<String, String>. | 10 * Storage is implemented as a Map<String, String>. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 * section of the library tour. | 30 * section of the library tour. |
| 31 */ | 31 */ |
| 32 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS | 32 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS |
| 33 implements Map<String, String> { | 33 implements Map<String, String> { |
| 34 | 34 |
| 35 void addAll(Map<String, String> other) { | 35 void addAll(Map<String, String> other) { |
| 36 other.forEach((k, v) { this[k] = v; }); | 36 other.forEach((k, v) { this[k] = v; }); |
| 37 } | 37 } |
| 38 | 38 |
| 39 // TODO(nweiz): update this when maps support lazy iteration | 39 // TODO(nweiz): update this when maps support lazy iteration |
| 40 bool containsValue(String value) => values.any((e) => e == value); | 40 bool containsValue(Object value) => values.any((e) => e == value); |
| 41 | 41 |
| 42 bool containsKey(String key) => _getItem(key) != null; | 42 bool containsKey(Object key) => _getItem(key) != null; |
| 43 | 43 |
| 44 String operator [](String key) => _getItem(key); | 44 String operator [](Object key) => _getItem(key); |
| 45 | 45 |
| 46 void operator []=(String key, String value) { _setItem(key, value); } | 46 void operator []=(String key, String value) { _setItem(key, value); } |
| 47 | 47 |
| 48 String putIfAbsent(String key, String ifAbsent()) { | 48 String putIfAbsent(String key, String ifAbsent()) { |
| 49 if (!containsKey(key)) this[key] = ifAbsent(); | 49 if (!containsKey(key)) this[key] = ifAbsent(); |
| 50 return this[key]; | 50 return this[key]; |
| 51 } | 51 } |
| 52 | 52 |
| 53 String remove(String key) { | 53 String remove(Object key) { |
| 54 final value = this[key]; | 54 final value = this[key]; |
| 55 _removeItem(key); | 55 _removeItem(key); |
| 56 return value; | 56 return value; |
| 57 } | 57 } |
| 58 | 58 |
| 59 void clear() => _clear(); | 59 void clear() => _clear(); |
| 60 | 60 |
| 61 void forEach(void f(String key, String value)) { | 61 void forEach(void f(String key, String value)) { |
| 62 for (var i = 0; true; i++) { | 62 for (var i = 0; true; i++) { |
| 63 final key = _key(i); | 63 final key = _key(i); |
| 64 if (key == null) return; | 64 if (key == null) return; |
| 65 | 65 |
| 66 f(key, this[key]); | 66 f(key, this[key]); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 Iterable<String> get keys { | 70 Iterable<String> get keys { |
| 71 final keys = []; | 71 final keys = <String>[]; |
| 72 forEach((k, v) => keys.add(k)); | 72 forEach((k, v) => keys.add(k)); |
| 73 return keys; | 73 return keys; |
| 74 } | 74 } |
| 75 | 75 |
| 76 Iterable<String> get values { | 76 Iterable<String> get values { |
| 77 final values = []; | 77 final values = <String>[]; |
| 78 forEach((k, v) => values.add(v)); | 78 forEach((k, v) => values.add(v)); |
| 79 return values; | 79 return values; |
| 80 } | 80 } |
| 81 | 81 |
| 82 int get length => _length; | 82 int get length => _length; |
| 83 | 83 |
| 84 bool get isEmpty => _key(0) == null; | 84 bool get isEmpty => _key(0) == null; |
| 85 | 85 |
| 86 bool get isNotEmpty => !isEmpty; | 86 bool get isNotEmpty => !isEmpty; |
| 87 $!MEMBERS | 87 $!MEMBERS |
| 88 } | 88 } |
| OLD | NEW |