-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNameChecker.js
37 lines (31 loc) · 961 Bytes
/
NameChecker.js
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
//this class is for checking whether a proposed new username is already held by another user
//moving to a database approach for data storage will make it unnecessary, or at least
//it can be converted to a wrapper class for the database calls
class NameChecker{
constructor(){
this.IDToNameMap=new Map();
this.NameToIDMap=new Map();
}
getIDFromName(username){
var ID=this.NameToIDMap.get(username);
if(ID===undefined){
return null;
}
}
getNameFromID(ID){
var username=this.IDToNameMap.get(ID);
if(username===undefined){
return null;
}
}
addIDAndName(ID,username){
this.IDToNameMap.set(ID,username);
this.NameToIDMap.set(username,ID);
}
removeID(ID){
var username=this.IDToNameMap.get(ID);
this.IDToNameMap.delete(ID);
this.NameToIDMap.delete(username);
}
}
module.exports = NameChecker;