Example usage for com.google.common.collect Multimap removeAll

List of usage examples for com.google.common.collect Multimap removeAll

Introduction

In this page you can find the example usage for com.google.common.collect Multimap removeAll.

Prototype

Collection<V> removeAll(@Nullable Object key);

Source Link

Document

Removes all values associated with the key key .

Usage

From source file:org.jclouds.aws.ec2.filters.FormSigner.java

@VisibleForTesting
void addSigningParams(Multimap<String, String> params) {
    params.replaceValues(SIGNATURE_METHOD, ImmutableList.of("HmacSHA256"));
    params.replaceValues(SIGNATURE_VERSION, ImmutableList.of("2"));
    params.replaceValues(TIMESTAMP, ImmutableList.of(dateService.get()));
    params.replaceValues(AWS_ACCESS_KEY_ID, ImmutableList.of(accessKey));
    params.removeAll(SIGNATURE);
}

From source file:pt.ua.tm.trigner.documents.Documents.java

public void cleanFeatures(final String[] except) {
    List<String> exceptList = Arrays.asList(except);
    for (Corpus corpus : this) {
        for (Sentence sentence : corpus) {
            for (Token token : sentence) {
                Multimap<String, String> current = token.getFeaturesMap();
                //                    Multimap<String, String> next = HashMultimap.create();

                List<String> toRemove = new ArrayList<>();
                for (String key : current.keySet()) {
                    if (!exceptList.contains(key)) {
                        toRemove.add(key);
                    }//w w  w  .  j  a  va 2s .  c  o  m
                }

                for (String keyToRemove : toRemove) {
                    current.removeAll(keyToRemove);
                }

                // Set new map
                //                    current = null;
                //                    token.setFeaturesMap(next);
            }
        }
    }
}

From source file:org.jclouds.ecs.filters.QuerySigner.java

@VisibleForTesting
void addSigningParams(Multimap<String, String> params) {
    params.replaceValues("AccessKeyId", ImmutableList.of(creds.get().identity));
    params.replaceValues("AccessKeyId", ImmutableList.of("bnF9nNdDFCTwM5mF"));
    params.replaceValues("SignatureMethod", ImmutableList.of("HMAC-SHA1"));
    params.replaceValues("Timestamp", ImmutableList.of(Timestamps.getCurrent()));
    params.replaceValues("SignatureVersion", ImmutableList.of("1.0"));
    params.replaceValues("SignatureNonce", ImmutableList.of(String.valueOf(new Random().nextInt())));
    params.removeAll("Signature");
}

From source file:com.facebook.buck.cli.MissingSymbolsHandler.java

/**
 * Instantiate a MissingSymbolsHandler and wrap it in a listener that calls it on the appropriate
 * events. This is done as part of the global listener setup in Main, and it's the entry point
 * into most of the dependency autodetection code.
 *///from   w  ww  .  j  a  va  2  s  .  c o  m
public static BuckEventListener createListener(ProjectFilesystem projectFilesystem,
        ImmutableSet<Description<?>> descriptions, BuckConfig config, BuckEventBus buckEventBus,
        Console console, JavacOptions javacOptions, ImmutableMap<String, String> environment) {
    final MissingSymbolsHandler missingSymbolsHandler = create(projectFilesystem, descriptions, config,
            buckEventBus, console, javacOptions, environment);

    final Multimap<BuildId, MissingSymbolEvent> missingSymbolEvents = HashMultimap.create();

    BuckEventListener missingSymbolsListener = new BuckEventListener() {
        @Override
        public void outputTrace(BuildId buildId) {
            // If we put {@link #printNeededDependencies} here, it's output won't be visible in buckd.
            // Instead, we listen for BuildEvent.Finished, below.
        }

        @Subscribe
        public void onMissingSymbol(MissingSymbolEvent event) {
            missingSymbolEvents.put(event.getBuildId(), event);
        }

        @Subscribe
        public void onBuildFinished(BuildEvent.Finished event) {
            // Shortcircuit if there aren't any failures.
            if (missingSymbolEvents.get(event.getBuildId()).isEmpty()) {
                return;
            }
            try {
                missingSymbolsHandler.printNeededDependencies(missingSymbolEvents.get(event.getBuildId()));
            } catch (InterruptedException e) {
                LOG.debug(e, "Missing symbols handler did not complete in time.");
            } catch (RuntimeException e) {
                if (e.getCause() instanceof ClosedByInterruptException) {
                    LOG.debug(e.getCause(), "Missing symbols handler did not complete in time.");
                } else {
                    throw e;
                }
            }
            missingSymbolEvents.removeAll(event.getBuildId());
        }
    };

    return missingSymbolsListener;
}

