Example usage for java.util Set removeAll

List of usage examples for java.util Set removeAll

Introduction

In this page you can find the example usage for java.util Set removeAll.

Prototype

boolean removeAll(Collection<?> c);

Source Link

Document

Removes from this set all of its elements that are contained in the specified collection (optional operation).

Usage

From source file:disAMS.AMRMClient.Impl.AMRMClientImpl.java

@Override
public synchronized void addContainerRequest(T req) {
    Preconditions.checkArgument(req != null, "Resource request can not be null.");
    Set<String> dedupedRacks = new HashSet<String>();
    if (req.getRacks() != null) {
        dedupedRacks.addAll(req.getRacks());
        if (req.getRacks().size() != dedupedRacks.size()) {
            Joiner joiner = Joiner.on(',');
            LOG.warn("ContainerRequest has duplicate racks: " + joiner.join(req.getRacks()));
        }/*from w w w  . ja va2  s.c  om*/
    }
    Set<String> inferredRacks = resolveRacks(req.getNodes());
    inferredRacks.removeAll(dedupedRacks);

    // check that specific and non-specific requests cannot be mixed within a
    // priority
    checkLocalityRelaxationConflict(req.getPriority(), ANY_LIST, req.getRelaxLocality());
    // check that specific rack cannot be mixed with specific node within a 
    // priority. If node and its rack are both specified then they must be 
    // in the same request.
    // For explicitly requested racks, we set locality relaxation to true
    checkLocalityRelaxationConflict(req.getPriority(), dedupedRacks, true);
    checkLocalityRelaxationConflict(req.getPriority(), inferredRacks, req.getRelaxLocality());
    // check if the node label expression specified is valid
    checkNodeLabelExpression(req);

    if (req.getNodes() != null) {
        HashSet<String> dedupedNodes = new HashSet<String>(req.getNodes());
        if (dedupedNodes.size() != req.getNodes().size()) {
            Joiner joiner = Joiner.on(',');
            LOG.warn("ContainerRequest has duplicate nodes: " + joiner.join(req.getNodes()));
        }
        for (String node : dedupedNodes) {
            addResourceRequest(req.getPriority(), node, req.getCapability(), req, true,
                    req.getNodeLabelExpression());
        }
    }

    for (String rack : dedupedRacks) {
        addResourceRequest(req.getPriority(), rack, req.getCapability(), req, true,
                req.getNodeLabelExpression());
    }

    // Ensure node requests are accompanied by requests for
    // corresponding rack
    for (String rack : inferredRacks) {
        addResourceRequest(req.getPriority(), rack, req.getCapability(), req, req.getRelaxLocality(),
                req.getNodeLabelExpression());
    }

    // Off-switch
    addResourceRequest(req.getPriority(), ResourceRequest.ANY, req.getCapability(), req, req.getRelaxLocality(),
            req.getNodeLabelExpression());
}

From source file:chat.viska.xmpp.HandshakerPipe.java

private boolean checkIfAllMandatoryFeaturesNegotiated() {
    final Set<StreamFeature> notNegotiated = new HashSet<>(FEATURES_ORDER);
    notNegotiated.removeAll(negotiatedFeatures);
    return !Observable.fromIterable(notNegotiated).any(StreamFeature::isMandatory).blockingGet();
}

From source file:com.capitalone.dashboard.client.story.StoryDataClientImpl.java

