Changeset 11821 in josm
- Timestamp:
- 2017-04-01T23:27:46+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/notes/Note.java
r10300 r11821 5 5 6 6 import java.util.ArrayList; 7 import java.util.Comparator; 7 8 import java.util.Date; 8 9 import java.util.List; … … 25 26 } 26 27 28 /** 29 * Sorts notes in the following order: 30 * 1) Open notes 31 * 2) Closed notes 32 * 3) New notes 33 * Within each subgroup it sorts by ID 34 */ 35 public static final Comparator<Note> DEFAULT_COMPARATOR = (n1, n2) -> { 36 if (n1.getId() < 0 && n2.getId() > 0) { 37 return 1; 38 } 39 if (n1.getId() > 0 && n2.getId() < 0) { 40 return -1; 41 } 42 if (n1.getState() == State.CLOSED && n2.getState() == State.OPEN) { 43 return 1; 44 } 45 if (n1.getState() == State.OPEN && n2.getState() == State.CLOSED) { 46 return -1; 47 } 48 return Long.compare(Math.abs(n1.getId()), Math.abs(n2.getId())); 49 }; 50 51 /** Sorts notes strictly by creation date */ 52 public static final Comparator<Note> DATE_COMPARATOR = (n1, n2) -> n1.createdAt.compareTo(n2.createdAt); 53 54 /** Sorts notes by user, then creation date */ 55 public static final Comparator<Note> USER_COMPARATOR = (n1, n2) -> { 56 String n1User = n1.getFirstComment().getUser().getName(); 57 String n2User = n2.getFirstComment().getUser().getName(); 58 return n1User.equals(n2User) ? DATE_COMPARATOR.compare(n1, n2) : n1User.compareTo(n2User); 59 }; 60 61 /** Sorts notes by the last modified date */ 62 public static final Comparator<Note> LAST_ACTION_COMPARATOR = 63 (n1, n2) -> NoteComment.DATE_COMPARATOR.compare(n1.getLastComment(), n2.getLastComment()); 64 27 65 private long id; 28 66 private LatLon latLon; … … 60 98 /** @return Date that this note was submitted */ 61 99 public Date getCreatedAt() { 62 return c reatedAt;100 return cloneDate(createdAt); 63 101 } 64 102 … … 68 106 */ 69 107 public void setCreatedAt(Date createdAt) { 70 this.createdAt = c reatedAt;108 this.createdAt = cloneDate(createdAt); 71 109 } 72 110 73 111 /** @return Date that this note was closed. Null if it is still open. */ 74 112 public Date getClosedAt() { 75 return clo sedAt;113 return cloneDate(closedAt); 76 114 } 77 115 … … 81 119 */ 82 120 public void setClosedAt(Date closedAt) { 83 this.closedAt = clo sedAt;121 this.closedAt = cloneDate(closedAt); 84 122 } 85 123 … … 103 141 104 142 /** 143 * Returns the last comment, or {@code null}. 144 * @return the last comment, or {@code null} 145 * @since 11821 146 */ 147 public NoteComment getLastComment() { 148 return comments.isEmpty() ? null : comments.get(comments.size()-1); 149 } 150 151 /** 105 152 * Adds a comment. 106 153 * @param comment note comment … … 125 172 public void updateWith(Note note) { 126 173 this.comments = note.comments; 127 this.createdAt = note.createdAt;174 this.createdAt = cloneDate(note.createdAt); 128 175 this.id = note.id; 129 176 this.state = note.state; … … 150 197 return tr("Note") + ' ' + id + ": " + getFirstComment(); 151 198 } 199 200 /** 201 * Null-safe date cloning method. 202 * @param d date to clone, or null 203 * @return cloned date, or null 204 */ 205 static Date cloneDate(Date d) { 206 return d != null ? (Date) d.clone() : null; 207 } 152 208 } -
trunk/src/org/openstreetmap/josm/data/notes/NoteComment.java
r10134 r11821 2 2 package org.openstreetmap.josm.data.notes; 3 3 4 import java.util.Comparator; 4 5 import java.util.Date; 5 6 … … 38 39 } 39 40 41 /** Sorts note comments strictly by creation date */ 42 public static final Comparator<NoteComment> DATE_COMPARATOR = (n1, n2) -> n1.commentTimestamp.compareTo(n2.commentTimestamp); 43 40 44 /** 41 45 * @param createDate The time at which this comment was added … … 48 52 this.text = commentText; 49 53 this.user = user; 50 this.commentTimestamp = createDate;54 this.commentTimestamp = Note.cloneDate(createDate); 51 55 this.action = action; 52 56 this.isNew = isNew; … … 65 69 /** @return The time at which this comment was created */ 66 70 public Date getCommentTimestamp() { 67 return commentTimestamp;71 return Note.cloneDate(commentTimestamp); 68 72 } 69 73 -
trunk/src/org/openstreetmap/josm/data/osm/NoteData.java
r10717 r11821 26 26 private final Storage<Note> noteList; 27 27 private Note selectedNote; 28 private Comparator<Note> comparator = DEFAULT_COMPARATOR; 29 30 /** 31 * Sorts notes in the following order: 32 * 1) Open notes 33 * 2) Closed notes 34 * 3) New notes 35 * Within each subgroup it sorts by ID 36 */ 37 public static final Comparator<Note> DEFAULT_COMPARATOR = (n1, n2) -> { 38 if (n1.getId() < 0 && n2.getId() > 0) { 39 return 1; 40 } 41 if (n1.getId() > 0 && n2.getId() < 0) { 42 return -1; 43 } 44 if (n1.getState() == State.CLOSED && n2.getState() == State.OPEN) { 45 return 1; 46 } 47 if (n1.getState() == State.OPEN && n2.getState() == State.CLOSED) { 48 return -1; 49 } 50 return Long.compare(Math.abs(n1.getId()), Math.abs(n2.getId())); 51 }; 52 53 /** Sorts notes strictly by creation date */ 54 public static final Comparator<Note> DATE_COMPARATOR = (n1, n2) -> n1.getCreatedAt().compareTo(n2.getCreatedAt()); 55 56 /** Sorts notes by user, then creation date */ 57 public static final Comparator<Note> USER_COMPARATOR = (n1, n2) -> { 58 String n1User = n1.getFirstComment().getUser().getName(); 59 String n2User = n2.getFirstComment().getUser().getName(); 60 if (n1User.equals(n2User)) { 61 return n1.getCreatedAt().compareTo(n2.getCreatedAt()); 62 } 63 return n1.getFirstComment().getUser().getName().compareTo(n2.getFirstComment().getUser().getName()); 64 }; 65 66 /** Sorts notes by the last modified date */ 67 public static final Comparator<Note> LAST_ACTION_COMPARATOR = (n1, n2) -> { 68 Date n1Date = n1.getComments().get(n1.getComments().size()-1).getCommentTimestamp(); 69 Date n2Date = n2.getComments().get(n2.getComments().size()-1).getCommentTimestamp(); 70 return n1Date.compareTo(n2Date); 71 }; 28 private Comparator<Note> comparator = Note.DEFAULT_COMPARATOR; 72 29 73 30 /** -
trunk/src/org/openstreetmap/josm/gui/NoteSortDialog.java
r9078 r11821 15 15 import org.openstreetmap.josm.Main; 16 16 import org.openstreetmap.josm.data.notes.Note; 17 import org.openstreetmap.josm.data.osm.NoteData;18 17 19 18 /** … … 43 42 public void showSortDialog(Comparator<Note> currentSortMode) { 44 43 JLabel label = new JLabel(tr("Select note sorting method")); 45 if (currentSortMode == Note Data.DEFAULT_COMPARATOR) {44 if (currentSortMode == Note.DEFAULT_COMPARATOR) { 46 45 defaultSort.setSelected(true); 47 } else if (currentSortMode == Note Data.DATE_COMPARATOR) {46 } else if (currentSortMode == Note.DATE_COMPARATOR) { 48 47 dateSort.setSelected(true); 49 } else if (currentSortMode == Note Data.USER_COMPARATOR) {48 } else if (currentSortMode == Note.USER_COMPARATOR) { 50 49 userSort.setSelected(true); 51 } else if (currentSortMode == Note Data.LAST_ACTION_COMPARATOR) {50 } else if (currentSortMode == Note.LAST_ACTION_COMPARATOR) { 52 51 lastActionSort.setSelected(true); 53 52 } else { … … 77 76 public Comparator<Note> getSelectedComparator() { 78 77 if (dateSort.isSelected()) { 79 return Note Data.DATE_COMPARATOR;78 return Note.DATE_COMPARATOR; 80 79 } else if (userSort.isSelected()) { 81 return Note Data.USER_COMPARATOR;80 return Note.USER_COMPARATOR; 82 81 } else if (lastActionSort.isSelected()) { 83 return Note Data.LAST_ACTION_COMPARATOR;82 return Note.LAST_ACTION_COMPARATOR; 84 83 } else { 85 return Note Data.DEFAULT_COMPARATOR;84 return Note.DEFAULT_COMPARATOR; 86 85 } 87 86 }
Note:
See TracChangeset
for help on using the changeset viewer.