forked from Zakelly/PKUGetClassHelper
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcourse.js
46 lines (43 loc) · 1.07 KB
/
course.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
38
39
40
41
42
43
44
45
46
/*
* 课程类
* @author Zakelly
*/
// 需要的域:除了构造参数,还需要$tr、name、currElectNum、maxElectNum
var Course = function(id, number, index, salt) {
this.id = id;
this.number = number;
this.index = index;
this.isDone = false;
this.salt = salt;
};
Course.prototype.courses = new Map();
Course.prototype.elect = function() {
elect(this);
};
Course.prototype.save = function () {
this.courses.put(this.getHash(), this);
};
Course.prototype.refreshIndex = function(i) {
if (i > 0) {
for(var course in this.courses) {
if (course.index > i) {
course.index--;
}
}
}
};
String.prototype.hashCode = function() {
var hash = 0;
if (this.length == 0) {
return hash;
}
for (var i = 0; i < this.length; i++) {
var char = this.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash = hash & hash; // Convert to 32bit integer
}
return hash;
};
Course.prototype.getHash = function () {
return (this.id + this.salt).hashCode();
};