private void loadEpicData(Collection<String> epicKeys) {
    // No need to lookup items that are already cached
    Set<String> epicsToLookup = new HashSet<>();
    epicsToLookup.addAll(epicKeys);//from   w  w w  . j a  va2  s  .  co  m
    epicsToLookup.removeAll(epicCache.keySet());

    List<String> epicsToLookupL = new ArrayList<>(epicsToLookup);

    if (!epicsToLookupL.isEmpty()) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Obtaining epic information for epics: " + epicsToLookupL);
        }

        // Do this at most 50 at a time as jira doesn't seem to always work when there are a lot of items in an in clause
        int maxEpicsToLookup = Math.min(featureSettings.getPageSize(), 50);

        for (int i = 0; i < epicsToLookupL.size(); i += maxEpicsToLookup) {
            int endIdx = Math.min(i + maxEpicsToLookup, epicsToLookupL.size());

            List<String> epicKeysSub = epicsToLookupL.subList(i, endIdx);

            List<Issue> epics = jiraClient.getEpics(epicKeysSub);

            for (Issue epic : epics) {
                String epicKey = epic.getKey();

                epicCache.put(epicKey, epic);
            }
        }
    }
}

From source file:de.fuberlin.wiwiss.r2r.Mapping.java

public Set<String> computeQueryVariableDependencies() {
    Set<String> varDependencies = new HashSet<String>();
    varDependencies.addAll(variableDependenciesOfTargetPatterns);
    varDependencies.addAll(variableDependenciesOfTransformations);
    varDependencies.removeAll(transformationGeneratedVariables);
    return varDependencies;
}

From source file:com.bdaum.zoom.gps.internal.operations.GeotagOperation.java

@Override
public IStatus undo(IProgressMonitor aMonitor, IAdaptable info) throws ExecutionException {
    Backup[] backups = getBackupsFromTrash();
    int size = backups.length;
    initUndo(aMonitor, size);//from www.j  ava 2s. c  o m
    if (postPonedAssets != null) {
        Meta meta = dbManager.getMeta(false);
        if (meta != null) {
            Set<String> postponedNaming = meta.getPostponedNaming();
            if (postponedNaming != null)
                postponedNaming.removeAll(postPonedAssets);
        }
    }
    List<Object> toBeStored = new ArrayList<Object>(size);
    List<Object> toBeDeleted = new ArrayList<Object>(size);
    for (Backup backup : backups) {
        try {
            backup.restore(toBeStored, toBeDeleted);
        } catch (Exception e) {
            addError(Messages.getString("GeotagOperation.error_assigning_former_value"), //$NON-NLS-1$
                    e);
        }
        dbManager.safeTransaction(toBeDeleted, toBeStored);
        toBeDeleted.clear();
        toBeStored.clear();
    }
    fireAssetsModified(null, null);
    return close(info);
}

From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushSubplanIntoGroupByRule.java

