protected void dequeueNotificationInQueueWithCoalesceMask(NSNotification notification, NSMutableArray<NSNotificationQueueEntry> queue, Set<NSNotificationCoalescing> coalesceMask) {
    int count = queue.count();

    while(--count >= 0) {
      NSNotification check = queue.objectAtIndex(count).notification();
      boolean remove = false;

      if (coalesceMask == null || coalesceMask.isEmpty()) {
        if (notification.equals(check)) {
          remove = true;
        }
      } else { 
        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);
      }
    }
  }