1
0
mirror of https://github.com/quinton-ashley/java2js synced 2024-12-29 10:11:54 +01:00
java2js/jdk/java/util/AbstractMap.js
Quinton Ashley 213f552d52 1.1.4
2022-02-01 21:32:29 -05:00

81 lines
1.4 KiB
JavaScript

jdk.imports['java.util.AbstractMap'].load = async () => {
let AbstractCollection = await jdk.import('java.util.AbstractCollection');
let Set = await jdk.import('java.util.Set');
class AbstractMap {
constructor(co) {
this.map = co || {};
class SimpleEntry {
constructor(key, val) {
this.key = key;
this.val = val;
}
getKey() {
return this.key;
}
getValue() {
return this.val;
}
toString() {
return this.key + '=' + this.val;
}
}
this.SimpleEntry = SimpleEntry;
}
clear() {
this.map = {};
}
containsKey(key) {
return this.map.hasOwnProperty(key);
}
containsValue(val) {
return Object.values(this.map).find((x) => x == val) ? true : false;
}
get(key) {
return this.map[key] || null;
}
isEmpty() {
return Object.keys(this.map).length == 0;
}
entrySet() {
let set = new Set();
for (let key in this.map) {
set.add(new this.SimpleEntry(key, this.map[key]));
}
return set;
}
put(key, value) {
const previous_val = this.map[key];
this.map[key] = value;
return previous_val || null;
}
remove(key) {
if (!this.map[key]) return null;
const val = this.map[key];
delete this.map[key];
return val;
}
values() {
const co = new AbstractCollection(Object.values(this.map));
return co;
}
size() {
return Object.keys(this.map).length;
}
}
jdk.java.util.AbstractMap = AbstractMap;
};