@Override
public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
        throws AlgebricksException {
    ILogicalOperator parentOperator = opRef.getValue();
    if (context.checkIfInDontApplySet(this, parentOperator)) {
        return false;
    }/*from w w w.  j  a  v  a2  s .c om*/
    context.addToDontApplySet(this, parentOperator);
    VariableUtilities.getUsedVariables(parentOperator, usedVarsSoFar);
    if (parentOperator.getInputs().size() <= 0) {
        return false;
    }
    boolean changed = false;
    GroupByOperator gby = null;
    for (Mutable<ILogicalOperator> ref : parentOperator.getInputs()) {
        AbstractLogicalOperator op = (AbstractLogicalOperator) ref.getValue();
        /** Only processes subplan operator. */
        List<SubplanOperator> subplans = new ArrayList<SubplanOperator>();
        if (op.getOperatorTag() == LogicalOperatorTag.SUBPLAN) {
            while (op.getOperatorTag() == LogicalOperatorTag.SUBPLAN) {
                SubplanOperator currentSubplan = (SubplanOperator) op;
                subplans.add(currentSubplan);
                op = (AbstractLogicalOperator) op.getInputs().get(0).getValue();
            }
            /** Only processes the case a group-by operator is the input of the subplan operators. */
            if (op.getOperatorTag() == LogicalOperatorTag.GROUP) {
                gby = (GroupByOperator) op;
                List<ILogicalPlan> newGbyNestedPlans = new ArrayList<ILogicalPlan>();
                for (SubplanOperator subplan : subplans) {
                    List<ILogicalPlan> subplanNestedPlans = subplan.getNestedPlans();
                    List<ILogicalPlan> gbyNestedPlans = gby.getNestedPlans();
                    List<ILogicalPlan> subplanNestedPlansToRemove = new ArrayList<ILogicalPlan>();
                    for (ILogicalPlan subplanNestedPlan : subplanNestedPlans) {
                        List<Mutable<ILogicalOperator>> rootOpRefs = subplanNestedPlan.getRoots();
                        List<Mutable<ILogicalOperator>> rootOpRefsToRemove = new ArrayList<Mutable<ILogicalOperator>>();
                        for (Mutable<ILogicalOperator> rootOpRef : rootOpRefs) {
                            /** Gets free variables in the root operator of a nested plan and its descent. */
                            Set<LogicalVariable> freeVars = new ListSet<LogicalVariable>();
                            VariableUtilities.getUsedVariablesInDescendantsAndSelf(rootOpRef.getValue(),
                                    freeVars);
                            Set<LogicalVariable> producedVars = new ListSet<LogicalVariable>();
                            VariableUtilities.getProducedVariablesInDescendantsAndSelf(rootOpRef.getValue(),
                                    producedVars);
                            freeVars.removeAll(producedVars);
                            /** * Checks whether the above freeVars are all contained in live variables * of one nested plan inside the group-by operator. * If yes, then the subplan can be pushed into the nested plan of the group-by. */
                            for (ILogicalPlan gbyNestedPlanOriginal : gbyNestedPlans) {
                                // add a subplan in the original gby
                                if (!newGbyNestedPlans.contains(gbyNestedPlanOriginal)) {
                                    newGbyNestedPlans.add(gbyNestedPlanOriginal);
                                }

                                // add a pushed subplan
                                ILogicalPlan gbyNestedPlan = OperatorManipulationUtil
                                        .deepCopy(gbyNestedPlanOriginal, context);
                                List<Mutable<ILogicalOperator>> gbyRootOpRefs = gbyNestedPlan.getRoots();
                                for (int rootIndex = 0; rootIndex < gbyRootOpRefs.size(); rootIndex++) {
                                    //set the nts for a original subplan
                                    Mutable<ILogicalOperator> originalGbyRootOpRef = gbyNestedPlanOriginal
                                            .getRoots().get(rootIndex);
                                    Mutable<ILogicalOperator> originalGbyNtsRef = downToNts(
                                            originalGbyRootOpRef);
                                    NestedTupleSourceOperator originalNts = (NestedTupleSourceOperator) originalGbyNtsRef
                                            .getValue();
                                    originalNts
                                            .setDataSourceReference(new MutableObject<ILogicalOperator>(gby));

                                    //push a new subplan if possible
                                    Mutable<ILogicalOperator> gbyRootOpRef = gbyRootOpRefs.get(rootIndex);
                                    Set<LogicalVariable> liveVars = new ListSet<LogicalVariable>();
                                    VariableUtilities.getLiveVariables(gbyRootOpRef.getValue(), liveVars);
                                    if (liveVars.containsAll(freeVars)) {
                                        /** Does the actual push. */
                                        Mutable<ILogicalOperator> ntsRef = downToNts(rootOpRef);
                                        ntsRef.setValue(gbyRootOpRef.getValue());
                                        // Removes unused vars.
                                        AggregateOperator aggOp = (AggregateOperator) gbyRootOpRef.getValue();
                                        for (int varIndex = aggOp.getVariables().size()
                                                - 1; varIndex >= 0; varIndex--) {
                                            if (!freeVars.contains(aggOp.getVariables().get(varIndex))) {
                                                aggOp.getVariables().remove(varIndex);
                                                aggOp.getExpressions().remove(varIndex);
                                            }
                                        }

                                        gbyRootOpRef.setValue(rootOpRef.getValue());
                                        rootOpRefsToRemove.add(rootOpRef);

                                        // Sets the nts for a new pushed plan.
                                        Mutable<ILogicalOperator> oldGbyNtsRef = downToNts(gbyRootOpRef);
                                        NestedTupleSourceOperator nts = (NestedTupleSourceOperator) oldGbyNtsRef
                                                .getValue();
                                        nts.setDataSourceReference(new MutableObject<ILogicalOperator>(gby));

                                        newGbyNestedPlans.add(gbyNestedPlan);
                                        changed = true;
                                        continue;
                                    }
                                }
                            }
                        }
                        rootOpRefs.removeAll(rootOpRefsToRemove);
                        if (rootOpRefs.size() == 0) {
                            subplanNestedPlansToRemove.add(subplanNestedPlan);
                        }
                    }
                    subplanNestedPlans.removeAll(subplanNestedPlansToRemove);
                }
                if (changed) {
                    ref.setValue(gby);
                    gby.getNestedPlans().clear();
                    gby.getNestedPlans().addAll(newGbyNestedPlans);
                }
            }
        }
    }
    if (changed) {
        cleanup(gby);
    }
    return changed;
}

From source file:org.syncope.core.rest.controller.UserController.java

private UserTO setStatus(final SyncopeUser user, final Set<String> resourceNames, final boolean performLocally,
        final boolean performRemotely, final boolean status, final String performedTask)
        throws NotFoundException, WorkflowException, UnauthorizedRoleException, PropagationException {

    LOG.debug("About to suspend " + user.getId());

    List<PropagationTask> tasks = null;
    WorkflowResult<Long> updated = null;

    if (performLocally) {
        // perform local changes

        if ("suspend".equals(performedTask)) {
            updated = wfAdapter.suspend(user.getId());
        } else if ("reactivate".equals(performedTask)) {
            updated = wfAdapter.reactivate(user.getId());
        } else {//from ww  w . j  av  a2s  .c o  m
            updated = wfAdapter.activate(user.getId(), user.getToken());
        }
    } else {
        // do not perform local changes
        updated = new WorkflowResult<Long>(user.getId(), null, performedTask);
    }

    // Resources to exclude from propagation.
    Set<String> resources = new HashSet<String>();
    if (!performRemotely) {
        resources.addAll(user.getResourceNames());
    } else {
        if (resourceNames != null) {
            resources.addAll(user.getResourceNames());
            resources.removeAll(resourceNames);
        }
    }

    tasks = propagationManager.getUpdateTaskIds(user, status, resources);

    propagationManager.execute(tasks);
    notificationManager.createTasks(updated);

    final UserTO savedTO = userDataBinder.getUserTO(updated.getResult());

    LOG.debug("About to return suspended user\n{}", savedTO);

    return savedTO;
}

From source file:io.apiman.test.common.json.JsonCompare.java

/**
 * Asserts that the JSON document matches what we expected.
 * @param expectedJson/*from  ww  w  .j  a v  a2s. c  o  m*/
 * @param actualJson
 */
