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 14 matching lines...) Expand all Loading... |
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].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 dart.as(key, K); | 35 (() => { |
36 dart.as(value, V); | 36 dart.as(key, K); |
37 this[_base].set(dart.as(dart.dcall(this[_canonicalize], key), C), new (u
tils.Pair$(K, V))(key, value)); | 37 dart.as(value, V); |
| 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)); |
| 40 })(); |
38 return value; | 41 return value; |
39 } | 42 } |
40 addAll(other) { | 43 addAll(other) { |
41 dart.as(other, core.Map$(K, V)); | 44 dart.as(other, core.Map$(K, V)); |
42 other.forEach(dart.fn((key, value) => this.set(key, value), V, [K, V])); | 45 other.forEach(dart.fn((key, value) => this.set(key, value), V, [K, V])); |
43 } | 46 } |
44 clear() { | 47 clear() { |
45 this[_base].clear(); | 48 this[_base].clear(); |
46 } | 49 } |
47 containsKey(key) { | 50 containsKey(key) { |
48 if (!dart.notNull(this[_isValidKey](key))) return false; | 51 if (!dart.notNull(this[_isValidKey](key))) return false; |
49 return this[_base].containsKey(dart.dcall(this[_canonicalize], key)); | 52 return this[_base].containsKey(dart.dcall(this[_canonicalize], key)); |
50 } | 53 } |
51 containsValue(value) { | 54 containsValue(value) { |
52 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].values[dartx.any](dart.fn(pair => dart.equals(pair.la
st, value), core.bool, [utils.Pair$(K, V)])); |
53 } | 56 } |
54 forEach(f) { | 57 forEach(f) { |
55 dart.as(f, dart.functionType(dart.void, [K, V])); | 58 dart.as(f, dart.functionType(dart.void, [K, V])); |
56 this[_base].forEach(dart.fn((key, pair) => f(pair.first, pair.last), dar
t.void, [C, utils.Pair$(K, V)])); | 59 this[_base].forEach(dart.fn((key, pair) => f(pair.first, pair.last), dar
t.void, [C, utils.Pair$(K, V)])); |
57 } | 60 } |
58 get isEmpty() { | 61 get isEmpty() { |
59 return this[_base].isEmpty; | 62 return this[_base].isEmpty; |
60 } | 63 } |
61 get isNotEmpty() { | 64 get isNotEmpty() { |
62 return this[_base].isNotEmpty; | 65 return this[_base].isNotEmpty; |
63 } | 66 } |
64 get keys() { | 67 get keys() { |
65 return dart.as(this[_base].values[dartx.map](dart.fn(pair => pair.first,
K, [utils.Pair$(K, V)])), core.Iterable$(K)); | 68 return this[_base].values[dartx.map](dart.fn(pair => pair.first, K, [uti
ls.Pair$(K, V)])); |
66 } | 69 } |
67 get length() { | 70 get length() { |
68 return this[_base].length; | 71 return this[_base].length; |
69 } | 72 } |
70 putIfAbsent(key, ifAbsent) { | 73 putIfAbsent(key, ifAbsent) { |
71 dart.as(key, K); | 74 dart.as(key, K); |
72 dart.as(ifAbsent, dart.functionType(V, [])); | 75 dart.as(ifAbsent, dart.functionType(V, [])); |
73 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].putIfAbsent(dart.as(dart.dcall(this[_canonicalize], k
ey), C), dart.fn(() => new (utils.Pair$(K, V))(key, ifAbsent()), utils.Pair$(K,
V), [])).last; |
74 } | 77 } |
75 remove(key) { | 78 remove(key) { |
76 if (!dart.notNull(this[_isValidKey](key))) return null; | 79 if (!dart.notNull(this[_isValidKey](key))) return null; |
77 let pair = this[_base].remove(dart.dcall(this[_canonicalize], key)); | 80 let pair = this[_base].remove(dart.dcall(this[_canonicalize], key)); |
78 return pair == null ? null : pair.last; | 81 return pair == null ? null : pair.last; |
79 } | 82 } |
80 get values() { | 83 get values() { |
81 return dart.as(this[_base].values[dartx.map](dart.fn(pair => pair.last,
V, [utils.Pair$(K, V)])), core.Iterable$(V)); | 84 return this[_base].values[dartx.map](dart.fn(pair => pair.last, V, [util
s.Pair$(K, V)])); |
82 } | 85 } |
83 toString() { | 86 toString() { |
84 return collection.Maps.mapToString(this); | 87 return collection.Maps.mapToString(this); |
85 } | 88 } |
86 [_isValidKey](key) { | 89 [_isValidKey](key) { |
87 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))); |
88 } | 91 } |
89 } | 92 } |
90 CanonicalizedMap[dart.implements] = () => [core.Map$(K, V)]; | 93 CanonicalizedMap[dart.implements] = () => [core.Map$(K, V)]; |
91 dart.defineNamedConstructor(CanonicalizedMap, 'from'); | 94 dart.defineNamedConstructor(CanonicalizedMap, 'from'); |
(...skipping 15 matching lines...) Expand all Loading... |
107 [_isValidKey]: [core.bool, [core.Object]] | 110 [_isValidKey]: [core.bool, [core.Object]] |
108 }) | 111 }) |
109 }); | 112 }); |
110 return CanonicalizedMap; | 113 return CanonicalizedMap; |
111 }); | 114 }); |
112 let CanonicalizedMap = CanonicalizedMap$(); | 115 let CanonicalizedMap = CanonicalizedMap$(); |
113 // Exports: | 116 // Exports: |
114 exports.CanonicalizedMap$ = CanonicalizedMap$; | 117 exports.CanonicalizedMap$ = CanonicalizedMap$; |
115 exports.CanonicalizedMap = CanonicalizedMap; | 118 exports.CanonicalizedMap = CanonicalizedMap; |
116 }); | 119 }); |
OLD | NEW |