Changeset 8224 in josm for trunk/src/org/openstreetmap/josm/data/osm/NoteData.java
- Timestamp:
- 2015-04-18T22:37:12+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/NoteData.java
r7937 r8224 3 3 4 4 import java.util.ArrayList; 5 import java.util.Collection; 5 6 import java.util.Collections; 6 7 import java.util.Comparator; 7 8 import java.util.Date; 8 import java.util.List;9 9 import java.util.Map; 10 10 … … 15 15 import org.openstreetmap.josm.data.notes.NoteComment; 16 16 import org.openstreetmap.josm.gui.JosmUserIdentityManager; 17 import org.openstreetmap.josm.tools.Predicate; 18 import org.openstreetmap.josm.tools.Utils; 17 19 18 20 /** … … 23 25 private long newNoteId = -1; 24 26 25 private final List<Note> noteList;27 private final Storage<Note> noteList; 26 28 private Note selectedNote = null; 27 29 private Comparator<Note> comparator = DEFAULT_COMPARATOR; … … 85 87 86 88 /** 87 * Construct a new note container with an empty note list88 */89 public NoteData() {90 noteList = new ArrayList<>();91 }92 93 /**94 89 * Construct a new note container with a given list of notes 95 90 * @param notes The list of notes to populate the container with 96 91 */ 97 public NoteData(List<Note> notes) { 98 noteList = notes; 99 Collections.sort(notes, comparator); 92 public NoteData(Collection<Note> notes) { 93 noteList = new Storage<>(); 100 94 for (Note note : notes) { 95 noteList.add(note); 101 96 if (note.getId() <= newNoteId) { 102 97 newNoteId = note.getId() - 1; … … 107 102 /** 108 103 * Returns the notes stored in this layer 109 * @return List of Note objects 110 */ 111 public List<Note> getNotes() { 112 return noteList; 104 * @return collection of notes 105 */ 106 public Collection<Note> getNotes() { 107 return Collections.unmodifiableCollection(noteList); 108 } 109 110 /** 111 * Returns the notes stored in this layer sorted according to {@link #comparator} 112 * @return sorted collection of notes 113 */ 114 public Collection<Note> getSortedNotes() { 115 final ArrayList<Note> list = new ArrayList<>(noteList); 116 Collections.sort(list, comparator); 117 return list; 113 118 } 114 119 … … 155 160 * @param newNotes A list of notes to add 156 161 */ 157 public synchronized void addNotes( List<Note> newNotes) {162 public synchronized void addNotes(Collection<Note> newNotes) { 158 163 for (Note newNote : newNotes) { 159 164 if (!noteList.contains(newNote)) { 160 165 noteList.add(newNote); 166 } else { 167 final Note existingNote = noteList.get(newNote); 168 final boolean isDirty = Utils.exists(existingNote.getComments(), new Predicate<NoteComment>() { 169 @Override 170 public boolean evaluate(NoteComment object) { 171 return object.getIsNew(); 172 } 173 }); 174 if (!isDirty) { 175 noteList.put(newNote); 176 } else { 177 // TODO merge comments? 178 Main.info("Keeping existing note id={0} with uncommitted changes", String.valueOf(newNote.getId())); 179 } 161 180 } 162 181 if (newNote.getId() <= newNoteId) { … … 165 184 } 166 185 dataUpdated(); 167 if (Main.isDebugEnabled()) {168 Main.debug("notes in current set: " + noteList.size());169 }170 186 } 171 187 … … 256 272 257 273 private void dataUpdated() { 258 Collections.sort(noteList, comparator); 259 Main.map.noteDialog.setNoteList(noteList); 274 Main.map.noteDialog.setNotes(getSortedNotes()); 260 275 Main.map.mapView.repaint(); 261 276 }
Note:
See TracChangeset
for help on using the changeset viewer.