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 _base = Symbol('_base'); | 10 const _base = Symbol('_base'); |
(...skipping 10 matching lines...) Expand all Loading... |
21 } | 21 } |
22 from(other, canonicalize, opts) { | 22 from(other, canonicalize, opts) { |
23 let isValidKey = opts && 'isValidKey' in opts ? opts.isValidKey : null; | 23 let isValidKey = opts && 'isValidKey' in opts ? opts.isValidKey : null; |
24 this[_base] = core.Map$(C, utils.Pair$(K, V)).new(); | 24 this[_base] = core.Map$(C, utils.Pair$(K, V)).new(); |
25 this[_canonicalize] = canonicalize; | 25 this[_canonicalize] = canonicalize; |
26 this[_isValidKeyFn] = isValidKey; | 26 this[_isValidKeyFn] = isValidKey; |
27 this.addAll(other); | 27 this.addAll(other); |
28 } | 28 } |
29 get(key) { | 29 get(key) { |
30 if (!dart.notNull(this[_isValidKey](key))) return null; | 30 if (!dart.notNull(this[_isValidKey](key))) return null; |
31 let pair = this[_base].get(dart.dcall(this[_canonicalize], key)); | 31 let pair = this[_base][dartx.get](dart.dcall(this[_canonicalize], key)); |
32 return pair == null ? null : pair.last; | 32 return pair == null ? null : pair.last; |
33 } | 33 } |
34 set(key, value) { | 34 set(key, value) { |
35 (() => { | 35 (() => { |
36 dart.as(key, K); | 36 dart.as(key, K); |
37 dart.as(value, V); | 37 dart.as(value, V); |
38 if (!dart.notNull(this[_isValidKey](key))) return; | 38 if (!dart.notNull(this[_isValidKey](key))) return; |
39 this[_base].set(dart.as(dart.dcall(this[_canonicalize], key), C), new
(utils.Pair$(K, V))(key, value)); | 39 this[_base][dartx.set](dart.as(dart.dcall(this[_canonicalize], key), C
), new (utils.Pair$(K, V))(key, value)); |
40 })(); | 40 })(); |
41 return value; | 41 return value; |
42 } | 42 } |
43 addAll(other) { | 43 addAll(other) { |
44 dart.as(other, core.Map$(K, V)); | 44 dart.as(other, core.Map$(K, V)); |
45 other.forEach(dart.fn((key, value) => this.set(key, value), V, [K, V])); | 45 other[dartx.forEach](dart.fn((key, value) => this.set(key, value), V, [K
, V])); |
46 } | 46 } |
47 clear() { | 47 clear() { |
48 this[_base].clear(); | 48 this[_base][dartx.clear](); |
49 } | 49 } |
50 containsKey(key) { | 50 containsKey(key) { |
51 if (!dart.notNull(this[_isValidKey](key))) return false; | 51 if (!dart.notNull(this[_isValidKey](key))) return false; |
52 return this[_base].containsKey(dart.dcall(this[_canonicalize], key)); | 52 return this[_base][dartx.containsKey](dart.dcall(this[_canonicalize], ke
y)); |
53 } | 53 } |
54 containsValue(value) { | 54 containsValue(value) { |
55 return this[_base].values[dartx.any](dart.fn(pair => dart.equals(pair.la
st, value), core.bool, [utils.Pair$(K, V)])); | 55 return this[_base][dartx.values][dartx.any](dart.fn(pair => dart.equals(
pair.last, value), core.bool, [utils.Pair$(K, V)])); |
56 } | 56 } |
57 forEach(f) { | 57 forEach(f) { |
58 dart.as(f, dart.functionType(dart.void, [K, V])); | 58 dart.as(f, dart.functionType(dart.void, [K, V])); |
59 this[_base].forEach(dart.fn((key, pair) => f(pair.first, pair.last), dar
t.void, [C, utils.Pair$(K, V)])); | 59 this[_base][dartx.forEach](dart.fn((key, pair) => f(pair.first, pair.las
t), dart.void, [C, utils.Pair$(K, V)])); |
60 } | 60 } |
61 get isEmpty() { | 61 get isEmpty() { |
62 return this[_base].isEmpty; | 62 return this[_base][dartx.isEmpty]; |
63 } | 63 } |
64 get isNotEmpty() { | 64 get isNotEmpty() { |
65 return this[_base].isNotEmpty; | 65 return this[_base][dartx.isNotEmpty]; |
66 } | 66 } |
67 get keys() { | 67 get keys() { |
68 return this[_base].values[dartx.map](dart.fn(pair => pair.first, K, [uti
ls.Pair$(K, V)])); | 68 return this[_base][dartx.values][dartx.map](dart.fn(pair => pair.first,
K, [utils.Pair$(K, V)])); |
69 } | 69 } |
70 get length() { | 70 get length() { |
71 return this[_base].length; | 71 return this[_base][dartx.length]; |
72 } | 72 } |
73 putIfAbsent(key, ifAbsent) { | 73 putIfAbsent(key, ifAbsent) { |
74 dart.as(key, K); | 74 dart.as(key, K); |
75 dart.as(ifAbsent, dart.functionType(V, [])); | 75 dart.as(ifAbsent, dart.functionType(V, [])); |
76 return this[_base].putIfAbsent(dart.as(dart.dcall(this[_canonicalize], k
ey), C), dart.fn(() => new (utils.Pair$(K, V))(key, ifAbsent()), utils.Pair$(K,
V), [])).last; | 76 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; |
77 } | 77 } |
78 remove(key) { | 78 remove(key) { |
79 if (!dart.notNull(this[_isValidKey](key))) return null; | 79 if (!dart.notNull(this[_isValidKey](key))) return null; |
80 let pair = this[_base].remove(dart.dcall(this[_canonicalize], key)); | 80 let pair = this[_base][dartx.remove](dart.dcall(this[_canonicalize], key
)); |
81 return pair == null ? null : pair.last; | 81 return pair == null ? null : pair.last; |
82 } | 82 } |
83 get values() { | 83 get values() { |
84 return this[_base].values[dartx.map](dart.fn(pair => pair.last, V, [util
s.Pair$(K, V)])); | 84 return this[_base][dartx.values][dartx.map](dart.fn(pair => pair.last, V
, [utils.Pair$(K, V)])); |
85 } | 85 } |
86 toString() { | 86 toString() { |
87 return collection.Maps.mapToString(this); | 87 return collection.Maps.mapToString(this); |
88 } | 88 } |
89 [_isValidKey](key) { | 89 [_isValidKey](key) { |
90 return (key == null || dart.is(key, K)) && (this[_isValidKeyFn] == null
|| dart.notNull(dart.as(dart.dcall(this[_isValidKeyFn], key), core.bool))); | 90 return (key == null || dart.is(key, K)) && (this[_isValidKeyFn] == null
|| dart.notNull(dart.as(dart.dcall(this[_isValidKeyFn], key), core.bool))); |
91 } | 91 } |
92 } | 92 } |
93 CanonicalizedMap[dart.implements] = () => [core.Map$(K, V)]; | 93 CanonicalizedMap[dart.implements] = () => [core.Map$(K, V)]; |
94 dart.defineNamedConstructor(CanonicalizedMap, 'from'); | 94 dart.defineNamedConstructor(CanonicalizedMap, 'from'); |
95 dart.setSignature(CanonicalizedMap, { | 95 dart.setSignature(CanonicalizedMap, { |
96 constructors: () => ({ | 96 constructors: () => ({ |
97 CanonicalizedMap: [CanonicalizedMap$(C, K, V), [dart.functionType(C, [K]
)], {isValidKey: dart.functionType(core.bool, [core.Object])}], | 97 CanonicalizedMap: [CanonicalizedMap$(C, K, V), [dart.functionType(C, [K]
)], {isValidKey: dart.functionType(core.bool, [core.Object])}], |
98 from: [CanonicalizedMap$(C, K, V), [core.Map$(K, V), dart.functionType(C
, [K])], {isValidKey: dart.functionType(core.bool, [core.Object])}] | 98 from: [CanonicalizedMap$(C, K, V), [core.Map$(K, V), dart.functionType(C
, [K])], {isValidKey: dart.functionType(core.bool, [core.Object])}] |
99 }), | 99 }), |
100 methods: () => ({ | 100 methods: () => ({ |
101 get: [V, [core.Object]], | 101 get: [V, [core.Object]], |
102 set: [dart.void, [K, V]], | 102 set: [dart.void, [K, V]], |
103 addAll: [dart.void, [core.Map$(K, V)]], | 103 addAll: [dart.void, [core.Map$(K, V)]], |
104 clear: [dart.void, []], | 104 clear: [dart.void, []], |
105 containsKey: [core.bool, [core.Object]], | 105 containsKey: [core.bool, [core.Object]], |
106 containsValue: [core.bool, [core.Object]], | 106 containsValue: [core.bool, [core.Object]], |
107 forEach: [dart.void, [dart.functionType(dart.void, [K, V])]], | 107 forEach: [dart.void, [dart.functionType(dart.void, [K, V])]], |
108 putIfAbsent: [V, [K, dart.functionType(V, [])]], | 108 putIfAbsent: [V, [K, dart.functionType(V, [])]], |
109 remove: [V, [core.Object]], | 109 remove: [V, [core.Object]], |
110 [_isValidKey]: [core.bool, [core.Object]] | 110 [_isValidKey]: [core.bool, [core.Object]] |
111 }) | 111 }) |
112 }); | 112 }); |
| 113 dart.defineExtensionMembers(CanonicalizedMap, [ |
| 114 'get', |
| 115 'set', |
| 116 'addAll', |
| 117 'clear', |
| 118 'containsKey', |
| 119 'containsValue', |
| 120 'forEach', |
| 121 'putIfAbsent', |
| 122 'remove', |
| 123 'isEmpty', |
| 124 'isNotEmpty', |
| 125 'keys', |
| 126 'length', |
| 127 'values' |
| 128 ]); |
113 return CanonicalizedMap; | 129 return CanonicalizedMap; |
114 }); | 130 }); |
115 let CanonicalizedMap = CanonicalizedMap$(); | 131 let CanonicalizedMap = CanonicalizedMap$(); |
116 // Exports: | 132 // Exports: |
117 exports.CanonicalizedMap$ = CanonicalizedMap$; | 133 exports.CanonicalizedMap$ = CanonicalizedMap$; |
118 exports.CanonicalizedMap = CanonicalizedMap; | 134 exports.CanonicalizedMap = CanonicalizedMap; |
119 }); | 135 }); |
OLD | NEW |