From source file:org.eclipse.xtext.ui.refactoring.impl.AbstractReferenceUpdater.java

protected void createReferenceUpdatesForCluster(ElementRenameArguments elementRenameArguments,
        Multimap<URI, IReferenceDescription> resource2references, ResourceSet resourceSet,
        IRefactoringUpdateAcceptor updateAcceptor, StatusWrapper status, IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, 100);
    List<URI> unloadableResources = loadReferringResources(resourceSet, resource2references.keySet(), status,
            progress.newChild(10));/*from  w  w  w  . j a v  a  2 s .  com*/
    if (progress.isCanceled()) {
        throw new OperationCanceledException();
    }
    for (URI unloadableResouce : unloadableResources)
        resource2references.removeAll(unloadableResouce);
    List<IReferenceDescription> unresolvableReferences = resolveReferenceProxies(resourceSet,
            resource2references.values(), status, progress.newChild(70));
    if (progress.isCanceled()) {
        throw new OperationCanceledException();
    }
    for (IReferenceDescription unresolvableReference : unresolvableReferences) {
        URI unresolvableReferringResource = unresolvableReference.getSourceEObjectUri().trimFragment();
        resource2references.remove(unresolvableReferringResource, unresolvableReference);
    }
    elementRenameArguments.getRenameStrategy().applyDeclarationChange(elementRenameArguments.getNewName(),
            resourceSet);
    if (progress.isCanceled()) {
        throw new OperationCanceledException();
    }
    createReferenceUpdates(elementRenameArguments, resource2references, resourceSet, updateAcceptor,
            progress.newChild(20));
    if (progress.isCanceled()) {
        throw new OperationCanceledException();
    }
    elementRenameArguments.getRenameStrategy().revertDeclarationChange(resourceSet);
}

From source file:org.eclipse.xtext.serializer.sequencer.ContextFinder.java

@Override
public Set<ISerializationContext> findByContents(EObject semanticObject,
        Iterable<ISerializationContext> contextCandidates) {
    if (semanticObject == null)
        throw new NullPointerException();

    initConstraints();//from w  ww . j a  v  a2s. co m

    Multimap<IConstraint, ISerializationContext> constraints;
    if (contextCandidates != null)
        constraints = getConstraints(semanticObject, contextCandidates);
    else
        constraints = getConstraints(semanticObject);

    if (constraints.size() < 2)
        return Sets.newLinkedHashSet(constraints.values());

    for (IConstraint cand : Lists.newArrayList(constraints.keySet()))
        if (!isValidValueQuantity(cand, semanticObject))
            constraints.removeAll(cand);

    if (constraints.size() < 2)
        return Sets.newLinkedHashSet(constraints.values());

    LinkedHashSet<ISerializationContext> result = Sets.newLinkedHashSet(constraints.values());
    for (EStructuralFeature feat : semanticObject.eClass().getEAllStructuralFeatures()) {
        if (transientValueUtil.isTransient(semanticObject, feat) != ValueTransient.NO)
            continue;
        if (feat.isMany() && ((List<?>) semanticObject.eGet(feat)).isEmpty())
            continue;
        Multimap<AbstractElement, ISerializationContext> assignments = collectAssignments(constraints, feat);
        Set<AbstractElement> assignedElements = findAssignedElements(semanticObject, feat, assignments);
        Set<ISerializationContext> keep = Sets.newHashSet();
        for (AbstractElement ele : assignedElements)
            keep.addAll(assignments.get(ele));
        result.retainAll(keep);
    }
    return result;
}

