-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessage.java
More file actions
233 lines (205 loc) · 5.48 KB
/
Message.java
File metadata and controls
233 lines (205 loc) · 5.48 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
//DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE
package elements;
/**
* Represents a message.
* @author leylayayladere
* @version 1.0
*/
public class Message {
/**
* <i>Static<i> number of total messages in the program.
*/
static int numOfMessages=0;
/**
* <i>Unique<i> <code>id</code> of each <code>Message</code>.
*/
private int id;
/**
* Text of this <code>Message</code>.
*/
private String body;
/**
* Sender of this <code>Message</code>.
*/
private User sender;
/**
* Receiver of this <code>Message</code>.
*/
private User receiver;
/**
* Time stamp sending of this <code>Message</code>.
*/
private int timeStampSent;
/**
* Time stamp reading of this <code>Message</code>.
*/
private int timeStampRead;
/**
* Time stamp receiving of this <code>Message</code>.
*/
private int timeStampReceived;
/**
* Creates a <code>Message</code> with specified parameters.
* @param sender <code>User</code> who sends the <code>Message</code>.
* @param receiver <code>User</code> who receives the <code>Message</code>.
* @param body Text content of <code>Message</code>.
* @param server Functions as the mechanism where all non-received messages are stored.
* @param time Stamp time sending of <code>Message</code>.
*/
public Message(User sender, User receiver, String body, Server server, int time) {
this.setSender(sender);
this.setReceiver(receiver);
this.setBody(body);
this.setTimeStampSent(time);
this.setID(numOfMessages);
numOfMessages++;
server.getMsgs().add(this);
}
/**
* Retrieves the value of time stamp sending.
* @return An integer data type.
*/
public int getTimeStampSent() {
return this.timeStampSent;
}
/**
* Sets the value of time stamp sending.
* @param timeStampSent A variable of type integer.
*/
public void setTimeStampSent(int timeStampSent) {
this.timeStampSent = timeStampSent;
}
/**
* Retrieves the value of time stamp reading.
* @return An integer data type.
*/
public int getTimeStampRead() {
return this.timeStampRead;
}
/**
* Sets the value of time stamp reading.
* @param timeStampRead A variable of type integer.
*/
public void setTimeStampRead(int timeStampRead) {
this.timeStampRead = timeStampRead;
}
/**
* Retrieves the value of time stamp receiving.
* @return An integer data type.
*/
public int getTimeStampReceived() {
return this.timeStampReceived;
}
/**
* Sets the value of time stamp receiving.
* @param timeStampReceived A variable of type integer.
*/
public void setTimeStampReceived(int timeStampReceived) {
this.timeStampReceived = timeStampReceived;
}
/**
* Retrieves the value of an <code>id</code>.
* @return An integer data type.
*/
public int getID( ) {
return this.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>body</code> of this <code>Message</code>.
* @return A String data type.
*/
public String getBody() {
return this.body;
}
/**
* Sets the value of a <code>body</code> of this <code>Message</code>.
* @param body A variable of type String.
*/
public void setBody(String body) {
this.body = body;
}
/**
* If this <code>Message</code> is longer than <code>o</code>, return
* positive number. Else if the <code>o</code> is longer, return negative number. Return 0 if both
* messages have the same number of characters.
* @param o Compared <code>Message</code>.
* @return An integer data type.
*/
public int compareTo(Message o) {
if(this.body.length() > o.body.length()) {
return 1;
}else if(this.body.length() < o.body.length()){
return -1;
}else{
return 0;
}
}
/**
* Checks this <code>Message</code> whether is equal to object <code>o</code> or not.
* @param o Object which will be checked whether is equal to this <code>Message</code> or not.
* @return A boolean data type. True if they are equal, false they are not.
*/
public boolean equals(Object o) {
if(o instanceof Message) {
if(this.getID() == ((Message) o).getID()) {
return true;
}else {
return false;
}
}else {
return false;
}
}
/**
* Forms information about this <code>Message</code>.
* @return A String data type.
*/
public String toString() {
String form = "\tFrom: " + this.getSender().getId() + " To: " + this.getReceiver().getId() + "\n\tReceived: ";
if(this.getTimeStampReceived() != 0) {
form += this.getTimeStampReceived();
}
form += " Read: ";
if(this.getTimeStampRead() != 0) {
form += this.getTimeStampRead();
}
form += "\n\t" + this.getBody();
return form;
}
/**
* Retrieves the value of a <code>sender</code> of this <code>Message</code>.
* @return An object <code>User</code> data type.
*/
public User getSender() {
return sender;
}
/**
* Sets the value of an <code>sender</code> of this <code>Message</code>.
* @param sender A variable of type object <code>User</code>.
*/
public void setSender(User sender) {
this.sender = sender;
}
/**
* Retrieves the value of a <code>receiver</code> of this <code>Message</code>.
* @return An object <code>User</code> data type.
*/
public User getReceiver() {
return receiver;
}
/**
* Sets the value of an <code>receiver</code> of this <code>Message</code>.
* @param receiver A variable of type object <code>User</code>.
*/
public void setReceiver(User receiver) {
this.receiver = receiver;
}
}
//DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE