-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathComment.java
145 lines (139 loc) · 3.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
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
import java.util.ArrayList;
import java.util.UUID;
import java.time.LocalDateTime;
/**
* @author Cam Osterholt & SB
* @version v1.0
* Date: 10/10/2023
*/
public class Comment {
private UUID id;
private String comment;
private User author;
private LocalDateTime time;
private ArrayList<Comment> comments;
/**
* Construct a new comment with the given content and sets the author
* @param comment The content of the comments
*/
public Comment(String comment) {
editComment(comment);
setID(UUID.randomUUID());
init();
}
/**
* Add reply to comment with an Author in mind and reply text.
* @param comment: the author text content
*/
public void reply(String comment) {
if(comment != null) {
Comment reply = new Comment(comment);
comments.add(reply);
}
}
private void init() {
time = LocalDateTime.now();
comments = new ArrayList<Comment>();
setAuthor(AppFacade.getInstance().getActiveUser());
}
/**
* get unique ID of the comment
* @return returns unique of the comment
*/
public UUID getID() {
return this.id;
}
private boolean setID(UUID id) {
if(id == null)
return false;
this.id = id;
return true;
}
/**
* Get the time/date when comment was created
* @return show the time/date of the comment
*/
public LocalDateTime getTime() {
return time;
}
/**
* Set the time/date for the comment
* @param time time/date for the comment
*/
public void setTime(LocalDateTime time) {
this.time = time;
}
/**
* Get the txt content of the comment
* @return the text content of the comment
*/
public String getComment() {
return comment;
}
/**
* edit the comment and update the time/date
* @param comment comment The updated comment content
*/
public void editComment(String comment) {
if(comment != null) {
this.comment = comment;
this.time = LocalDateTime.now();
}
}
/**
* Get the author comment
* @return author of the comment
*/
public User getAuthor() {
return author;
}
/**
* Set Author's comment
* @param author new auhtor's comment
* @return true if the author is successful, false if the author is invalid
*/
public boolean setAuthor(User author) {
if(author != null) {
this.author = author;
return true;
}
else {
System.out.println("Invalid Author.");
return false;
}
}
/**
* Get list of comments replying to this comment.
* @return list of reply comments.
*/
public ArrayList<Comment> getComments() {
return comments;
}
/**
* Delete a comment with the specified ID
* @param id The ID of the comment to be deleted
* @return true if a comment with the specified ID was found and deleted.
*/
public boolean deleteComment(UUID id) {
for(Comment comment : this.comments) {
if(comment.getID().equals(id)) {
comments.remove(comment);
return true;
}
if(comment.deleteComment(id))
return true;
}
return false;
}
/**
* get a string representation of the comment, including its content and sub-comments.
* @return A string representation of the comment
*/
public String toString(){
String toReturn = "\n Comment: " + comment;
toReturn += "\n Author: " + this.author;
if(comments!=null)
toReturn += "\n Sub-Comments: " + comments.toString();
return toReturn;
}
}