Search in sources :

Example 1 with IClientNotificationAddress

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ClientNotificationMessage(org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage) IClientNotificationAddress(org.eclipse.scout.rt.shared.clientnotification.IClientNotificationAddress) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 ClientNotificationMessage (org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage)1 IClientNotificationAddress (org.eclipse.scout.rt.shared.clientnotification.IClientNotificationAddress)1