public void assertJson(JsonNode expectedJson, JsonNode actualJson) {
    if (expectedJson instanceof ArrayNode) {
        JsonNode actualValue = actualJson;
        ArrayNode expectedArray = (ArrayNode) expectedJson;
        Assert.assertEquals(
                message("Expected JSON array but found non-array [{0}] instead.",
                        actualValue.getClass().getSimpleName()),
                expectedJson.getClass(), actualValue.getClass());
        ArrayNode actualArray = (ArrayNode) actualValue;
        Assert.assertEquals(message("Array size mismatch."), expectedArray.size(), actualArray.size());

        JsonNode[] expected = new JsonNode[expectedArray.size()];
        JsonNode[] actual = new JsonNode[actualArray.size()];
        for (int idx = 0; idx < expected.length; idx++) {
            expected[idx] = expectedArray.get(idx);
            actual[idx] = actualArray.get(idx);
        }
        // If strict ordering is disabled, then sort both arrays
        if (getArrayOrdering() == JsonArrayOrderingType.any) {
            Comparator<? super JsonNode> comparator = new Comparator<JsonNode>() {
                @Override
                public int compare(JsonNode o1, JsonNode o2) {
                    String str1 = o1.asText();
                    String str2 = o2.asText();
                    if (o1.isObject() && o2.isObject()) {
                        // Try name (PermissionBean only)
                        JsonNode o1NameNode = o1.get("name");
                        JsonNode o2NameNode = o2.get("name");
                        if (o1NameNode != null && o2NameNode != null) {
                            str1 = o1NameNode.asText();
                            str2 = o2NameNode.asText();
                        }

                        // Try username (UserBean only)
                        JsonNode o1UsernameNode = o1.get("username");
                        JsonNode o2UsernameNode = o2.get("username");
                        if (o1UsernameNode != null && o2UsernameNode != null) {
                            str1 = o1UsernameNode.asText();
                            str2 = o2UsernameNode.asText();
                        }

                        // Try version (*VersionBeans)
                        JsonNode o1VersionNode = o1.get("version");
                        JsonNode o2VersionNode = o2.get("version");
                        if (o1VersionNode != null && o2VersionNode != null) {
                            str1 = o1VersionNode.asText();
                            str2 = o2VersionNode.asText();
                        }

                        // Try OrganizationBean.id (Orgs)
                        JsonNode o1OrgNode = o1.get("OrganizationBean");
                        JsonNode o2OrgNode = o2.get("OrganizationBean");
                        if (o1OrgNode != null && o2OrgNode != null) {
                            str1 = o1OrgNode.get("id").asText();
                            str2 = o2OrgNode.get("id").asText();
                        }

                        // Try ClientBean.id (Orgs)
                        JsonNode o1ClientNode = o1.get("ClientBean");
                        JsonNode o2ClientNode = o2.get("ClientBean");
                        if (o1ClientNode != null && o2ClientNode != null) {
                            str1 = o1ClientNode.get("id").asText();
                            str2 = o2ClientNode.get("id").asText();
                        }

                        // Try PlanBean.id (Orgs)
                        JsonNode o1PlanNode = o1.get("PlanBean");
                        JsonNode o2PlanNode = o2.get("PlanBean");
                        if (o1PlanNode != null && o2PlanNode != null) {
                            str1 = o1PlanNode.get("id").asText();
                            str2 = o2PlanNode.get("id").asText();
                        }

                        // Try ApiBean.id (Orgs)
                        JsonNode o1ApiNode = o1.get("ApiBean");
                        JsonNode o2ApiNode = o2.get("ApiBean");
                        if (o1ApiNode != null && o2ApiNode != null) {
                            str1 = o1ApiNode.get("id").asText();
                            str2 = o2ApiNode.get("id").asText();
                        }

                        // Try Id (all other beans)
                        JsonNode o1IdNode = o1.get("id");
                        JsonNode o2IdNode = o2.get("id");
                        if (o1IdNode != null && o2IdNode != null) {
                            if (o1IdNode.isNumber()) {
                                return new Long(o1IdNode.asLong()).compareTo(o2IdNode.asLong());
                            }
                            str1 = o1IdNode.asText();
                            str2 = o2IdNode.asText();
                        }
                    }
                    int cmp = str1.compareTo(str2);
                    if (cmp == 0)
                        cmp = 1;
                    return cmp;
                }
            };
            Arrays.sort(expected, comparator);
            Arrays.sort(actual, comparator);
        }
        for (int idx = 0; idx < expected.length; idx++) {
            currentPath.push(idx);
            assertJson(expected[idx], actual[idx]);
            currentPath.pop();
        }
    } else {
        Iterator<Entry<String, JsonNode>> fields = expectedJson.fields();
        Set<String> expectedFieldNames = new HashSet<>();
        while (fields.hasNext()) {
            Entry<String, JsonNode> entry = fields.next();
            String expectedFieldName = entry.getKey();
            expectedFieldNames.add(expectedFieldName);
            JsonNode expectedValue = entry.getValue();
            currentPath.push(expectedFieldName);
            if (expectedValue instanceof TextNode) {
                TextNode tn = (TextNode) expectedValue;
                String expected = tn.textValue();
                JsonNode actualValue = actualJson.get(expectedFieldName);

                if (isIgnoreCase()) {
                    expected = expected.toLowerCase();
                    if (actualValue == null) {
                        actualValue = actualJson.get(expectedFieldName.toLowerCase());
                    }
                }

                Assert.assertNotNull(
                        message("Expected JSON text field \"{0}\" with value \"{1}\" but was not found.",
                                expectedFieldName, expected),
                        actualValue);
                Assert.assertEquals(message(
                        "Expected JSON text field \"{0}\" with value \"{1}\" but found non-text [{2}] field with that name instead.",
                        expectedFieldName, expected, actualValue.getClass().getSimpleName()), TextNode.class,
                        actualValue.getClass());
                String actual = ((TextNode) actualValue).textValue();

                if (isIgnoreCase()) {
                    if (actual != null) {
                        actual = actual.toLowerCase();
                    }
                }

                if (!expected.equals("*")) {
                    Assert.assertEquals(message("Value mismatch for text field \"{0}\".", expectedFieldName),
                            expected, actual);
                }
            } else if (expectedValue.isNumber()) {
                NumericNode numeric = (NumericNode) expectedValue;
                Number expected = numeric.numberValue();
                JsonNode actualValue = actualJson.get(expectedFieldName);
                try {
                    Assert.assertNotNull(
                            message("Expected JSON numeric field \"{0}\" with value \"{1}\" but was not found.",
                                    expectedFieldName, expected),
                            actualValue);
                } catch (Error e) {
                    throw e;
                }
                Assert.assertTrue(message(
                        "Expected JSON numeric field \"{0}\" with value \"{1}\" but found non-numeric [{2}] field with that name instead.",
                        expectedFieldName, expected, actualValue.getClass().getSimpleName()),
                        actualValue.isNumber());
                Number actual = ((NumericNode) actualValue).numberValue();
                if (!"id".equals(expectedFieldName) || isCompareNumericIds()) {
                    Assert.assertEquals(message("Value mismatch for numeric field \"{0}\".", expectedFieldName),
                            expected, actual);
                }
            } else if (expectedValue instanceof BooleanNode) {
                BooleanNode bool = (BooleanNode) expectedValue;
                Boolean expected = bool.booleanValue();
                JsonNode actualValue = actualJson.get(expectedFieldName);
                Assert.assertNotNull(
                        message("Expected JSON boolean field \"{0}\" with value \"{1}\" but was not found.",
                                expectedFieldName, expected),
                        actualValue);
                Assert.assertEquals(message(
                        "Expected JSON boolean field \"{0}\" with value \"{1}\" but found non-boolean [{2}] field with that name instead.",
                        expectedFieldName, expected, actualValue.getClass().getSimpleName()),
                        expectedValue.getClass(), actualValue.getClass());
                Boolean actual = ((BooleanNode) actualValue).booleanValue();
                Assert.assertEquals(message("Value mismatch for boolean field \"{0}\".", expectedFieldName),
                        expected, actual);
            } else if (expectedValue instanceof ObjectNode) {
                JsonNode actualValue = actualJson.get(expectedFieldName);
                Assert.assertNotNull(
                        message("Expected parent JSON field \"{0}\" but was not found.", expectedFieldName),
                        actualValue);
                Assert.assertEquals(
                        message("Expected parent JSON field \"{0}\" but found field of type \"{1}\".",
                                expectedFieldName, actualValue.getClass().getSimpleName()),
                        ObjectNode.class, actualValue.getClass());
                assertJson(expectedValue, actualValue);
            } else if (expectedValue instanceof ArrayNode) {
                JsonNode actualValue = actualJson.get(expectedFieldName);
                Assert.assertNotNull(
                        message("Expected JSON array field \"{0}\" but was not found.", expectedFieldName),
                        actualValue);
                ArrayNode expectedArray = (ArrayNode) expectedValue;
                Assert.assertEquals(message(
                        "Expected JSON array field \"{0}\" but found non-array [{1}] field with that name instead.",
                        expectedFieldName, actualValue.getClass().getSimpleName()), expectedValue.getClass(),
                        actualValue.getClass());
                ArrayNode actualArray = (ArrayNode) actualValue;
                Assert.assertEquals(message("Field \"{0}\" array size mismatch.", expectedFieldName),
                        expectedArray.size(), actualArray.size());
                assertJson(expectedArray, actualArray);
            } else if (expectedValue instanceof NullNode) {
                JsonNode actualValue = actualJson.get(expectedFieldName);
                Assert.assertNotNull(
                        message("Expected Null JSON field \"{0}\" but was not found.", expectedFieldName),
                        actualValue);
                Assert.assertEquals(
                        message("Expected Null JSON field \"{0}\" but found field of type \"{0}\".",
                                expectedFieldName, actualValue.getClass().getSimpleName()),
                        NullNode.class, actualValue.getClass());
            } else {
                Assert.fail(message("Unsupported field type: {0}", expectedValue.getClass().getSimpleName()));
            }
            currentPath.pop();
        }

        if (getMissingField() == JsonMissingFieldType.fail) {
            Set<String> actualFieldNames = new HashSet();
            Iterator<String> names = actualJson.fieldNames();
            while (names.hasNext()) {
                actualFieldNames.add(names.next());
            }
            actualFieldNames.removeAll(expectedFieldNames);
            Assert.assertTrue(message("Found unexpected fields: {0}", StringUtils.join(actualFieldNames, ", ")),
                    actualFieldNames.isEmpty());
        }
    }
}