From source file:com.vecna.dbDiff.business.dbCompare.impl.RdbDiffEngine.java

/**
 * Compare the indices of two tables./*from   ww  w . j av  a 2  s .co  m*/
 * @param refT reference table.
 * @param testT test table.
 * @return the list of index differences.
 */
private List<RdbCompareError> compareIndices(final RelationalTable refT, final RelationalTable testT) {
    Multimap<List<String>, RelationalIndex> refIndices = ArrayListMultimap.create(refT.getIndicesByColumns());
    List<RdbCompareError> errors = new ArrayList<>();

    for (final Entry<List<String>, Collection<RelationalIndex>> entry : testT.getIndicesByColumns().asMap()
            .entrySet()) {
        Collection<RelationalIndex> matchingRefIndices = refIndices.removeAll(entry.getKey());
        if (CollectionUtils.isEmpty(matchingRefIndices)) {
            for (RelationalIndex testIndex : entry.getValue()) {
                errors.add(new RdbCompareError(RdbCompareErrorType.UNEXPECTED_INDEX,
                        "Test index \"" + getIndexDesc(testIndex, testT) + "\" is unexpected!"));
            }
        } else {
            int testIndicesWithUnknownNames = 0;
            int refIndicesWithUnknownNames = 0;
            Set<String> testIndexNames = Sets.newHashSet();
            Set<String> refIndexNames = Sets.newHashSet();

            for (RelationalIndex refIndex : matchingRefIndices) {
                if (refIndex.getName() == null) {
                    refIndicesWithUnknownNames++;
                } else {
                    refIndexNames.add(refIndex.getName());
                }
            }

            for (RelationalIndex testIndex : entry.getValue()) {
                if (testIndex.getName() == null) {
                    testIndicesWithUnknownNames++;
                } else {
                    if (!refIndexNames.remove(testIndex.getName())) {
                        testIndexNames.add(testIndex.getName());
                    }
                }
            }

            if (refIndicesWithUnknownNames == 0 && !testIndexNames.isEmpty()) {
                for (String testIndexName : testIndexNames) {
                    errors.add(new RdbCompareError(RdbCompareErrorType.UNEXPECTED_INDEX, "Test index \""
                            + getIndexDesc(testIndexName, entry.getKey(), testT) + "\" is unexpected!"));
                }
            } else if (testIndexNames.size() > refIndicesWithUnknownNames) {
                errors.add(new RdbCompareError(RdbCompareErrorType.UNEXPECTED_INDEX,
                        "At least " + (testIndexNames.size() - refIndicesWithUnknownNames) + " of test indices "
                                + Joiner.on(", ").join(
                                        Collections2.transform(testIndexNames, new Function<String, String>() {
                                            @Override
                                            public String apply(String from) {
                                                return "\"" + getIndexDesc(from, entry.getKey(), testT) + "\"";
                                            }
                                        }))
                                + " are unexpected!"));
            }

            if (testIndicesWithUnknownNames == 0 && !refIndexNames.isEmpty()) {
                for (String refIndexName : refIndexNames) {
                    errors.add(new RdbCompareError(RdbCompareErrorType.MISSING_INDEX, "Reference index \""
                            + getIndexDesc(refIndexName, entry.getKey(), refT) + "\" is missing!"));
                }
            } else if (refIndexNames.size() > testIndicesWithUnknownNames) {
                errors.add(new RdbCompareError(RdbCompareErrorType.MISSING_INDEX,
                        "At least " + (refIndexNames.size() - testIndicesWithUnknownNames)
                                + " of reference indices " + Joiner.on(", ").join(
                                        Collections2.transform(refIndexNames, new Function<String, String>() {
                                            @Override
                                            public String apply(String from) {
                                                return "\"" + getIndexDesc(from, entry.getKey(), refT) + "\"";
                                            }
                                        }))
                                + " are missing!"));
            }
        }
    }
    return errors;
}

From source file:org.summer.ss.core.dispatch.DispatchingSupport.java

protected void removeNonLocalMethods(final JvmGenericType type,
        Multimap<Pair<String, Integer>, JvmOperation> result) {
    List<Pair<String, Integer>> removeKeys = newArrayList();
    for (Pair<String, Integer> signatureTuple : result.keySet()) {
        Collection<JvmOperation> collection = result.get(signatureTuple);
        if (!any(collection, new Predicate<JvmOperation>() {
            public boolean apply(JvmOperation input) {
                return input.getDeclaringType() == type;
            }/*from  w ww.  ja va 2s  . co  m*/
        })) {
            removeKeys.add(signatureTuple);
        }
    }
    for (Pair<String, Integer> signatureTuple : removeKeys) {
        result.removeAll(signatureTuple);
    }
}

From source file:com.b2international.snowowl.datastore.server.snomed.ModuleDependencyCollector.java

public Multimap<String, String> getModuleDependencies(Iterable<Long> storageKeys) throws IOException {
    if (Iterables.isEmpty(storageKeys)) {
        return ImmutableMultimap.of();
    }/*from   w ww .  ja v a 2 s . c o m*/

    final Multimap<String, String> moduleDependencies = HashMultimap.create();

    final Multimap<String, String> componentIdsByReferringModule = HashMultimap.create();
    collectConceptModuleDependencies(storageKeys, componentIdsByReferringModule);
    collectDescriptionModuleDependencies(storageKeys, componentIdsByReferringModule);
    collectRelationshipModuleDependencies(storageKeys, componentIdsByReferringModule);
    collectMemberModuleDependencies(storageKeys, componentIdsByReferringModule);

    // iterate over each module and get modules of all components registered to componentsByReferringModule
    for (String module : ImmutableSet.copyOf(componentIdsByReferringModule.keySet())) {
        final Collection<String> dependencies = componentIdsByReferringModule.removeAll(module);
        for (Class<? extends SnomedComponentDocument> type : CORE_COMPONENT_TYPES) {
            Query<String[]> dependencyQuery = Query.select(String[].class).from(type)
                    .fields(SnomedComponentDocument.Fields.ID, SnomedComponentDocument.Fields.MODULE_ID)
                    .where(SnomedComponentDocument.Expressions.ids(dependencies)).limit(10000).build();
            for (Hits<String[]> dependencyHits : searcher.scroll(dependencyQuery)) {
                for (String[] idAndModule : dependencyHits) {
                    String targetModule = idAndModule[1];
                    if (!module.equals(targetModule)) {
                        moduleDependencies.put(module, targetModule);
                    }
                }
            }
        }
    }

    return moduleDependencies;
}

From source file:org.raml.jaxrs.generator.builders.resources.ResourceBuilder.java

private void buildResource(TypeSpec.Builder typeSpec, GResource currentResource) {

    Multimap<GMethod, GRequest> incomingBodies = ArrayListMultimap.create();
    Multimap<GMethod, GResponse> responses = ArrayListMultimap.create();
    ResourceUtils.fillInBodiesAndResponses(currentResource, incomingBodies, responses);

    Map<String, TypeSpec.Builder> responseSpecs = createResponseClass(typeSpec, incomingBodies, responses);

    for (GMethod gMethod : currentResource.methods()) {

        String methodName = Names.resourceMethodName(gMethod.resource(), gMethod);
        Set<String> mediaTypesForMethod = fetchAllMediaTypesForMethodResponses(gMethod);
        if (gMethod.body().size() == 0) {

            createMethodWithoutBody(typeSpec, gMethod, mediaTypesForMethod, methodName, responseSpecs);
        } else {/*from   w  ww  .  j av a 2s .  c o m*/
            Multimap<String, String> ramlTypeToMediaType = accumulateMediaTypesPerType(incomingBodies, gMethod);
            for (GRequest gRequest : gMethod.body()) {

                if (ramlTypeToMediaType.containsKey(gRequest.type().name())) {
                    createMethodWithBody(typeSpec, gMethod, ramlTypeToMediaType, methodName, gRequest,
                            responseSpecs);
                    ramlTypeToMediaType.removeAll(gRequest.type().name());
                }
            }
        }
    }
}