-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonVisitor.java
More file actions
86 lines (68 loc) · 1.49 KB
/
Copy pathButtonVisitor.java
File metadata and controls
86 lines (68 loc) · 1.49 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
package A2;
public class ButtonVisitor implements Visitor{
private int userTotal = 0;
private int messageTotal = 0;
private int totalPositive = 0;
private int groupTotal = 0;
@Override
public void visitUserTotal(TwitterService ts) {
userTotal += ts.getUserList().size();
}
@Override
public void visitMessagesTotal(User user) {
messageTotal +=user.getList(5).size();
}
@Override
public void visitGroupTotal(TwitterService ts) {
groupTotal += ts.getGroupList().size();
}
@Override
public void visitPositivePercentage(User user) {
totalPositive += user.getPositive();
}
public int getUserTotal() {
return userTotal;
}
public int getMessageTotal() {
return messageTotal;
}
public String getPositivePercentage() {
if(totalPositive ==0 && messageTotal == 0){
return "0";
}
String x="";
double y = (totalPositive*100)/messageTotal;
x = y+"%";
return x;
}
public int getGroupTotal() {
return groupTotal;
}
@Override
public void setMessageZero() {
messageTotal = 0;
}
@Override
public void setPositiveZero() {
totalPositive = 0;
}
@Override
public void setGroupZero() {
groupTotal = 0;
}
@Override
public void setUserZero() {
userTotal = 0;
}
// add new visitor
@Override
public User visitLastUpdateTime(TwitterService ts) {
User lastUpdateUser = new User("null");
for (User user:ts.getUserList()){
if(user.getLastUpdateTime()>lastUpdateUser.getLastUpdateTime()){
lastUpdateUser = user;
}
}
return lastUpdateUser;
}
}