use of org.eclipse.scout.rt.shared.clientnotification.IClientNotificationAddress in project scout.rt by eclipse.
the class ClientNotificationCoalescer method coalesce.
public List<ClientNotificationMessage> coalesce(List<ClientNotificationMessage> inNotifications) {
LinkedHashSet<ClientNotificationMessage> notificationsNoDuplicates = new LinkedHashSet<ClientNotificationMessage>(inNotifications);
// sort by distribute & address property
Map<Boolean, Map<IClientNotificationAddress, List<ClientNotificationMessage>>> messagesPerDistributeAndAddress = new HashMap<>();
messagesPerDistributeAndAddress.put(true, new HashMap<IClientNotificationAddress, List<ClientNotificationMessage>>());
messagesPerDistributeAndAddress.put(false, new HashMap<IClientNotificationAddress, List<ClientNotificationMessage>>());
for (ClientNotificationMessage message : notificationsNoDuplicates) {
Map<IClientNotificationAddress, List<ClientNotificationMessage>> messagesPerAddress = messagesPerDistributeAndAddress.get(message.isDistributeOverCluster());
List<ClientNotificationMessage> messages = messagesPerAddress.get(message.getAddress());
if (messages == null) {
messages = new ArrayList<ClientNotificationMessage>();
messagesPerAddress.put(message.getAddress(), messages);
}
messages.add(message);
}
List<ClientNotificationMessage> result = new ArrayList<>();
for (Entry<Boolean, Map<IClientNotificationAddress, List<ClientNotificationMessage>>> distributeEntry : messagesPerDistributeAndAddress.entrySet()) {
boolean distribute = distributeEntry.getKey();
for (Entry<IClientNotificationAddress, List<ClientNotificationMessage>> e : distributeEntry.getValue().entrySet()) {
result.addAll(coalesce(distribute, e.getKey(), e.getValue()));
}
}
return result;
}
Aggregations