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'); |
11 const _canonicalize = Symbol('_canonicalize'); | 11 const _canonicalize = Symbol('_canonicalize'); |
12 const _isValidKeyFn = Symbol('_isValidKeyFn'); | 12 const _isValidKeyFn = Symbol('_isValidKeyFn'); |
13 const _isValidKey = Symbol('_isValidKey'); | 13 const _isValidKey = Symbol('_isValidKey'); |
14 const CanonicalizedMap$ = dart.generic(function(C, K, V) { | 14 const CanonicalizedMap$ = dart.generic(function(C, K, V) { |
15 class CanonicalizedMap extends core.Object { | 15 class CanonicalizedMap extends core.Object { |
16 CanonicalizedMap(canonicalize, opts) { | 16 CanonicalizedMap(canonicalize, opts) { |
17 let isValidKey = opts && 'isValidKey' in opts ? opts.isValidKey : null; | 17 let isValidKey = opts && 'isValidKey' in opts ? opts.isValidKey : null; |
18 this[_base] = core.Map$(C, utils.Pair$(K, V)).new(); | 18 this[_base] = core.Map$(C, utils.Pair$(K, V)).new(); |
19 this[_canonicalize] = canonicalize; | 19 this[_canonicalize] = canonicalize; |
20 this[_isValidKeyFn] = isValidKey; | 20 this[_isValidKeyFn] = isValidKey; |
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))) | 30 if (!dart.notNull(this[_isValidKey](key))) return null; |
31 return null; | |
32 let pair = this[_base].get(dart.dcall(this[_canonicalize], key)); | 31 let pair = this[_base].get(dart.dcall(this[_canonicalize], key)); |
33 return pair == null ? null : pair.last; | 32 return pair == null ? null : pair.last; |
34 } | 33 } |
35 set(key, value) { | 34 set(key, value) { |
36 dart.as(key, K); | 35 dart.as(key, K); |
37 dart.as(value, V); | 36 dart.as(value, V); |
38 this[_base].set(dart.as(dart.dcall(this[_canonicalize], key), C), new (u
tils.Pair$(K, V))(key, value)); | 37 this[_base].set(dart.as(dart.dcall(this[_canonicalize], key), C), new (u
tils.Pair$(K, V))(key, value)); |
39 return value; | 38 return value; |
40 } | 39 } |
41 addAll(other) { | 40 addAll(other) { |
42 dart.as(other, core.Map$(K, V)); | 41 dart.as(other, core.Map$(K, V)); |
43 other.forEach(dart.fn((key, value) => this.set(dart.as(key, K), dart.as(
value, V)))); | 42 other.forEach(dart.fn((key, value) => this.set(dart.as(key, K), dart.as(
value, V)))); |
44 } | 43 } |
45 clear() { | 44 clear() { |
46 this[_base].clear(); | 45 this[_base].clear(); |
47 } | 46 } |
48 containsKey(key) { | 47 containsKey(key) { |
49 if (!dart.notNull(this[_isValidKey](key))) | 48 if (!dart.notNull(this[_isValidKey](key))) return false; |
50 return false; | |
51 return this[_base].containsKey(dart.dcall(this[_canonicalize], key)); | 49 return this[_base].containsKey(dart.dcall(this[_canonicalize], key)); |
52 } | 50 } |
53 containsValue(value) { | 51 containsValue(value) { |
54 return this[_base].values[dartx.any](dart.fn(pair => dart.equals(dart.dl
oad(pair, 'last'), value), core.bool, [dart.dynamic])); | 52 return this[_base].values[dartx.any](dart.fn(pair => dart.equals(dart.dl
oad(pair, 'last'), value), core.bool, [dart.dynamic])); |
55 } | 53 } |
56 forEach(f) { | 54 forEach(f) { |
57 dart.as(f, dart.functionType(dart.void, [K, V])); | 55 dart.as(f, dart.functionType(dart.void, [K, V])); |
58 this[_base].forEach(dart.fn((key, pair) => f(dart.as(dart.dload(pair, 'f
irst'), K), dart.as(dart.dload(pair, 'last'), V)), dart.void, [dart.dynamic, dar
t.dynamic])); | 56 this[_base].forEach(dart.fn((key, pair) => f(dart.as(dart.dload(pair, 'f
irst'), K), dart.as(dart.dload(pair, 'last'), V)), dart.void, [dart.dynamic, dar
t.dynamic])); |
59 } | 57 } |
60 get isEmpty() { | 58 get isEmpty() { |
61 return this[_base].isEmpty; | 59 return this[_base].isEmpty; |
62 } | 60 } |
63 get isNotEmpty() { | 61 get isNotEmpty() { |
64 return this[_base].isNotEmpty; | 62 return this[_base].isNotEmpty; |
65 } | 63 } |
66 get keys() { | 64 get keys() { |
67 return dart.as(this[_base].values[dartx.map](dart.fn(pair => dart.dload(
pair, 'first'))), core.Iterable$(K)); | 65 return dart.as(this[_base].values[dartx.map](dart.fn(pair => dart.dload(
pair, 'first'))), core.Iterable$(K)); |
68 } | 66 } |
69 get length() { | 67 get length() { |
70 return this[_base].length; | 68 return this[_base].length; |
71 } | 69 } |
72 putIfAbsent(key, ifAbsent) { | 70 putIfAbsent(key, ifAbsent) { |
73 dart.as(key, K); | 71 dart.as(key, K); |
74 dart.as(ifAbsent, dart.functionType(V, [])); | 72 dart.as(ifAbsent, dart.functionType(V, [])); |
75 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; | 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 } | 74 } |
77 remove(key) { | 75 remove(key) { |
78 if (!dart.notNull(this[_isValidKey](key))) | 76 if (!dart.notNull(this[_isValidKey](key))) return null; |
79 return null; | |
80 let pair = this[_base].remove(dart.dcall(this[_canonicalize], key)); | 77 let pair = this[_base].remove(dart.dcall(this[_canonicalize], key)); |
81 return pair == null ? null : pair.last; | 78 return pair == null ? null : pair.last; |
82 } | 79 } |
83 get values() { | 80 get values() { |
84 return dart.as(this[_base].values[dartx.map](dart.fn(pair => dart.dload(
pair, 'last'))), core.Iterable$(V)); | 81 return dart.as(this[_base].values[dartx.map](dart.fn(pair => dart.dload(
pair, 'last'))), core.Iterable$(V)); |
85 } | 82 } |
86 toString() { | 83 toString() { |
87 return collection.Maps.mapToString(this); | 84 return collection.Maps.mapToString(this); |
88 } | 85 } |
89 [_isValidKey](key) { | 86 [_isValidKey](key) { |
(...skipping 20 matching lines...) Expand all Loading... |
110 [_isValidKey]: [core.bool, [core.Object]] | 107 [_isValidKey]: [core.bool, [core.Object]] |
111 }) | 108 }) |
112 }); | 109 }); |
113 return CanonicalizedMap; | 110 return CanonicalizedMap; |
114 }); | 111 }); |
115 let CanonicalizedMap = CanonicalizedMap$(); | 112 let CanonicalizedMap = CanonicalizedMap$(); |
116 // Exports: | 113 // Exports: |
117 exports.CanonicalizedMap$ = CanonicalizedMap$; | 114 exports.CanonicalizedMap$ = CanonicalizedMap$; |
118 exports.CanonicalizedMap = CanonicalizedMap; | 115 exports.CanonicalizedMap = CanonicalizedMap; |
119 }); | 116 }); |
OLD | NEW |