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:com.fluidops.iwb.widget.SemWiki.java

/**
 * Extracts semantic links from the old and from the new wiki page and collects the diff
 * inside the addStmts and remStmts variables.
 * /*from w w w  . j  av  a2 s.c  o m*/
 * @param wikiPageOld the old wiki page text (may be null or empty)
 * @param wikiPageNew (may be null or empty)
 * @param subject the URI represented by the wiki page
 * @param context the context in which to store the diff
 */
public static void saveSemanticLinkDiff(String wikiPageOld, String wikiPageNew, URI subject, Context context) {
    try {
        List<Statement> oldStmts = Wikimedia.getSemanticRelations(wikiPageOld, subject);
        List<Statement> newStmts = Wikimedia.getSemanticRelations(wikiPageNew, subject);

        // calculate stmts to remove
        Set<Statement> remStmts = new HashSet<Statement>();
        remStmts.addAll(oldStmts);
        remStmts.removeAll(newStmts);

        // calculate stmts to add
        Set<Statement> addStmts = new HashSet<Statement>();
        addStmts.addAll(newStmts);
        // Note msc: 
        // strictly speaking, we should do the following now:
        //
        // addStmts.removeAll(oldStmts);
        // 
        // , to add only those statements that were definitely added. Though we
        // encountered problems with this (e.g. when pressing the Save button
        // twice), resulting in statements that are visible in the Wiki as sem
        // links, but not contained in the DB. Given that the addToContext() 
        // will not create duplicates anyway, we write all statements, to avoid
        // the above-mentioned problems.

        ReadWriteDataManager dm = null;
        try {
            dm = ReadWriteDataManagerImpl.openDataManager(Global.repository);
            if (remStmts.size() > 0)
                dm.removeInEditableContexts(remStmts, context);

            if (addStmts.size() > 0)
                dm.addToContextNoDuplicates(addStmts, context);
        } finally {
            ReadWriteDataManagerImpl.closeQuietly(dm);
        }

        // update statements in keyword index
        KeywordIndexAPI.replaceKeywordIndexEntry(subject);
    } catch (Exception e) {
        String message = e.getMessage();
        if (e instanceof UnsupportedOperationException)
            message = "Write operations to the repository not supported (read only).";
        logger.debug("Error while saving semantic links: " + message);
        throw new RuntimeException("Error while saving semantic links: " + message, e);
    }
}

From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java

public static <T extends Element> Set<T> removeInvisibleElements(Set<T> elements,
        HighlightConditionList highlightConditions) {
    Set<T> removed = new LinkedHashSet<>();

    highlightConditions.getConditions().stream().filter(c -> c.isInvisible()).forEach(c -> {
        Set<T> toRemove = c.getValues(elements).entrySet().stream().filter(e -> e.getValue() != 0.0)
                .map(e -> e.getKey()).collect(Collectors.toCollection(LinkedHashSet::new));

        elements.removeAll(toRemove);
        removed.addAll(toRemove);//  www . j a  v  a  2s . c  om
    });

    return removed;
}

From source file:io.cloudslang.lang.compiler.modeller.transformers.AbstractTransformer.java

protected void validateKeySet(Set<String> keySet, Set<String> mandatoryKeys, Set<String> optionalKeys) {
    Validate.notNull(keySet);/*ww w  .  ja  v  a 2s . c o m*/
    Validate.notNull(mandatoryKeys);
    Validate.notNull(optionalKeys);

    Set<String> missingKeys = new HashSet<>(mandatoryKeys);
    missingKeys.removeAll(keySet);
    if (CollectionUtils.isNotEmpty(missingKeys)) {
        throw new RuntimeException(MISSING_KEYS_ERROR_MESSAGE_PREFIX + missingKeys.toString());
    }

    Set<String> invalidKeys = new HashSet<>(keySet);
    invalidKeys.removeAll(mandatoryKeys);
    invalidKeys.removeAll(optionalKeys);
    if (CollectionUtils.isNotEmpty(invalidKeys)) {
        throw new RuntimeException(
                INVALID_KEYS_ERROR_MESSAGE_PREFIX + invalidKeys.toString() + INVALID_KEYS_ERROR_MESSAGE_SUFFIX);
    }
}

