-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPost.java
More file actions
46 lines (37 loc) · 953 Bytes
/
Post.java
File metadata and controls
46 lines (37 loc) · 953 Bytes
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
import java.util.Date;
public class Post {
private int id;
private Date timestamp;
private String message;
private int authorId;
private int likes;
public Post( String message ) {
// TODO implement, set default values for timestamp, likes, authorId
this.message = message;
this.timestamp = new Date();
}
public void setId( int id ) {
this.id = id;
}
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append( String.format("[Post %d] %d likes, created %s\n", this.id, this.likes, this.timestamp.toString() ) );
buffer.append( message );
return buffer.toString();
}
public void like() {
// TODO implement
}
public void dislike() {
// TODO implementation
}
public String serialize() {
return String.format( "%d,%d,%s,%d,%d\n",
this.id,
this.timestamp.getTime(),
this.message,
this.likes,
this.authorId
);
}
}