-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.java
More file actions
161 lines (136 loc) · 4.17 KB
/
User.java
File metadata and controls
161 lines (136 loc) · 4.17 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE
package elements;
import java.io.File;
import java.io.PrintStream;
import java.util.ArrayList;
import boxes.Inbox;
import boxes.Outbox;
/**
* Represents a user.
* @author leylayayladere
* @version 1.0
*/
public class User {
/**
* <i>Unique<i> <code>id</code> of each <code>User</code>.
*/
private int id;
/**
* Inbox object belongs to this <code>User</code>.
*/
private Inbox inbox;
/**
* Outbox object belongs to this <code>User</code>.
*/
private Outbox outbox;
/**
* Keeps track of all users who are currently friends with this <code>User</code>.
*/
private ArrayList<User> friends = new ArrayList<User>();
/**
* Creates a <code>User</code> with specified <code>id</code>.
* @param id <i>Unique<i> <code>id</code> of this <code>User</code>.
*/
public User(int id) {
this.setId(id);
this.inbox = new Inbox(this);
this.outbox = new Outbox(this);
}
/**
* Adds <code>User</code> <code>other</code> to <code>friends</code> <i>list<i> of this <code>User</code> and vice versa.
* @param other <code>User</code> who become friend with this <code>User</code>.
*/
public void addFriend(User other) {
this.getFriends().add(other);
other.getFriends().add(this);
}
/**
* Removes <code>User</code> <code>other</code> from <code>friends</code> <i>list<i> of this <code>User</code> and vice versa.
* @param other <code>User</code> who ends friendship with this <code>User</code>.
*/
public void removeFriend(User other) {
this.getFriends().remove(other);
other.getFriends().remove(this);
}
/**
* Checks this <code>User</code> whether is friend with <code>other</code> <code>User</code> or not.
* @param other <code>User</code> who will be checked whether is friend with this <code>User</code> or not.
* @return A boolean data type. True if this <code>User</code> is friend with <code>other</code> <code>User</code>, false if she/he is not.
*/
public boolean isFriendWith(User other) {
if(this.getFriends().contains(other)) {
return true;
}else {
return false;
}
}
/**
* Sends <code>Message</code> which contains <code>body</code> text from this <code>User</code> to <code>receiver</code> through <code>server</code>.
* @param receiver <code>User</code> who receives <code>Message</code>.
* @param body Text content of <code>Message</code>.
* @param time Stamp time sending of <code>Message</code>.
* @param server Functions as the mechanism where all non-received messages are stored.
*/
public void sendMessage(User receiver, String body, int time, Server server) {
Message m = new Message(this, receiver, body, server, time);
this.getOutbox().getSent().add(m);
server.setCurrentSize(server.getCurrentSize() + m.getBody().length());
}
/**
* Retrieves the value of an <code>id</code>.
* @return An integer data type.
*/
public int getId() {
return id;
}
/**
* Sets the value of an <code>id</code>.
* @param id A variable of type integer.
*/
public void setId(int id) {
this.id = id;
}
/**
* Retrieves the value of a <code>inbox</code> of this <code>User</code>.
* @return An object <code>Inbox</code> data type.
*/
public Inbox getInbox() {
return inbox;
}
/**
* Sets the value of an <code>inbox</code> of this <code>User</code>.
* @param inbox A variable of type object <code>Box</code>.
*/
public void setInbox(Inbox inbox) {
this.inbox = inbox;
}
/**
* Retrieves the value of a <code>outbox</code> of this <code>User</code>.
* @return An object <code>Outbox</code> data type.
*/
public Outbox getOutbox() {
return outbox;
}
/**
* Sets the value of an <code>outbox</code> of this <code>User</code>.
* @param outbox A variable of type object <code>Box</code>.
*/
public void setOutbox(Outbox outbox) {
this.outbox = outbox;
}
/**
* Retrieves the value of a <code>friends</code> <i>list<i>.
* @return A list data type.
*/
public ArrayList<User> getFriends() {
return friends;
}
/**
* Sets the value of a <code>friends</code> <i>list<i>.
* @param friends A variable of type list.
*/
public void setFriends(ArrayList<User> friends) {
this.friends = friends;
}
}
//DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE