001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.data.notes; 003 004import java.util.ArrayList; 005import java.util.Date; 006import java.util.List; 007 008import org.openstreetmap.josm.data.coor.LatLon; 009 010/** 011 * A map note. It always has at least one comment since a comment is required 012 * to create a note on osm.org 013 */ 014public class Note { 015 016 public enum State { open, closed } 017 018 private long id; 019 private LatLon latLon; 020 private Date createdAt; 021 private Date closedAt; 022 private State state; 023 private List<NoteComment> comments = new ArrayList<NoteComment>(); 024 025 /** 026 * Create a note with a given location 027 * @param latLon Geographic location of this note 028 */ 029 public Note(LatLon latLon) { 030 this.latLon = latLon; 031 } 032 033 /** @return The unique OSM ID of this note */ 034 public long getId() { 035 return id; 036 } 037 038 public void setId(long id) { 039 this.id = id; 040 } 041 042 /** @return The geographic location of the note */ 043 public LatLon getLatLon() { 044 return latLon; 045 } 046 047 /** @return Date that this note was submitted */ 048 public Date getCreatedAt() { 049 return createdAt; 050 } 051 052 public void setCreatedAt(Date createdAt) { 053 this.createdAt = createdAt; 054 } 055 056 /** @return Date that this note was closed. Null if it is still open. */ 057 public Date getClosedAt() { 058 return closedAt; 059 } 060 061 public void setClosedAt(Date closedAt) { 062 this.closedAt = closedAt; 063 } 064 065 /** @return The open or closed state of this note */ 066 public State getState() { 067 return state; 068 } 069 070 public void setState(State state) { 071 this.state = state; 072 } 073 074 /** @return An ordered list of comments associated with this note */ 075 public List<NoteComment> getComments() { 076 return comments; 077 } 078 079 public void addComment(NoteComment comment) { 080 this.comments.add(comment); 081 } 082 083 /** 084 * Returns the comment that was submitted by the user when creating the note 085 * @return First comment object 086 */ 087 public NoteComment getFirstComment() { 088 return this.comments.get(0); 089 } 090 091 /** 092 * Copies values from a new note into an existing one. Used after a note 093 * has been updated on the server and the local copy needs refreshing. 094 * @param note New values to copy 095 */ 096 public void updateWith(Note note) { 097 this.comments = note.comments; 098 this.createdAt = note.createdAt; 099 this.id = note.id; 100 this.state = note.state; 101 this.latLon = note.latLon; 102 } 103 104 @Override 105 public int hashCode() { 106 final int prime = 31; 107 int result = 1; 108 result = prime * result + (int) (id ^ (id >>> 32)); 109 return result; 110 } 111 112 /** Compares notes by OSM ID */ 113 @Override 114 public boolean equals(Object obj) { 115 if (this == obj) 116 return true; 117 if (obj == null) 118 return false; 119 if (getClass() != obj.getClass()) 120 return false; 121 Note other = (Note) obj; 122 if (id != other.id) 123 return false; 124 return true; 125 } 126}