source: josm/trunk/src/org/openstreetmap/josm/data/notes/NoteComment.java

Last change on this file was 17837, checked in by simon04, 3 years ago

fix #20824 - NPE while sorting notes

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