From source file:bdi4jade.core.AbstractBDIAgent.java

final void resetAllCapabilities() {
    synchronized (aggregatedCapabilities) {
        Set<Capability> oldCapabilities = this.capabilities;
        Set<Capability> allCapabilities = new HashSet<>();
        for (Capability capability : aggregatedCapabilities) {
            allCapabilities.add(capability);
            capability.addRelatedCapabilities(allCapabilities);
        }/*from w ww .  j a  v  a2 s .  c om*/
        this.capabilities = allCapabilities;
        log.debug("Capabilities: " + this.capabilities);

        Set<Capability> removedCapabilities = new HashSet<>(oldCapabilities);
        removedCapabilities.removeAll(allCapabilities);
        for (Capability capability : removedCapabilities) {
            capability.setMyAgent(null);
        }

        Set<Capability> addedCapabilities = new HashSet<>(allCapabilities);
        addedCapabilities.removeAll(oldCapabilities);
        for (Capability capability : addedCapabilities) {
            if (capability.getMyAgent() != null) {
                throw new IllegalArgumentException(
                        "Capability already binded to another agent: " + capability.getFullId());
            }
            capability.setMyAgent(this);
        }
    }
}

From source file:com.bluexml.side.Integration.alfresco.sql.synchronization.schemaManagement.SchemaCreation.java

public void afterDictionaryInit() {

    logger.debug("Checking for new model to replicate in synchronization database");
    Set<QName> acceptableModelNames = new HashSet<QName>();
    for (QName modelName : dictionaryDAO.getModels()) {
        if (filterer.acceptModelQName(modelName)) {
            acceptableModelNames.add(modelName);
        }//from   www. java2  s.com
    }
    if (logger.isDebugEnabled())
        logger.debug("Acceptable models: [" + StringUtils.join(acceptableModelNames.iterator(), ",") + "]");
    acceptableModelNames.removeAll(replicatedModels);
    if (logger.isDebugEnabled())
        logger.debug("New models: [" + StringUtils.join(acceptableModelNames.iterator(), ",") + "]");

    for (QName modelName : acceptableModelNames) {
        createFromModel(modelName);
    }
    for (QName modelName : acceptableModelNames) {
        replicateFromModel(modelName);
    }
}