/** * Synchronizes the {@code OrganizationalEntity} objects contained in the {@code CircularQueue} and the list of * potential owners * @param queueName The name of the queue to be synchronized. * @param potentialOwners This list of potential owners of the task * @return The CircularQueue that contains all potential owners */ private synchronized CircularQueue<OrganizationalEntity> synchronizedQueue(String queueName, List<OrganizationalEntity> potentialOwners) { CircularQueue<OrganizationalEntity> existingQueue = (queueName == null || queueName.trim().length() == 0) ? null : circularQueueMap.get(queueName); // If the queue does not exist then a new CircularQueue should be created final CircularQueue<OrganizationalEntity> workingQueue = existingQueue != null ? existingQueue : new CircularQueue(); potentialOwners.forEach(po -> { if (!queueContainsUser(workingQueue, po)) { workingQueue.add(po); } }); workingQueue.removeIf(oe -> !potentialOwners.contains(oe)); circularQueueMap.put(queueName, workingQueue); return workingQueue; }