OLD | NEW |
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 export "dart:collection" show UnmodifiableListView, UnmodifiableMapView; | 5 export "dart:collection" show UnmodifiableListView, UnmodifiableMapView; |
6 | 6 |
7 import 'wrappers.dart'; | 7 import 'wrappers.dart'; |
8 | 8 |
9 /// A fixed-length list. | 9 /// A fixed-length list. |
10 /// | 10 /// |
11 /// A `NonGrowableListView` contains a [List] object and ensures that | 11 /// A `NonGrowableListView` contains a [List] object and ensures that |
12 /// its length does not change. | 12 /// its length does not change. |
13 /// Methods that would change the length of the list, | 13 /// Methods that would change the length of the list, |
14 /// such as [add] and [remove], throw an [UnsupportedError]. | 14 /// such as [add] and [remove], throw an [UnsupportedError]. |
15 /// All other methods work directly on the underlying list. | 15 /// All other methods work directly on the underlying list. |
16 /// | 16 /// |
17 /// This class _does_ allow changes to the contents of the wrapped list. | 17 /// This class _does_ allow changes to the contents of the wrapped list. |
18 /// You can, for example, [sort] the list. | 18 /// You can, for example, [sort] the list. |
19 /// Permitted operations defer to the wrapped list. | 19 /// Permitted operations defer to the wrapped list. |
20 class NonGrowableListView<E> extends DelegatingList<E> | 20 class NonGrowableListView<E> extends DelegatingList<E> |
21 with NonGrowableListMixin<E> { | 21 with NonGrowableListMixin<E> { |
22 NonGrowableListView(List<E> listBase) : super(listBase); | 22 NonGrowableListView(List<E> listBase) : super(listBase); |
23 } | 23 } |
24 | 24 |
25 /// Mixin class that implements a throwing version of all list operations that | 25 /// Mixin class that implements a throwing version of all list operations that |
26 /// change the List's length. | 26 /// change the List's length. |
27 abstract class NonGrowableListMixin<E> implements List<E> { | 27 abstract class NonGrowableListMixin<E> implements List<E> { |
28 static _throw() { | 28 static /*=T*/ _throw/*<T>*/() { |
29 throw new UnsupportedError( | 29 throw new UnsupportedError( |
30 "Cannot change the length of a fixed-length list"); | 30 "Cannot change the length of a fixed-length list"); |
31 } | 31 } |
32 | 32 |
33 /// Throws an [UnsupportedError]; | 33 /// Throws an [UnsupportedError]; |
34 /// operations that change the length of the list are disallowed. | 34 /// operations that change the length of the list are disallowed. |
35 void set length(int newLength) => _throw(); | 35 void set length(int newLength) => _throw(); |
36 | 36 |
37 /// Throws an [UnsupportedError]; | 37 /// Throws an [UnsupportedError]; |
38 /// operations that change the length of the list are disallowed. | 38 /// operations that change the length of the list are disallowed. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 /// such as [add] and [remove], throw an [UnsupportedError]. | 91 /// such as [add] and [remove], throw an [UnsupportedError]. |
92 /// Permitted operations defer to the wrapped set. | 92 /// Permitted operations defer to the wrapped set. |
93 class UnmodifiableSetView<E> extends DelegatingSet<E> | 93 class UnmodifiableSetView<E> extends DelegatingSet<E> |
94 with UnmodifiableSetMixin<E> { | 94 with UnmodifiableSetMixin<E> { |
95 UnmodifiableSetView(Set<E> setBase) : super(setBase); | 95 UnmodifiableSetView(Set<E> setBase) : super(setBase); |
96 } | 96 } |
97 | 97 |
98 /// Mixin class that implements a throwing version of all set operations that | 98 /// Mixin class that implements a throwing version of all set operations that |
99 /// change the Set. | 99 /// change the Set. |
100 abstract class UnmodifiableSetMixin<E> implements Set<E> { | 100 abstract class UnmodifiableSetMixin<E> implements Set<E> { |
101 _throw() { | 101 static /*=T*/ _throw/*<T>*/() { |
102 throw new UnsupportedError("Cannot modify an unmodifiable Set"); | 102 throw new UnsupportedError("Cannot modify an unmodifiable Set"); |
103 } | 103 } |
104 | 104 |
105 /// Throws an [UnsupportedError]; | 105 /// Throws an [UnsupportedError]; |
106 /// operations that change the set are disallowed. | 106 /// operations that change the set are disallowed. |
107 bool add(E value) => _throw(); | 107 bool add(E value) => _throw(); |
108 | 108 |
109 /// Throws an [UnsupportedError]; | 109 /// Throws an [UnsupportedError]; |
110 /// operations that change the set are disallowed. | 110 /// operations that change the set are disallowed. |
111 void addAll(Iterable<E> elements) => _throw(); | 111 void addAll(Iterable<E> elements) => _throw(); |
(...skipping 19 matching lines...) Expand all Loading... |
131 void retainWhere(bool test(E element)) => _throw(); | 131 void retainWhere(bool test(E element)) => _throw(); |
132 | 132 |
133 /// Throws an [UnsupportedError]; | 133 /// Throws an [UnsupportedError]; |
134 /// operations that change the set are disallowed. | 134 /// operations that change the set are disallowed. |
135 void clear() => _throw(); | 135 void clear() => _throw(); |
136 } | 136 } |
137 | 137 |
138 /// Mixin class that implements a throwing version of all map operations that | 138 /// Mixin class that implements a throwing version of all map operations that |
139 /// change the Map. | 139 /// change the Map. |
140 abstract class UnmodifiableMapMixin<K, V> implements Map<K, V> { | 140 abstract class UnmodifiableMapMixin<K, V> implements Map<K, V> { |
141 static _throw() { | 141 static /*=T*/ _throw/*<T>*/() { |
142 throw new UnsupportedError("Cannot modify an unmodifiable Map"); | 142 throw new UnsupportedError("Cannot modify an unmodifiable Map"); |
143 } | 143 } |
144 | 144 |
145 /// Throws an [UnsupportedError]; | 145 /// Throws an [UnsupportedError]; |
146 /// operations that change the map are disallowed. | 146 /// operations that change the map are disallowed. |
147 void operator []=(K key, V value) => _throw(); | 147 void operator []=(K key, V value) => _throw(); |
148 | 148 |
149 /// Throws an [UnsupportedError]; | 149 /// Throws an [UnsupportedError]; |
150 /// operations that change the map are disallowed. | 150 /// operations that change the map are disallowed. |
151 V putIfAbsent(K key, V ifAbsent()) => _throw(); | 151 V putIfAbsent(K key, V ifAbsent()) => _throw(); |
152 | 152 |
153 /// Throws an [UnsupportedError]; | 153 /// Throws an [UnsupportedError]; |
154 /// operations that change the map are disallowed. | 154 /// operations that change the map are disallowed. |
155 void addAll(Map<K, V> other) => _throw(); | 155 void addAll(Map<K, V> other) => _throw(); |
156 | 156 |
157 /// Throws an [UnsupportedError]; | 157 /// Throws an [UnsupportedError]; |
158 /// operations that change the map are disallowed. | 158 /// operations that change the map are disallowed. |
159 V remove(Object key) => _throw(); | 159 V remove(Object key) => _throw(); |
160 | 160 |
161 /// Throws an [UnsupportedError]; | 161 /// Throws an [UnsupportedError]; |
162 /// operations that change the map are disallowed. | 162 /// operations that change the map are disallowed. |
163 void clear() => _throw(); | 163 void clear() => _throw(); |
164 } | 164 } |
OLD | NEW |