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

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

add more unit tests

  • Property svn:eol-style set to native
File size: 3.0 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
15 * to create a note on osm.org
16 */
17public class Note {
18
19 public enum State { open, closed }
20
21 private long id;
22 private LatLon latLon;
23 private Date createdAt;
24 private Date closedAt;
25 private State state;
26 private List<NoteComment> comments = new ArrayList<>();
27
28 /**
29 * Create a note with a given location
30 * @param latLon Geographic location of this note
31 */
32 public Note(LatLon latLon) {
33 this.latLon = latLon;
34 }
35
36 /** @return The unique OSM ID of this note */
37 public long getId() {
38 return id;
39 }
40
41 public void setId(long id) {
42 this.id = id;
43 }
44
45 /** @return The geographic location of the note */
46 public LatLon getLatLon() {
47 return latLon;
48 }
49
50 /** @return Date that this note was submitted */
51 public Date getCreatedAt() {
52 return createdAt;
53 }
54
55 public void setCreatedAt(Date createdAt) {
56 this.createdAt = createdAt;
57 }
58
59 /** @return Date that this note was closed. Null if it is still open. */
60 public Date getClosedAt() {
61 return closedAt;
62 }
63
64 public void setClosedAt(Date closedAt) {
65 this.closedAt = closedAt;
66 }
67
68 /** @return The open or closed state of this note */
69 public State getState() {
70 return state;
71 }
72
73 public void setState(State state) {
74 this.state = state;
75 }
76
77 /** @return An ordered list of comments associated with this note */
78 public List<NoteComment> getComments() {
79 return comments;
80 }
81
82 public void addComment(NoteComment comment) {
83 comments.add(comment);
84 }
85
86 /**
87 * Returns the comment that was submitted by the user when creating the note
88 * @return First comment object
89 */
90 public NoteComment getFirstComment() {
91 return comments.isEmpty() ? null : comments.get(0);
92 }
93
94 /**
95 * Copies values from a new note into an existing one. Used after a note
96 * has been updated on the server and the local copy needs refreshing.
97 * @param note New values to copy
98 */
99 public void updateWith(Note note) {
100 this.comments = note.comments;
101 this.createdAt = note.createdAt;
102 this.id = note.id;
103 this.state = note.state;
104 this.latLon = note.latLon;
105 }
106
107 @Override
108 public int hashCode() {
109 return Objects.hash(id);
110 }
111
112 @Override
113 public boolean equals(Object obj) {
114 if (this == obj) return true;
115 if (obj == null || getClass() != obj.getClass()) return false;
116 Note note = (Note) obj;
117 return id == note.id;
118 }
119
120 @Override
121 public String toString() {
122 return tr("Note") + " " + id + ": " + getFirstComment();
123 }
124}
Note: See TracBrowser for help on using the repository browser.