-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparty.prop
More file actions
86 lines (78 loc) · 1.77 KB
/
party.prop
File metadata and controls
86 lines (78 loc) · 1.77 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
(
"initial"
(fn ()
(let ((state (new-obj)))
(put state "name" "unnamed")
(put state "objects" (new))
state
))
"operations"
(
"addObj"
(fn (state op)
(let ((item (get op "item"))
(id (get item "id"))
(objects (get state "objects")))
(put objects id item)
state
))
"deleteObj"
(fn (state op)
(let ((id (get op "itemId"))
(objects (get state "objects")))
(del objects id)
state
))
"setName"
(fn (state op)
(let ((name (get op "name")))
(put state "name" name)
state
))
"resetVoteHistory"
(fn (state op)
(put state "voteHistory" (new-obj)))
"vote"
(fn (state op)
(let ((id (get op "itemId"))
(count (get op "count"))
(objects (get state "objects"))
(obj (get objects id))
(cur (get obj "votes")))
(put obj "votes" (+ cur count))
))
)
)
if(type.equals("addObj")){
JSONObject item = op.optJSONObject("item");
String id = item.optString("id");
objects.put(id, (new JSONObjWrapper(item)));
}
else if(type.equals("deleteObj")){
String id = op.optString("itemId");
objects.remove(id);
}
else if(type.equals("setName")){
String name = op.optString("name");
this.name = name;
}
else if(type.equals("resetVoteHistory")){
this.voteHistory.clear();
}
else if(type.equals("vote")){
String id = op.optString("itemId");
int count = op.optInt("count");
JSONObject o = objects.get(id);
if(o != null){
int cur = o.optInt("votes");
try{
o.put("votes", cur + count);
}
catch(JSONException e){
e.printStackTrace(System.err);
}
}
else{
System.err.println("Couldn't find object for id: " + id);
}
}