Chromium Code Reviews| 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 // Immutable map class for compiler generated map literals. | 4 // Immutable map class for compiler generated map literals. |
| 5 | 5 |
| 6 class ImmutableMap<K, V> implements Map<K, V> { | 6 class ImmutableMap<K, V> implements Map<K, V> { |
| 7 final _ImmutableArray kvPairs_; | 7 final _ImmutableArray kvPairs_; |
| 8 | 8 |
| 9 const ImmutableMap._create(_ImmutableArray keyValuePairs) | 9 const ImmutableMap._create(_ImmutableArray keyValuePairs) |
| 10 : kvPairs_ = keyValuePairs; | 10 : kvPairs_ = keyValuePairs; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 bool containsValue(V value) { | 65 bool containsValue(V value) { |
| 66 for (int i = 1; i < kvPairs_.length; i += 2) { | 66 for (int i = 1; i < kvPairs_.length; i += 2) { |
| 67 if (value == kvPairs_[i]) { | 67 if (value == kvPairs_[i]) { |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 return false; | 71 return false; |
| 72 } | 72 } |
| 73 | 73 |
| 74 void operator []=(K key, V value) { | 74 void operator []=(K key, V value) { |
| 75 throw const IllegalAccessException(); | 75 throw new StateError("Cannot set value in unmodifiable Map"); |
|
floitsch
2012/10/23 12:50:32
why not const?
Lasse Reichstein Nielsen
2012/10/24 12:32:15
Why const. It's an exception case that should happ
| |
| 76 } | 76 } |
| 77 | 77 |
| 78 V putIfAbsent(K key, V ifAbsent()) { | 78 V putIfAbsent(K key, V ifAbsent()) { |
| 79 throw const IllegalAccessException(); | 79 throw new StateError("Cannot set value in unmodifiable Map"); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void clear() { | 82 void clear() { |
| 83 throw const IllegalAccessException(); | 83 throw new StateError("Cannot clear unmodifiable Map"); |
| 84 } | 84 } |
| 85 | 85 |
| 86 V remove(K key) { | 86 V remove(K key) { |
| 87 throw const IllegalAccessException(); | 87 throw new StateError("Cannot remove from unmodifiable Map"); |
| 88 } | 88 } |
| 89 | 89 |
| 90 String toString() { | 90 String toString() { |
| 91 return Maps.mapToString(this); | 91 return Maps.mapToString(this); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| OLD | NEW |