Here is my code:
这是我的代码:
/* Returns a Map that stores a contact name as a key and a list of messages from that contact
as a value. If a message has no associated contact, it should not appear in the Map. Must
not change messages field. Must call filter with an anonymous inner class in the method body. */
public Map<String, List<Message>> sortMessagesByContact() {
Map<String, List<Message>> map = new HashMap<>();
List<Message> filtered = new ArrayList<>();
Predicate<Message> p = new Predicate<>() {
@Override
public boolean test(Message t) {
return t.getContact().isPresent();
}
}; for (Message mg : messages) {
if (p.test(mg)) {
map.put(mg.getContact().get(), messages);
}
}
return map;
}
/* Returns a Map t