mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-29 05:07:40 +00:00
Use Comparator.reverseOrder() and Map.computeIfAbsent() in SMSHelper.
This commit is contained in:
parent
ca7f691b93
commit
c4dcecb8d8
@ -45,6 +45,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
@ -191,12 +192,11 @@ public class SMSHelper {
|
||||
// Suppose we were requested to return N values and suppose a user sends only one MMS per
|
||||
// week and N SMS per day. We have requested the same N for each, so if we just return everything
|
||||
// we would return some very old MMS messages which would be very confusing.
|
||||
SortedMap<Long, Collection<Message>> sortedMessages = new TreeMap<>((lhs, rhs) -> Long.compare(rhs, lhs));
|
||||
SortedMap<Long, Collection<Message>> sortedMessages = new TreeMap<>(Comparator.reverseOrder());
|
||||
for (Message message : allMessages) {
|
||||
Collection<Message> existingMessages = sortedMessages.getOrDefault(message.date, new ArrayList<>());
|
||||
assert existingMessages != null;
|
||||
Collection<Message> existingMessages = sortedMessages.computeIfAbsent(message.date,
|
||||
key -> new ArrayList<>());
|
||||
existingMessages.add(message);
|
||||
sortedMessages.put(message.date, existingMessages);
|
||||
}
|
||||
|
||||
List<Message> toReturn = new ArrayList<>(allMessages.size());
|
||||
|
Loading…
x
Reference in New Issue
Block a user