-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashMap.js
More file actions
67 lines (60 loc) · 1.22 KB
/
Copy pathHashMap.js
File metadata and controls
67 lines (60 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import ArrayList from './ArrayList'
import MapInterface from './Map'
import HashSet from './HashSet'
import MapPolyfill from '../../Map'
let MapImpl = typeof Map === 'undefined' || !Map.prototype.values ? MapPolyfill : Map
/**
* @see http://download.oracle.com/javase/6/docs/api/java/util/HashMap.html
*
* @extends {javascript.util.Map}
* @constructor
* @private
*/
export default function HashMap () {
/**
* @type {Object}
* @private
*/
this.map_ = new MapImpl()
}
HashMap.prototype = new MapInterface()
/**
* @override
*/
HashMap.prototype.get = function (key) {
return this.map_.get(key) || null
}
/**
* @override
*/
HashMap.prototype.put = function (key, value) {
this.map_.set(key, value)
return value
}
/**
* @override
*/
HashMap.prototype.values = function () {
const arrayList = new ArrayList()
const it = this.map_.values()
let o = it.next()
while (!o.done) {
arrayList.add(o.value)
o = it.next()
}
return arrayList
}
/**
* @override
*/
HashMap.prototype.entrySet = function () {
const hashSet = new HashSet()
this.map_.entries().forEach(entry => hashSet.add(entry))
return hashSet
}
/**
* @override
*/
HashMap.prototype.size = function () {
return this.map_.size()
}