-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComment.java
99 lines (77 loc) · 1.78 KB
/
Comment.java
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
import java.io.*;
import java.util.*;
import java.text.*;
public class Comment implements Serializable, Comparator<Comment>, Comparable<Comment>
{
private String text = "";
private User author = new User();
private Discussion parent;
private Date dateCreated;
private Date dateEdited;
private String latestEdit = "";
private int karma;
public Comment() {}
public Comment(String text){
this.text = text;
setTimeEdited(false);
}
public Comment(String text, User author){
this.text = text;
this.author = author;
setTimeEdited(false);
}
public String getText(){
return text;
}
public void setText(String text){
this.text = text;
}
public User getAuthor(){
return author;
}
public void setAuthor(User author){
this.author = author;
}
public void setParent(Discussion parent){
this.parent = parent;
}
public String toString(){
return text;
}
public void upvote(){
karma++;
}
public void downvote(){
karma--;
}
public int getKarma(){
return karma;
}
public void setTimeEdited(boolean edit){
Date date = new Date();
if(edit)
dateEdited = date;
else
dateCreated = date;
SimpleDateFormat ft = new SimpleDateFormat("E dd.MM.yyyy 'at' hh:mm a");
latestEdit = ft.format(date);
}
public String getTimeEdited(){
return latestEdit;
}
public void deleteThis(){
parent.removeComment(this);
}
public int compareTo(Comment c){
if((new Integer(karma)).compareTo(c.karma) == 0)
return c.dateCreated.compareTo(dateCreated);
else
return (new Integer(karma)).compareTo(c.karma);
}
public int compare(Comment c1, Comment c2){
if((new Integer(c1.karma)).compareTo(c2.karma) == 0)
return c2.dateCreated.compareTo(c1.dateCreated);
else
return (new Integer(c1.karma)).compareTo(c2.karma);
}
}