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