Submit thread list items to ListAdapter

This commit is contained in:
Torsten Grote
2021-01-07 08:52:51 -03:00
parent 6611d7c02e
commit d393b79ced
19 changed files with 276 additions and 311 deletions

View File

@@ -30,9 +30,14 @@ public class MessageTreeImpl<T extends MessageTree.MessageNode>
private final List<List<T>> unsortedLists = new ArrayList<>();
@SuppressWarnings("UseCompareMethod")
private Comparator<T> comparator = (o1, o2) ->
private final Comparator<T> comparator = (o1, o2) ->
Long.valueOf(o1.getTimestamp()).compareTo(o2.getTimestamp());
public MessageTreeImpl(Collection<T> collection) {
super();
add(collection);
}
@Override
public synchronized void clear() {
roots.clear();
@@ -79,6 +84,7 @@ public class MessageTreeImpl<T extends MessageTree.MessageNode>
@GuardedBy("this")
private void sortUnsorted() {
for (List<T> list : unsortedLists) {
//noinspection Java8ListSort
Collections.sort(list, comparator);
}
unsortedLists.clear();
@@ -95,17 +101,7 @@ public class MessageTreeImpl<T extends MessageTree.MessageNode>
}
@Override
public synchronized void setComparator(Comparator<T> comparator) {
this.comparator = comparator;
// Sort all lists with the new comparator
Collections.sort(roots, comparator);
for (Map.Entry<MessageId, List<T>> entry : nodeMap.entrySet()) {
Collections.sort(entry.getValue(), comparator);
}
}
@Override
public synchronized Collection<T> depthFirstOrder() {
public synchronized List<T> depthFirstOrder() {
List<T> orderedList = new ArrayList<>();
for (T root : roots) {
traverse(orderedList, root, 0);