001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.data.notes; 003 004import java.time.Instant; 005import java.util.Comparator; 006 007import org.openstreetmap.josm.data.osm.User; 008 009/** 010 * Represents a comment made on a note. All notes have at least on comment 011 * which is the comment the note was opened with. Comments are immutable. 012 * @since 7451 013 */ 014public class NoteComment { 015 016 private final String text; 017 private final User user; 018 private final Instant commentTimestamp; 019 private final Action action; 020 021 //not currently used. I'm planning on using this to keep track of new actions that need to be uploaded 022 private boolean isNew; 023 024 /** 025 * Every comment has an associated action. Some comments are just comments 026 * while others indicate the note being opened, closed or reopened 027 */ 028 public enum Action { 029 /** note has been opened */ 030 OPENED, 031 /** note has been closed */ 032 CLOSED, 033 /** note has been reopened */ 034 REOPENED, 035 /** note has been commented */ 036 COMMENTED, 037 /** note has been hidden */ 038 HIDDEN 039 } 040 041 /** Sorts note comments strictly by creation date */ 042 public static final Comparator<NoteComment> DATE_COMPARATOR = Comparator.nullsLast(Comparator.comparing(n -> n.commentTimestamp)); 043 044 /** 045 * @param createDate The time at which this comment was added 046 * @param user JOSM User object of the user who created the comment 047 * @param commentText The text left by the user. Is sometimes blank 048 * @param action The action associated with this comment 049 * @param isNew Whether or not this comment is new and needs to be uploaded 050 */ 051 public NoteComment(Instant createDate, User user, String commentText, Action action, boolean isNew) { 052 this.text = commentText; 053 this.user = user; 054 this.commentTimestamp = createDate; 055 this.action = action; 056 this.isNew = isNew; 057 } 058 059 /** 060 * Returns Plain text of user's comment. 061 * @return Plain text of user's comment 062 */ 063 public String getText() { 064 return text; 065 } 066 067 /** 068 * Returns the user who made this comment. 069 * @return JOSM's User object for the user who made this comment 070 */ 071 public User getUser() { 072 return user; 073 } 074 075 /** 076 * Returns the time at which this comment was created. 077 * @return The time at which this comment was created 078 */ 079 public Instant getCommentTimestamp() { 080 return commentTimestamp; 081 } 082 083 /** 084 * Returns the action associated with this note. 085 * @return the action associated with this note 086 */ 087 public Action getNoteAction() { 088 return action; 089 } 090 091 /** 092 * Sets whether this is a new comment/action and needs to be uploaded to the API 093 * @param isNew {@code true} if this is a new comment/action and needs to be uploaded to the API 094 */ 095 public void setNew(boolean isNew) { 096 this.isNew = isNew; 097 } 098 099 /** 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}