protected void coalesceNotificationInQueueWithCoalesceMask(NSNotification notification, NSMutableArray<NSNotificationQueueEntry> queue, Set<NSNotificationCoalescing> coalesceMask) {
    if (coalesceMask != null && !coalesceMask.isEmpty()) {
      int count = queue.count();
      
      while(--count >= 0) {
        NSNotification check = queue.objectAtIndex(count).notification();
        boolean remove = false;
        
        if (coalesceMask.contains(NSNotificationCoalescing.OnName)) {
          if (check.name().equals(notification.name())) {
            remove = true;
          }
        }
        
        if (coalesceMask.contains(NSNotificationCoalescing.OnSender)) {
          if (check.object() == notification.object()) {
            remove = true;
          }
        }
        
        if (remove) {
          queue.removeObjectAtIndex(count);
        }
      }
    }
  }