1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.notes;
|
---|
3 |
|
---|
4 | import java.util.Comparator;
|
---|
5 | import java.util.Date;
|
---|
6 |
|
---|
7 | import org.openstreetmap.josm.data.osm.User;
|
---|
8 | import org.openstreetmap.josm.tools.date.DateUtils;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * Represents a comment made on a note. All notes have at least on comment
|
---|
12 | * which is the comment the note was opened with. Comments are immutable.
|
---|
13 | * @since 7451
|
---|
14 | */
|
---|
15 | public class NoteComment {
|
---|
16 |
|
---|
17 | private final String text;
|
---|
18 | private final User user;
|
---|
19 | private final Date commentTimestamp;
|
---|
20 | private final Action action;
|
---|
21 |
|
---|
22 | //not currently used. I'm planning on using this to keep track of new actions that need to be uploaded
|
---|
23 | private boolean isNew;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Every comment has an associated action. Some comments are just comments
|
---|
27 | * while others indicate the note being opened, closed or reopened
|
---|
28 | */
|
---|
29 | public enum Action {
|
---|
30 | /** note has been opened */
|
---|
31 | OPENED,
|
---|
32 | /** note has been closed */
|
---|
33 | CLOSED,
|
---|
34 | /** note has been reopened */
|
---|
35 | REOPENED,
|
---|
36 | /** note has been commented */
|
---|
37 | COMMENTED,
|
---|
38 | /** note has been hidden */
|
---|
39 | HIDDEN
|
---|
40 | }
|
---|
41 |
|
---|
42 | /** Sorts note comments strictly by creation date */
|
---|
43 | public static final Comparator<NoteComment> DATE_COMPARATOR = (n1, n2) -> n1.commentTimestamp.compareTo(n2.commentTimestamp);
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * @param createDate The time at which this comment was added
|
---|
47 | * @param user JOSM User object of the user who created the comment
|
---|
48 | * @param commentText The text left by the user. Is sometimes blank
|
---|
49 | * @param action The action associated with this comment
|
---|
50 | * @param isNew Whether or not this comment is new and needs to be uploaded
|
---|
51 | */
|
---|
52 | public NoteComment(Date createDate, User user, String commentText, Action action, boolean isNew) {
|
---|
53 | this.text = commentText;
|
---|
54 | this.user = user;
|
---|
55 | this.commentTimestamp = DateUtils.cloneDate(createDate);
|
---|
56 | this.action = action;
|
---|
57 | this.isNew = isNew;
|
---|
58 | }
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Returns Plain text of user's comment.
|
---|
62 | * @return Plain text of user's comment
|
---|
63 | */
|
---|
64 | public String getText() {
|
---|
65 | return text;
|
---|
66 | }
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Returns the user who made this comment.
|
---|
70 | * @return JOSM's User object for the user who made this comment
|
---|
71 | */
|
---|
72 | public User getUser() {
|
---|
73 | return user;
|
---|
74 | }
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Returns the time at which this comment was created.
|
---|
78 | * @return The time at which this comment was created
|
---|
79 | */
|
---|
80 | public Date getCommentTimestamp() {
|
---|
81 | return DateUtils.cloneDate(commentTimestamp);
|
---|
82 | }
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * Returns the action associated with this note.
|
---|
86 | * @return the action associated with this note
|
---|
87 | */
|
---|
88 | public Action getNoteAction() {
|
---|
89 | return action;
|
---|
90 | }
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Sets whether this is a new comment/action and needs to be uploaded to the API
|
---|
94 | * @param isNew {@code true} if this is a new comment/action and needs to be uploaded to the API
|
---|
95 | */
|
---|
96 | public void setNew(boolean isNew) {
|
---|
97 | this.isNew = isNew;
|
---|
98 | }
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Determines if this is a new comment/action and needs to be uploaded to the API
|
---|
102 | * @return true if this is a new comment/action and needs to be uploaded to the API
|
---|
103 | */
|
---|
104 | public boolean isNew() {
|
---|
105 | return isNew;
|
---|
106 | }
|
---|
107 |
|
---|
108 | @Override
|
---|
109 | public String toString() {
|
---|
110 | return text;
|
---|
111 | }
|
---|
112 | }
|
---|