OLD | NEW |
1 // Copyright 2013 Google Inc. All Rights Reserved. | 1 // Copyright 2013 Google Inc. All Rights Reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 part of quiver.collection; | 15 part of quiver.collection; |
16 | 16 |
17 /** | 17 /// An implementation of [Map] that delegates all methods to another [Map]. |
18 * An implementation of [Map] that delegates all methods to another [Map]. | 18 /// For instance you can create a FruitMap like this : |
19 * For instance you can create a FruitMap like this : | 19 /// |
20 * | 20 /// class FruitMap extends DelegatingMap<String, Fruit> { |
21 * class FruitMap extends DelegatingMap<String, Fruit> { | 21 /// final Map<String, Fruit> _fruits = {}; |
22 * final Map<String, Fruit> _fruits = {}; | 22 /// |
23 * | 23 /// Map<String, Fruit> get delegate => _fruits; |
24 * Map<String, Fruit> get delegate => _fruits; | 24 /// |
25 * | 25 /// // custom methods |
26 * // custom methods | 26 /// } |
27 * } | |
28 */ | |
29 abstract class DelegatingMap<K, V> implements Map<K, V> { | 27 abstract class DelegatingMap<K, V> implements Map<K, V> { |
30 Map<K, V> get delegate; | 28 Map<K, V> get delegate; |
31 | 29 |
32 V operator [](Object key) => delegate[key]; | 30 V operator [](Object key) => delegate[key]; |
33 | 31 |
34 void operator []=(K key, V value) { | 32 void operator []=(K key, V value) { |
35 delegate[key] = value; | 33 delegate[key] = value; |
36 } | 34 } |
37 | 35 |
38 void addAll(Map<K, V> other) => delegate.addAll(other); | 36 void addAll(Map<K, V> other) => delegate.addAll(other); |
(...skipping 13 matching lines...) Expand all Loading... |
52 Iterable<K> get keys => delegate.keys; | 50 Iterable<K> get keys => delegate.keys; |
53 | 51 |
54 int get length => delegate.length; | 52 int get length => delegate.length; |
55 | 53 |
56 V putIfAbsent(K key, V ifAbsent()) => delegate.putIfAbsent(key, ifAbsent); | 54 V putIfAbsent(K key, V ifAbsent()) => delegate.putIfAbsent(key, ifAbsent); |
57 | 55 |
58 V remove(Object key) => delegate.remove(key); | 56 V remove(Object key) => delegate.remove(key); |
59 | 57 |
60 Iterable<V> get values => delegate.values; | 58 Iterable<V> get values => delegate.values; |
61 } | 59 } |
OLD | NEW |