I need to migrate a code in java to javascript. In java, I am maintaining a hashmap with key = string and value = arraylist of objects
I need to implement the same in javascript:
this.hashMap = new Hash();
this.hashMapArrayList =[];
...
var hashMapDataSet = new HashMapDataSet(id1,name1,type1);
this.hashMapArrayList[0] = hashMapDataSet;
...
this.hashMap.set(fileName1, this.hashMapArrayList);
var hashMapDataSet1= new HashMapDataSet(id2,name2,type2);
this.hashMapArrayList[0] = hashMapDataSet1;
this.hashMap.set(fileName2, this.hashMapArrayList);
But when I try to get the properties for a specified key
this.hashMap.get(fileName1).getId()
I get the value= id2 which is the last id that was set for HashMapDataSet object.
I have tried to mimic getters and setters in javascript as specified in the following link: http://javascript.crockford.com/private.html
Here is the HashMapDataSet class
function HashMapDataSet(pId, pName, pType) {
var id = pId;
var name = pName;
var type = pType;
function getId1() {
return id;
}
function setId1(mId) {
id = mId;
}
....
this.getId = function () {
return getId1();
};
this.setId = function (id) {
setId1(id);
};
...
}
where getId1, setId1 are private methods and getId, setId are priviledged methods
I am new to javascript, so I am unable to correlate java object with javascript. Kindly help.