From source file:com.github.fge.jsonschema.keyword.validator.draftv3.PropertiesValidator.java

@Override
public void validate(final Processor<FullData, FullData> processor, final ProcessingReport report,
        final MessageBundle bundle, final FullData data) throws ProcessingException {
    final Set<String> set = Sets.newLinkedHashSet(required);
    set.removeAll(Sets.newHashSet(data.getInstance().getNode().fieldNames()));

    if (!set.isEmpty())
        report.error(newMsg(data, bundle, "err.common.object.missingMembers").put("required", required)
                .putArgument("missing", toArrayNode(set)));
}

From source file:com.pinterest.terrapin.controller.HdfsManager.java

static double calculateDeviationForResource(String resource, IdealState idealState,
        RoutingTableProvider routingTableProvider) {
    Set<String> partitions = idealState.getPartitionSet();
    int totalAssignments = 0, totalDeviations = 0;
    // Check if the external view has deviated from the actual view.
    for (String partition : partitions) {
        // Make a copy of the instance mapping in the ideal state.
        Set<String> idealInstances = new HashSet(idealState.getInstanceSet(partition));
        totalAssignments += idealInstances.size();
        // Now check against our real state and count the amount of deviating
        // assignments.
        List<InstanceConfig> currentInstanceConfigs = routingTableProvider.getInstances(resource, partition,
                "ONLINE");
        Set<String> currentInstances = Sets.newHashSetWithExpectedSize(currentInstanceConfigs.size());
        if (currentInstanceConfigs != null) {
            for (InstanceConfig instanceConfig : currentInstanceConfigs) {
                currentInstances.add(instanceConfig.getHostName());
            }/*from   w  w w. j a  v  a 2s  .  com*/
        }
        idealInstances.removeAll(currentInstances);
        totalDeviations += idealInstances.size();
    }
    return (double) totalDeviations / totalAssignments;
}

From source file:com.espertech.esper.epl.join.plan.NStreamOuterQueryPlanBuilder.java

/**
 * Recusivly builds a substream-per-stream ordered tree graph using the
 * join information supplied for outer joins and from the query graph (where clause).
 * <p>/*  ww  w.ja  va2 s .c  o  m*/
 * Required streams are considered first and their lookup is placed first in the list
 * to gain performance.
 * @param streamNum is the root stream number that supplies the incoming event to build the tree for
 * @param queryGraph contains where-clause stream relationship info
 * @param outerInnerGraph contains the outer join stream relationship info
 * @param completedStreams is a temporary holder for streams already considered
 * @param substreamsPerStream is the ordered, tree-like structure to be filled
 * @param requiredPerStream indicates which streams are required and which are optional
 * @param streamCallStack the query plan call stack of streams available via cursor
 * @param dependencyGraph - dependencies between historical streams
 * @throws ExprValidationException if the query planning failed
 */
