OLD | NEW |
1 dart_library.library('collection/src/canonicalized_map', null, /* Imports */[ | 1 dart_library.library('collection/src/canonicalized_map', null, /* Imports */[ |
2 'dart/_runtime', | 2 'dart/_runtime', |
3 'dart/core', | 3 'dart/core', |
4 'collection/src/utils', | 4 'collection/src/utils', |
5 'dart/collection' | 5 'dart/collection' |
6 ], /* Lazy imports */[ | 6 ], /* Lazy imports */[ |
7 ], function(exports, dart, core, utils, collection) { | 7 ], function(exports, dart, core, utils, collection) { |
8 'use strict'; | 8 'use strict'; |
9 let dartx = dart.dartx; | 9 let dartx = dart.dartx; |
| 10 const _Canonicalize$ = dart.generic(function(C, K) { |
| 11 const _Canonicalize = dart.typedef('_Canonicalize', () => dart.functionType(
C, [K])); |
| 12 return _Canonicalize; |
| 13 }); |
| 14 let _Canonicalize = _Canonicalize$(); |
| 15 const _IsValidKey = dart.typedef('_IsValidKey', () => dart.functionType(core.b
ool, [core.Object])); |
10 const _base = Symbol('_base'); | 16 const _base = Symbol('_base'); |
11 const _canonicalize = Symbol('_canonicalize'); | 17 const _canonicalize = Symbol('_canonicalize'); |
12 const _isValidKeyFn = Symbol('_isValidKeyFn'); | 18 const _isValidKeyFn = Symbol('_isValidKeyFn'); |
13 const _isValidKey = Symbol('_isValidKey'); | 19 const _isValidKey = Symbol('_isValidKey'); |
14 const CanonicalizedMap$ = dart.generic(function(C, K, V) { | 20 const CanonicalizedMap$ = dart.generic(function(C, K, V) { |
15 class CanonicalizedMap extends core.Object { | 21 class CanonicalizedMap extends core.Object { |
16 CanonicalizedMap(canonicalize, opts) { | 22 CanonicalizedMap(canonicalize, opts) { |
17 let isValidKey = opts && 'isValidKey' in opts ? opts.isValidKey : null; | 23 let isValidKey = opts && 'isValidKey' in opts ? opts.isValidKey : null; |
18 this[_base] = core.Map$(C, utils.Pair$(K, V)).new(); | 24 this[_base] = core.Map$(C, utils.Pair$(K, V)).new(); |
19 this[_canonicalize] = canonicalize; | 25 this[_canonicalize] = canonicalize; |
20 this[_isValidKeyFn] = isValidKey; | 26 this[_isValidKeyFn] = isValidKey; |
21 } | 27 } |
22 from(other, canonicalize, opts) { | 28 from(other, canonicalize, opts) { |
23 let isValidKey = opts && 'isValidKey' in opts ? opts.isValidKey : null; | 29 let isValidKey = opts && 'isValidKey' in opts ? opts.isValidKey : null; |
24 this[_base] = core.Map$(C, utils.Pair$(K, V)).new(); | 30 this[_base] = core.Map$(C, utils.Pair$(K, V)).new(); |
25 this[_canonicalize] = canonicalize; | 31 this[_canonicalize] = canonicalize; |
26 this[_isValidKeyFn] = isValidKey; | 32 this[_isValidKeyFn] = isValidKey; |
27 this.addAll(other); | 33 this.addAll(other); |
28 } | 34 } |
29 get(key) { | 35 get(key) { |
30 if (!dart.notNull(this[_isValidKey](key))) return null; | 36 if (!dart.notNull(this[_isValidKey](key))) return null; |
31 let pair = this[_base][dartx.get](dart.dcall(this[_canonicalize], key)); | 37 let pair = this[_base][dartx.get](this[_canonicalize](dart.as(key, K))); |
32 return pair == null ? null : pair.last; | 38 return pair == null ? null : pair.last; |
33 } | 39 } |
34 set(key, value) { | 40 set(key, value) { |
35 (() => { | 41 (() => { |
36 dart.as(key, K); | 42 dart.as(key, K); |
37 dart.as(value, V); | 43 dart.as(value, V); |
38 if (!dart.notNull(this[_isValidKey](key))) return; | 44 if (!dart.notNull(this[_isValidKey](key))) return; |
39 this[_base][dartx.set](dart.as(dart.dcall(this[_canonicalize], key), C
), new (utils.Pair$(K, V))(key, value)); | 45 this[_base][dartx.set](this[_canonicalize](key), new (utils.Pair$(K, V
))(key, value)); |
40 })(); | 46 })(); |
41 return value; | 47 return value; |
42 } | 48 } |
43 addAll(other) { | 49 addAll(other) { |
44 dart.as(other, core.Map$(K, V)); | 50 dart.as(other, core.Map$(K, V)); |
45 other[dartx.forEach](dart.fn((key, value) => { | 51 other[dartx.forEach](dart.fn((key, value) => { |
46 dart.as(key, K); | 52 dart.as(key, K); |
47 dart.as(value, V); | 53 dart.as(value, V); |
48 return this.set(key, value); | 54 return this.set(key, value); |
49 }, V, [K, V])); | 55 }, V, [K, V])); |
50 } | 56 } |
51 clear() { | 57 clear() { |
52 this[_base][dartx.clear](); | 58 this[_base][dartx.clear](); |
53 } | 59 } |
54 containsKey(key) { | 60 containsKey(key) { |
55 if (!dart.notNull(this[_isValidKey](key))) return false; | 61 if (!dart.notNull(this[_isValidKey](key))) return false; |
56 return this[_base][dartx.containsKey](dart.dcall(this[_canonicalize], ke
y)); | 62 return this[_base][dartx.containsKey](this[_canonicalize](dart.as(key, K
))); |
57 } | 63 } |
58 containsValue(value) { | 64 containsValue(value) { |
59 return this[_base][dartx.values][dartx.any](dart.fn(pair => { | 65 return this[_base][dartx.values][dartx.any](dart.fn(pair => { |
60 dart.as(pair, utils.Pair$(K, V)); | 66 dart.as(pair, utils.Pair$(K, V)); |
61 return dart.equals(pair.last, value); | 67 return dart.equals(pair.last, value); |
62 }, core.bool, [utils.Pair$(K, V)])); | 68 }, core.bool, [utils.Pair$(K, V)])); |
63 } | 69 } |
64 forEach(f) { | 70 forEach(f) { |
65 dart.as(f, dart.functionType(dart.void, [K, V])); | 71 dart.as(f, dart.functionType(dart.void, [K, V])); |
66 this[_base][dartx.forEach](dart.fn((key, pair) => { | 72 this[_base][dartx.forEach](dart.fn((key, pair) => { |
(...skipping 13 matching lines...) Expand all Loading... |
80 dart.as(pair, utils.Pair$(K, V)); | 86 dart.as(pair, utils.Pair$(K, V)); |
81 return pair.first; | 87 return pair.first; |
82 }, K, [utils.Pair$(K, V)])); | 88 }, K, [utils.Pair$(K, V)])); |
83 } | 89 } |
84 get length() { | 90 get length() { |
85 return this[_base][dartx.length]; | 91 return this[_base][dartx.length]; |
86 } | 92 } |
87 putIfAbsent(key, ifAbsent) { | 93 putIfAbsent(key, ifAbsent) { |
88 dart.as(key, K); | 94 dart.as(key, K); |
89 dart.as(ifAbsent, dart.functionType(V, [])); | 95 dart.as(ifAbsent, dart.functionType(V, [])); |
90 return this[_base][dartx.putIfAbsent](dart.as(dart.dcall(this[_canonical
ize], key), C), dart.fn(() => new (utils.Pair$(K, V))(key, ifAbsent()), utils.Pa
ir$(K, V), [])).last; | 96 return this[_base][dartx.putIfAbsent](this[_canonicalize](key), dart.fn(
() => new (utils.Pair$(K, V))(key, ifAbsent()), utils.Pair$(K, V), [])).last; |
91 } | 97 } |
92 remove(key) { | 98 remove(key) { |
93 if (!dart.notNull(this[_isValidKey](key))) return null; | 99 if (!dart.notNull(this[_isValidKey](key))) return null; |
94 let pair = this[_base][dartx.remove](dart.dcall(this[_canonicalize], key
)); | 100 let pair = this[_base][dartx.remove](this[_canonicalize](dart.as(key, K)
)); |
95 return pair == null ? null : pair.last; | 101 return pair == null ? null : pair.last; |
96 } | 102 } |
97 get values() { | 103 get values() { |
98 return this[_base][dartx.values][dartx.map](dart.fn(pair => { | 104 return this[_base][dartx.values][dartx.map](dart.fn(pair => { |
99 dart.as(pair, utils.Pair$(K, V)); | 105 dart.as(pair, utils.Pair$(K, V)); |
100 return pair.last; | 106 return pair.last; |
101 }, V, [utils.Pair$(K, V)])); | 107 }, V, [utils.Pair$(K, V)])); |
102 } | 108 } |
103 toString() { | 109 toString() { |
104 return collection.Maps.mapToString(this); | 110 return collection.Maps.mapToString(this); |
105 } | 111 } |
106 [_isValidKey](key) { | 112 [_isValidKey](key) { |
107 return (key == null || dart.is(key, K)) && (this[_isValidKeyFn] == null
|| dart.notNull(dart.as(dart.dcall(this[_isValidKeyFn], key), core.bool))); | 113 return (key == null || dart.is(key, K)) && (this[_isValidKeyFn] == null
|| dart.notNull(this[_isValidKeyFn](key))); |
108 } | 114 } |
109 } | 115 } |
110 CanonicalizedMap[dart.implements] = () => [core.Map$(K, V)]; | 116 CanonicalizedMap[dart.implements] = () => [core.Map$(K, V)]; |
111 dart.defineNamedConstructor(CanonicalizedMap, 'from'); | 117 dart.defineNamedConstructor(CanonicalizedMap, 'from'); |
112 dart.setSignature(CanonicalizedMap, { | 118 dart.setSignature(CanonicalizedMap, { |
113 constructors: () => ({ | 119 constructors: () => ({ |
114 CanonicalizedMap: [CanonicalizedMap$(C, K, V), [dart.functionType(C, [K]
)], {isValidKey: dart.functionType(core.bool, [core.Object])}], | 120 CanonicalizedMap: [CanonicalizedMap$(C, K, V), [dart.functionType(C, [K]
)], {isValidKey: dart.functionType(core.bool, [core.Object])}], |
115 from: [CanonicalizedMap$(C, K, V), [core.Map$(K, V), dart.functionType(C
, [K])], {isValidKey: dart.functionType(core.bool, [core.Object])}] | 121 from: [CanonicalizedMap$(C, K, V), [core.Map$(K, V), dart.functionType(C
, [K])], {isValidKey: dart.functionType(core.bool, [core.Object])}] |
116 }), | 122 }), |
117 methods: () => ({ | 123 methods: () => ({ |
(...skipping 25 matching lines...) Expand all Loading... |
143 'length', | 149 'length', |
144 'values' | 150 'values' |
145 ]); | 151 ]); |
146 return CanonicalizedMap; | 152 return CanonicalizedMap; |
147 }); | 153 }); |
148 let CanonicalizedMap = CanonicalizedMap$(); | 154 let CanonicalizedMap = CanonicalizedMap$(); |
149 // Exports: | 155 // Exports: |
150 exports.CanonicalizedMap$ = CanonicalizedMap$; | 156 exports.CanonicalizedMap$ = CanonicalizedMap$; |
151 exports.CanonicalizedMap = CanonicalizedMap; | 157 exports.CanonicalizedMap = CanonicalizedMap; |
152 }); | 158 }); |
OLD | NEW |