OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
3 * Copyright (C) 2012 Google Inc. All rights reserved. | 3 * Copyright (C) 2012 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1274 | 1274 |
1275 /** | 1275 /** |
1276 * @return {!Array<!KEY>} | 1276 * @return {!Array<!KEY>} |
1277 */ | 1277 */ |
1278 Map.prototype.keysArray = function() | 1278 Map.prototype.keysArray = function() |
1279 { | 1279 { |
1280 return Array.from(this.keys()); | 1280 return Array.from(this.keys()); |
1281 } | 1281 } |
1282 | 1282 |
1283 /** | 1283 /** |
| 1284 * @return {!Multimap<!KEY, !VALUE>} |
| 1285 */ |
| 1286 Map.prototype.inverse = function() |
| 1287 { |
| 1288 var result = new Multimap(); |
| 1289 for (var key of this.keys()) { |
| 1290 var value = this.get(key); |
| 1291 result.set(value, key); |
| 1292 } |
| 1293 return result; |
| 1294 } |
| 1295 |
| 1296 /** |
1284 * @constructor | 1297 * @constructor |
1285 * @template K, V | 1298 * @template K, V |
1286 */ | 1299 */ |
1287 var Multimap = function() | 1300 var Multimap = function() |
1288 { | 1301 { |
1289 /** @type {!Map.<K, !Set.<!V>>} */ | 1302 /** @type {!Map.<K, !Set.<!V>>} */ |
1290 this._map = new Map(); | 1303 this._map = new Map(); |
1291 } | 1304 } |
1292 | 1305 |
1293 Multimap.prototype = { | 1306 Multimap.prototype = { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1523 * @param {T} defaultValue | 1536 * @param {T} defaultValue |
1524 * @return {!Promise.<T>} | 1537 * @return {!Promise.<T>} |
1525 * @template T | 1538 * @template T |
1526 */ | 1539 */ |
1527 Promise.prototype.catchException = function(defaultValue) { | 1540 Promise.prototype.catchException = function(defaultValue) { |
1528 return this.catch(function (error) { | 1541 return this.catch(function (error) { |
1529 console.error(error); | 1542 console.error(error); |
1530 return defaultValue; | 1543 return defaultValue; |
1531 }); | 1544 }); |
1532 } | 1545 } |
OLD | NEW |