source: josm/trunk/src/org/openstreetmap/josm/data/notes/Note.java@ 10134

Last change on this file since 10134 was 10134, checked in by Don-vip, 8 years ago

sonar, javadoc

  • Property svn:eol-style set to native
File size: 3.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.notes;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.ArrayList;
7import java.util.Date;
8import java.util.List;
9import java.util.Objects;
10
11import org.openstreetmap.josm.data.coor.LatLon;
12
13/**
14 * A map note. It always has at least one comment since a comment is required to create a note on osm.org.
15 * @since 7451
16 */
17public class Note {
18
19 /** Note state */
20 public enum State {
21 /** Note is open */
22 OPEN,
23 /** Note is closed */
24 CLOSED
25 }
26
27 private long id;
28 private LatLon latLon;
29 private Date createdAt;
30 private Date closedAt;
31 private State state;
32 private List<NoteComment> comments = new ArrayList<>();
33
34 /**
35 * Create a note with a given location
36 * @param latLon Geographic location of this note
37 */
38 public Note(LatLon latLon) {
39 this.latLon = latLon;
40 }
41
42 /** @return The unique OSM ID of this note */
43 public long getId() {
44 return id;
45 }
46
47 /**
48 * Sets note id.
49 * @param id OSM ID of this note
50 */
51 public void setId(long id) {
52 this.id = id;
53 }
54
55 /** @return The geographic location of the note */
56 public LatLon getLatLon() {
57 return latLon;
58 }
59
60 /** @return Date that this note was submitted */
61 public Date getCreatedAt() {
62 return createdAt;
63 }
64
65 /**
66 * Sets date at which this note has been created.
67 * @param createdAt date at which this note has been created
68 */
69 public void setCreatedAt(Date createdAt) {
70 this.createdAt = createdAt;
71 }
72
73 /** @return Date that this note was closed. Null if it is still open. */
74 public Date getClosedAt() {
75 return closedAt;
76 }
77
78 /**
79 * Sets date at which this note has been closed.
80 * @param closedAt date at which this note has been closed
81 */
82 public void setClosedAt(Date closedAt) {
83 this.closedAt = closedAt;
84 }
85
86 /** @return The open or closed state of this note */
87 public State getState() {
88 return state;
89 }
90
91 /**
92 * Sets the note state.
93 * @param state note state (open or closed)
94 */
95 public void setState(State state) {
96 this.state = state;
97 }
98
99 /** @return An ordered list of comments associated with this note */
100 public List<NoteComment> getComments() {
101 return comments;
102 }
103
104 /**
105 * Adds a comment.
106 * @param comment note comment
107 */
108 public void addComment(NoteComment comment) {
109 comments.add(comment);
110 }
111
112 /**
113 * Returns the comment that was submitted by the user when creating the note
114 * @return First comment object
115 */
116 public NoteComment getFirstComment() {
117 return comments.isEmpty() ? null : comments.get(0);
118 }
119
120 /**
121 * Copies values from a new note into an existing one. Used after a note
122 * has been updated on the server and the local copy needs refreshing.
123 * @param note New values to copy
124 */
125 public void updateWith(Note note) {
126 this.comments = note.comments;
127 this.createdAt = note.createdAt;
128 this.id = note.id;
129 this.state = note.state;
130 this.latLon = note.latLon;
131 }
132
133 @Override
134 public int hashCode() {
135 return Objects.hash(id);
136 }
137
138 @Override
139 public boolean equals(Object obj) {
140 if (this == obj)
141 return true;
142 if (obj == null || getClass() != obj.getClass())
143 return false;
144 Note note = (Note) obj;
145 return id == note.id;
146 }
147
148 @Override
149 public String toString() {
150 return tr("Note") + " " + id + ": " + getFirstComment();
151 }
152}
Note: See TracBrowser for help on using the repository browser.