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

Side by Side Diff: pkg/mdv_observe/lib/src/observable_map.dart

Issue 14246008: Allow Object when doing lookups. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Forgot to upload before committing Created 7 years, 6 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/serialization/lib/src/serialization_helpers.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 part of mdv_observe; 5 part of mdv_observe;
6 6
7 // TODO(jmesserly): this needs to be faster. We currently require multiple 7 // TODO(jmesserly): this needs to be faster. We currently require multiple
8 // lookups per key to get the old value. 8 // lookups per key to get the old value.
9 // TODO(jmesserly): this doesn't implement the precise interfaces like 9 // TODO(jmesserly): this doesn't implement the precise interfaces like
10 // LinkedHashMap, SplayTreeMap or HashMap. However it can use them for the 10 // LinkedHashMap, SplayTreeMap or HashMap. However it can use them for the
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 Iterable<K> get keys => _map.keys; 87 Iterable<K> get keys => _map.keys;
88 88
89 Iterable<V> get values => _map.values; 89 Iterable<V> get values => _map.values;
90 90
91 int get length =>_map.length; 91 int get length =>_map.length;
92 92
93 bool get isEmpty => length == 0; 93 bool get isEmpty => length == 0;
94 94
95 bool get isNotEmpty => !isEmpty; 95 bool get isNotEmpty => !isEmpty;
96 96
97 bool containsValue(V value) => _map.containsValue(value); 97 bool containsValue(Object value) => _map.containsValue(value);
98 98
99 bool containsKey(K key) => _map.containsKey(key); 99 bool containsKey(Object key) => _map.containsKey(key);
100 100
101 V operator [](K key) => _map[key]; 101 V operator [](Object key) => _map[key];
102 102
103 void operator []=(K key, V value) { 103 void operator []=(K key, V value) {
104 int len = _map.length; 104 int len = _map.length;
105 V oldValue = _map[key]; 105 V oldValue = _map[key];
106 _map[key] = value; 106 _map[key] = value;
107 if (hasObservers) { 107 if (hasObservers) {
108 if (len != _map.length) { 108 if (len != _map.length) {
109 notifyPropertyChange(_LENGTH, len, _map.length); 109 notifyPropertyChange(_LENGTH, len, _map.length);
110 notifyChange(new MapChangeRecord(key, isInsert: true)); 110 notifyChange(new MapChangeRecord(key, isInsert: true));
111 } else if (!identical(oldValue, value)) { 111 } else if (!identical(oldValue, value)) {
112 notifyChange(new MapChangeRecord(key)); 112 notifyChange(new MapChangeRecord(key));
113 } 113 }
114 } 114 }
115 } 115 }
116 116
117 V putIfAbsent(K key, V ifAbsent()) { 117 V putIfAbsent(K key, V ifAbsent()) {
118 int len = _map.length; 118 int len = _map.length;
119 V result = _map.putIfAbsent(key, ifAbsent); 119 V result = _map.putIfAbsent(key, ifAbsent);
120 if (hasObservers && len != _map.length) { 120 if (hasObservers && len != _map.length) {
121 notifyPropertyChange(_LENGTH, len, _map.length); 121 notifyPropertyChange(_LENGTH, len, _map.length);
122 notifyChange(new MapChangeRecord(key, isInsert: true)); 122 notifyChange(new MapChangeRecord(key, isInsert: true));
123 } 123 }
124 return result; 124 return result;
125 } 125 }
126 126
127 V remove(K key) { 127 V remove(Object key) {
128 int len = _map.length; 128 int len = _map.length;
129 V result = _map.remove(key); 129 V result = _map.remove(key);
130 if (hasObservers && len != _map.length) { 130 if (hasObservers && len != _map.length) {
131 notifyChange(new MapChangeRecord(key, isRemove: true)); 131 notifyChange(new MapChangeRecord(key, isRemove: true));
132 notifyPropertyChange(_LENGTH, len, _map.length); 132 notifyPropertyChange(_LENGTH, len, _map.length);
133 } 133 }
134 return result; 134 return result;
135 } 135 }
136 136
137 void clear() { 137 void clear() {
138 int len = _map.length; 138 int len = _map.length;
139 if (hasObservers && len > 0) { 139 if (hasObservers && len > 0) {
140 _map.forEach((key, value) { 140 _map.forEach((key, value) {
141 notifyChange(new MapChangeRecord(key, isRemove: true)); 141 notifyChange(new MapChangeRecord(key, isRemove: true));
142 }); 142 });
143 notifyPropertyChange(_LENGTH, len, 0); 143 notifyPropertyChange(_LENGTH, len, 0);
144 } 144 }
145 _map.clear(); 145 _map.clear();
146 } 146 }
147 147
148 void forEach(void f(K key, V value)) => _map.forEach(f); 148 void forEach(void f(K key, V value)) => _map.forEach(f);
149 149
150 String toString() => Maps.mapToString(this); 150 String toString() => Maps.mapToString(this);
151 } 151 }
OLDNEW
« no previous file with comments | « no previous file | pkg/serialization/lib/src/serialization_helpers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698