Changeset 17837 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/notes/Note.java
r17712 r17837 53 53 54 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 }; 55 public static final Comparator<Note> USER_COMPARATOR = 56 Comparator.comparing(Note::getUserName, Comparator.nullsLast(Comparator.naturalOrder())).thenComparing(DATE_COMPARATOR); 60 57 61 58 /** 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()); 59 public static final Comparator<Note> LAST_ACTION_COMPARATOR = Comparator.comparing(Note::getLastComment, NoteComment.DATE_COMPARATOR); 64 60 65 61 private long id; … … 181 177 public NoteComment getFirstComment() { 182 178 return comments.isEmpty() ? null : comments.get(0); 179 } 180 181 private String getUserName() { 182 return getFirstComment() == null ? null : getFirstComment().getUser().getName(); 183 183 } 184 184 -
trunk/src/org/openstreetmap/josm/data/notes/NoteComment.java
r17712 r17837 40 40 41 41 /** Sorts note comments strictly by creation date */ 42 public static final Comparator<NoteComment> DATE_COMPARATOR = Comparator. comparing(n -> n.commentTimestamp);42 public static final Comparator<NoteComment> DATE_COMPARATOR = Comparator.nullsLast(Comparator.comparing(n -> n.commentTimestamp)); 43 43 44 44 /** -
trunk/test/unit/org/openstreetmap/josm/data/notes/NoteTest.java
r17712 r17837 6 6 7 7 import java.time.Instant; 8 import java.util.List; 8 9 9 10 import org.junit.jupiter.api.extension.RegisterExtension; … … 11 12 import org.openstreetmap.josm.TestUtils; 12 13 import org.openstreetmap.josm.data.coor.LatLon; 14 import org.openstreetmap.josm.io.NoteReader; 13 15 import org.openstreetmap.josm.testutils.JOSMTestRules; 14 16 … … 69 71 .verify(); 70 72 } 73 74 @Test 75 void testSorting() throws Exception { 76 List<Note> list = new NoteReader("" + 77 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 78 "<osm version=\"0.6\" generator=\"OpenStreetMap server\">\n" + 79 "<note lon=\"68.86415\" lat=\"36.7232991\">\n"+ 80 " <id>4</id>\n"+ 81 " <url>http://api.openstreetmap.org/api/0.6/notes/4</url>\n"+ 82 " <reopen_url>http://api.openstreetmap.org/api/0.6/notes/4/reopen</reopen_url>\n"+ 83 " <date_created>2013-04-24 08:07:02 UTC</date_created>\n"+ 84 " <status>closed</status>\n"+ 85 " <date_closed>2013-04-24 08:08:51 UTC</date_closed>\n"+ 86 " <comments>\n"+ 87 " <comment>\n"+ 88 " <date>2013-04-24 08:07:02 UTC</date>\n"+ 89 " <uid>1626</uid>\n"+ 90 " <user>FredB</user>\n"+ 91 " <user_url>http://www.openstreetmap.org/user/FredB</user_url>\n"+ 92 " <action>opened</action>\n"+ 93 " <text>test</text>\n"+ 94 " <html><p>test</p></html>\n"+ 95 " </comment>\n"+ 96 " <comment>\n"+ 97 " <date>2013-04-24 08:08:51 UTC</date>\n"+ 98 " <uid>1626</uid>\n"+ 99 " <user>FredB</user>\n"+ 100 " <user_url>http://www.openstreetmap.org/user/FredB</user_url>\n"+ 101 " <action>closed</action>\n"+ 102 " <text></text>\n"+ 103 " <html><p></p></html>\n"+ 104 " </comment>\n"+ 105 " </comments>\n"+ 106 "</note>\n"+ 107 "<note lon=\"23.2663071\" lat=\"50.7173607\">\n" + 108 " <id>1396945</id>\n" + 109 " <url>https://www.openstreetmap.org/api/0.6/notes/1396945</url>\n" + 110 " <comment_url>https://www.openstreetmap.org/api/0.6/notes/1396945/comment</comment_url>\n" + 111 " <close_url>https://www.openstreetmap.org/api/0.6/notes/1396945/close</close_url>\n" + 112 " <date_created>2018-05-17 15:41:06 UTC</date_created>\n" + 113 " <status>open</status>\n" + 114 " <comments>\n" + 115 " </comments>\n" + 116 "</note>\n" + 117 "</osm>\n").parse(); 118 // Non-regression test for ticket #20824 119 list.sort(Note.DATE_COMPARATOR); 120 list.sort(Note.DEFAULT_COMPARATOR); 121 list.sort(Note.LAST_ACTION_COMPARATOR); 122 list.sort(Note.USER_COMPARATOR); 123 } 71 124 }
Note:
See TracChangeset
for help on using the changeset viewer.