protected static void recursiveBuild(int streamNum, Stack<Integer> streamCallStack, QueryGraph queryGraph,
        OuterInnerDirectionalGraph outerInnerGraph, InnerJoinGraph innerJoinGraph,
        Set<Integer> completedStreams, LinkedHashMap<Integer, int[]> substreamsPerStream,
        boolean[] requiredPerStream, DependencyGraph dependencyGraph) throws ExprValidationException {
    // add this stream to the set of completed streams
    completedStreams.add(streamNum);

    // check if the dependencies have been satisfied
    if (dependencyGraph.hasDependency(streamNum)) {
        Set<Integer> dependencies = dependencyGraph.getDependenciesForStream(streamNum);
        for (Integer dependentStream : dependencies) {
            if (!streamCallStack.contains(dependentStream)) {
                throw new ExprValidationException(
                        "Historical stream " + streamNum + " parameter dependency originating in stream "
                                + dependentStream + " cannot or may not be satisfied by the join");
            }
        }
    }

    // Determine the streams we can navigate to from this stream
    Set<Integer> navigableStreams = queryGraph.getNavigableStreams(streamNum);

    // add unqualified navigable streams (since on-expressions in outer joins are optional)
    Set<Integer> unqualifiedNavigable = outerInnerGraph.getUnqualifiedNavigableStreams().get(streamNum);
    if (unqualifiedNavigable != null) {
        navigableStreams.addAll(unqualifiedNavigable);
    }

    // remove those already done
    navigableStreams.removeAll(completedStreams);

    // Which streams are inner streams to this stream (optional), which ones are outer to the stream (required)
    Set<Integer> requiredStreams = getOuterStreams(streamNum, navigableStreams, outerInnerGraph);

    // Add inner joins, if any, unless already completed for this stream
    innerJoinGraph.addRequiredStreams(streamNum, requiredStreams, completedStreams);

    Set<Integer> optionalStreams = getInnerStreams(streamNum, navigableStreams, outerInnerGraph, innerJoinGraph,
            completedStreams);

    // Remove from the required streams the optional streams which places 'full' joined streams
    // into the optional stream category
    requiredStreams.removeAll(optionalStreams);

    // if we are a leaf node, we are done
    if (navigableStreams.isEmpty()) {
        substreamsPerStream.put(streamNum, new int[0]);
        return;
    }

    // First the outer (required) streams to this stream, then the inner (optional) streams
    int[] substreams = new int[requiredStreams.size() + optionalStreams.size()];
    substreamsPerStream.put(streamNum, substreams);
    int count = 0;
    for (int stream : requiredStreams) {
        substreams[count++] = stream;
        requiredPerStream[stream] = true;
    }
    for (int stream : optionalStreams) {
        substreams[count++] = stream;
    }

    // next we look at all the required streams and add their dependent streams
    for (int stream : requiredStreams) {
        completedStreams.add(stream);
    }

    for (int stream : requiredStreams) {
        streamCallStack.push(stream);
        recursiveBuild(stream, streamCallStack, queryGraph, outerInnerGraph, innerJoinGraph, completedStreams,
                substreamsPerStream, requiredPerStream, dependencyGraph);
        streamCallStack.pop();
    }
    // look at all the optional streams and add their dependent streams
    for (int stream : optionalStreams) {
        streamCallStack.push(stream);
        recursiveBuild(stream, streamCallStack, queryGraph, outerInnerGraph, innerJoinGraph, completedStreams,
                substreamsPerStream, requiredPerStream, dependencyGraph);
        streamCallStack.pop();
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.MaskingOntModelCache.java

private void checkForMissingNamedModels() {
    Set<String> missingModelNames = new HashSet<>(this.maskingNames);
    missingModelNames.removeAll(maskingCache.getModelNames());
    if (!missingModelNames.isEmpty()) {
        log.warn("Specifed models do not exist in the masking cache: " + missingModelNames);
        maskingNames.removeAll(missingModelNames);
    }/*from ww w.j  ava2s  . c  o m*/
}

From source file:org.eel.kitchen.jsonschema.keyword.PropertiesKeywordValidator.java

@Override
public void validate(final ValidationContext context, final ValidationReport report, final JsonNode instance) {
    final Set<String> fields = JacksonUtils.fieldNames(instance);

    if (fields.containsAll(required))
        return;/*from ww  w. ja  v a2 s.c o  m*/

    final Set<String> requiredSorted = Sets.newTreeSet(required);
    final Set<String> missing = Sets.newTreeSet(required);
    missing.removeAll(fields);

    final Message.Builder msg = newMsg().addInfo("required", requiredSorted).addInfo("missing", missing)
            .setMessage("required property(ies) not found");
    report.addMessage(msg.build());
}

From source file:org.trustedanalytics.serviceexposer.keyvaluestore.RedisCredentialsStore.java

@Override
public Set<String> getSurplusServicesGuids(String serviceType, Set<String> servicesGuids) {
    Set<String> serviceInstancesToDeleted = this.hashOps.keys(serviceType);
    serviceInstancesToDeleted.removeAll(servicesGuids);
    return serviceInstancesToDeleted;
}

From source file:com.vrem.wifianalyzer.wifi.graphutils.SeriesCache.java

List<WiFiDetail> difference(@NonNull Set<WiFiDetail> series) {
    Set<WiFiDetail> difference = new TreeSet<>(cache.keySet());
    difference.removeAll(series);
    return new ArrayList<>(difference);
}