1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.notes;
|
---|
3 |
|
---|
4 | import java.util.ArrayList;
|
---|
5 | import java.util.Date;
|
---|
6 | import java.util.List;
|
---|
7 | import java.util.Objects;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * A map note. It always has at least one comment since a comment is required
|
---|
13 | * to create a note on osm.org
|
---|
14 | */
|
---|
15 | public class Note {
|
---|
16 |
|
---|
17 | public enum State { open, closed }
|
---|
18 |
|
---|
19 | private long id;
|
---|
20 | private LatLon latLon;
|
---|
21 | private Date createdAt;
|
---|
22 | private Date closedAt;
|
---|
23 | private State state;
|
---|
24 | private List<NoteComment> comments = new ArrayList<>();
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Create a note with a given location
|
---|
28 | * @param latLon Geographic location of this note
|
---|
29 | */
|
---|
30 | public Note(LatLon latLon) {
|
---|
31 | this.latLon = latLon;
|
---|
32 | }
|
---|
33 |
|
---|
34 | /** @return The unique OSM ID of this note */
|
---|
35 | public long getId() {
|
---|
36 | return id;
|
---|
37 | }
|
---|
38 |
|
---|
39 | public void setId(long id) {
|
---|
40 | this.id = id;
|
---|
41 | }
|
---|
42 |
|
---|
43 | /** @return The geographic location of the note */
|
---|
44 | public LatLon getLatLon() {
|
---|
45 | return latLon;
|
---|
46 | }
|
---|
47 |
|
---|
48 | /** @return Date that this note was submitted */
|
---|
49 | public Date getCreatedAt() {
|
---|
50 | return createdAt;
|
---|
51 | }
|
---|
52 |
|
---|
53 | public void setCreatedAt(Date createdAt) {
|
---|
54 | this.createdAt = createdAt;
|
---|
55 | }
|
---|
56 |
|
---|
57 | /** @return Date that this note was closed. Null if it is still open. */
|
---|
58 | public Date getClosedAt() {
|
---|
59 | return closedAt;
|
---|
60 | }
|
---|
61 |
|
---|
62 | public void setClosedAt(Date closedAt) {
|
---|
63 | this.closedAt = closedAt;
|
---|
64 | }
|
---|
65 |
|
---|
66 | /** @return The open or closed state of this note */
|
---|
67 | public State getState() {
|
---|
68 | return state;
|
---|
69 | }
|
---|
70 |
|
---|
71 | public void setState(State state) {
|
---|
72 | this.state = state;
|
---|
73 | }
|
---|
74 |
|
---|
75 | /** @return An ordered list of comments associated with this note */
|
---|
76 | public List<NoteComment> getComments() {
|
---|
77 | return comments;
|
---|
78 | }
|
---|
79 |
|
---|
80 | public void addComment(NoteComment comment) {
|
---|
81 | this.comments.add(comment);
|
---|
82 | }
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * Returns the comment that was submitted by the user when creating the note
|
---|
86 | * @return First comment object
|
---|
87 | */
|
---|
88 | public NoteComment getFirstComment() {
|
---|
89 | return this.comments.get(0);
|
---|
90 | }
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Copies values from a new note into an existing one. Used after a note
|
---|
94 | * has been updated on the server and the local copy needs refreshing.
|
---|
95 | * @param note New values to copy
|
---|
96 | */
|
---|
97 | public void updateWith(Note note) {
|
---|
98 | this.comments = note.comments;
|
---|
99 | this.createdAt = note.createdAt;
|
---|
100 | this.id = note.id;
|
---|
101 | this.state = note.state;
|
---|
102 | this.latLon = note.latLon;
|
---|
103 | }
|
---|
104 |
|
---|
105 | @Override
|
---|
106 | public int hashCode() {
|
---|
107 | return Objects.hash(id);
|
---|
108 | }
|
---|
109 |
|
---|
110 | @Override
|
---|
111 | public boolean equals(Object obj) {
|
---|
112 | if (this == obj) return true;
|
---|
113 | if (obj == null || getClass() != obj.getClass()) return false;
|
---|
114 | Note note = (Note) obj;
|
---|
115 | return id == note.id;
|
---|
116 | }
|
---|
117 | }
|
---|