| OLD | NEW |
| (Empty) |
| 1 dart_library.library('collection/src/canonicalized_map', null, /* Imports */[ | |
| 2 'dart/_runtime', | |
| 3 'dart/core', | |
| 4 'collection/src/utils', | |
| 5 'dart/collection' | |
| 6 ], /* Lazy imports */[ | |
| 7 ], function(exports, dart, core, utils, collection) { | |
| 8 'use strict'; | |
| 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])); | |
| 16 const _base = Symbol('_base'); | |
| 17 const _canonicalize = Symbol('_canonicalize'); | |
| 18 const _isValidKeyFn = Symbol('_isValidKeyFn'); | |
| 19 const _isValidKey = Symbol('_isValidKey'); | |
| 20 const CanonicalizedMap$ = dart.generic(function(C, K, V) { | |
| 21 class CanonicalizedMap extends core.Object { | |
| 22 CanonicalizedMap(canonicalize, opts) { | |
| 23 let isValidKey = opts && 'isValidKey' in opts ? opts.isValidKey : null; | |
| 24 this[_base] = core.Map$(C, utils.Pair$(K, V)).new(); | |
| 25 this[_canonicalize] = canonicalize; | |
| 26 this[_isValidKeyFn] = isValidKey; | |
| 27 } | |
| 28 from(other, canonicalize, opts) { | |
| 29 let isValidKey = opts && 'isValidKey' in opts ? opts.isValidKey : null; | |
| 30 this[_base] = core.Map$(C, utils.Pair$(K, V)).new(); | |
| 31 this[_canonicalize] = canonicalize; | |
| 32 this[_isValidKeyFn] = isValidKey; | |
| 33 this.addAll(other); | |
| 34 } | |
| 35 get(key) { | |
| 36 if (!dart.notNull(this[_isValidKey](key))) return null; | |
| 37 let pair = this[_base][dartx.get](this[_canonicalize](dart.as(key, K))); | |
| 38 return pair == null ? null : pair.last; | |
| 39 } | |
| 40 set(key, value) { | |
| 41 (() => { | |
| 42 dart.as(key, K); | |
| 43 dart.as(value, V); | |
| 44 if (!dart.notNull(this[_isValidKey](key))) return; | |
| 45 this[_base][dartx.set](this[_canonicalize](key), new (utils.Pair$(K, V
))(key, value)); | |
| 46 })(); | |
| 47 return value; | |
| 48 } | |
| 49 addAll(other) { | |
| 50 dart.as(other, core.Map$(K, V)); | |
| 51 other[dartx.forEach](dart.fn((key, value) => { | |
| 52 dart.as(key, K); | |
| 53 dart.as(value, V); | |
| 54 return this.set(key, value); | |
| 55 }, V, [K, V])); | |
| 56 } | |
| 57 clear() { | |
| 58 this[_base][dartx.clear](); | |
| 59 } | |
| 60 containsKey(key) { | |
| 61 if (!dart.notNull(this[_isValidKey](key))) return false; | |
| 62 return this[_base][dartx.containsKey](this[_canonicalize](dart.as(key, K
))); | |
| 63 } | |
| 64 containsValue(value) { | |
| 65 return this[_base][dartx.values][dartx.any](dart.fn(pair => { | |
| 66 dart.as(pair, utils.Pair$(K, V)); | |
| 67 return dart.equals(pair.last, value); | |
| 68 }, core.bool, [utils.Pair$(K, V)])); | |
| 69 } | |
| 70 forEach(f) { | |
| 71 dart.as(f, dart.functionType(dart.void, [K, V])); | |
| 72 this[_base][dartx.forEach](dart.fn((key, pair) => { | |
| 73 dart.as(key, C); | |
| 74 dart.as(pair, utils.Pair$(K, V)); | |
| 75 return f(pair.first, pair.last); | |
| 76 }, dart.void, [C, utils.Pair$(K, V)])); | |
| 77 } | |
| 78 get isEmpty() { | |
| 79 return this[_base][dartx.isEmpty]; | |
| 80 } | |
| 81 get isNotEmpty() { | |
| 82 return this[_base][dartx.isNotEmpty]; | |
| 83 } | |
| 84 get keys() { | |
| 85 return this[_base][dartx.values][dartx.map](dart.fn(pair => { | |
| 86 dart.as(pair, utils.Pair$(K, V)); | |
| 87 return pair.first; | |
| 88 }, K, [utils.Pair$(K, V)])); | |
| 89 } | |
| 90 get length() { | |
| 91 return this[_base][dartx.length]; | |
| 92 } | |
| 93 putIfAbsent(key, ifAbsent) { | |
| 94 dart.as(key, K); | |
| 95 dart.as(ifAbsent, dart.functionType(V, [])); | |
| 96 return this[_base][dartx.putIfAbsent](this[_canonicalize](key), dart.fn(
() => new (utils.Pair$(K, V))(key, ifAbsent()), utils.Pair$(K, V), [])).last; | |
| 97 } | |
| 98 remove(key) { | |
| 99 if (!dart.notNull(this[_isValidKey](key))) return null; | |
| 100 let pair = this[_base][dartx.remove](this[_canonicalize](dart.as(key, K)
)); | |
| 101 return pair == null ? null : pair.last; | |
| 102 } | |
| 103 get values() { | |
| 104 return this[_base][dartx.values][dartx.map](dart.fn(pair => { | |
| 105 dart.as(pair, utils.Pair$(K, V)); | |
| 106 return pair.last; | |
| 107 }, V, [utils.Pair$(K, V)])); | |
| 108 } | |
| 109 toString() { | |
| 110 return collection.Maps.mapToString(this); | |
| 111 } | |
| 112 [_isValidKey](key) { | |
| 113 return (key == null || dart.is(key, K)) && (this[_isValidKeyFn] == null
|| dart.notNull(this[_isValidKeyFn](key))); | |
| 114 } | |
| 115 } | |
| 116 CanonicalizedMap[dart.implements] = () => [core.Map$(K, V)]; | |
| 117 dart.defineNamedConstructor(CanonicalizedMap, 'from'); | |
| 118 dart.setSignature(CanonicalizedMap, { | |
| 119 constructors: () => ({ | |
| 120 CanonicalizedMap: [CanonicalizedMap$(C, 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])}] | |
| 122 }), | |
| 123 methods: () => ({ | |
| 124 get: [V, [core.Object]], | |
| 125 set: [dart.void, [K, V]], | |
| 126 addAll: [dart.void, [core.Map$(K, V)]], | |
| 127 clear: [dart.void, []], | |
| 128 containsKey: [core.bool, [core.Object]], | |
| 129 containsValue: [core.bool, [core.Object]], | |
| 130 forEach: [dart.void, [dart.functionType(dart.void, [K, V])]], | |
| 131 putIfAbsent: [V, [K, dart.functionType(V, [])]], | |
| 132 remove: [V, [core.Object]], | |
| 133 [_isValidKey]: [core.bool, [core.Object]] | |
| 134 }) | |
| 135 }); | |
| 136 dart.defineExtensionMembers(CanonicalizedMap, [ | |
| 137 'get', | |
| 138 'set', | |
| 139 'addAll', | |
| 140 'clear', | |
| 141 'containsKey', | |
| 142 'containsValue', | |
| 143 'forEach', | |
| 144 'putIfAbsent', | |
| 145 'remove', | |
| 146 'isEmpty', | |
| 147 'isNotEmpty', | |
| 148 'keys', | |
| 149 'length', | |
| 150 'values' | |
| 151 ]); | |
| 152 return CanonicalizedMap; | |
| 153 }); | |
| 154 let CanonicalizedMap = CanonicalizedMap$(); | |
| 155 // Exports: | |
| 156 exports.CanonicalizedMap$ = CanonicalizedMap$; | |
| 157 exports.CanonicalizedMap = CanonicalizedMap; | |
| 158 }); | |
| OLD | NEW |