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

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

Introduction

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

Prototype

boolean containsKey(@Nullable Object key);

Source Link

Document

Returns true if this multimap contains at least one key-value pair with the key key .

Usage

From source file:org.jboss.errai.idea.plugin.ui.completion.XmlDatafieldReference.java

private List<DataFieldRef> findLinkedTemplateAndDataFields() {
    final Project project = getElement().getProject();
    DaemonCodeAnalyzer.getInstance(project).restart();

    final XmlFile xmlFile = getXmlFile();
    final List<DataFieldRef> dataFieldRefs = new ArrayList<DataFieldRef>();
    final Multimap<String, TemplateDataField> allDataFieldTags = TemplateUtil.findAllDataFieldTags(xmlFile,
            xmlFile.getRootTag(), true);

    for (TemplateMetaData metaData : TemplateUtil.getTemplateOwners(xmlFile)) {
        final Collection<AnnotationSearchResult> allAnnotatedElements = Util
                .findAllAnnotatedElements(metaData.getTemplateClass(), Types.DATAFIELD);

        for (String dataField : TemplateUtil.extractDataFieldList(allAnnotatedElements)) {
            if (allDataFieldTags.containsKey(dataField) || dataField.contains(Util.INTELLIJ_MAGIC_STRING))
                continue;

            dataFieldRefs.add(new DataFieldRef(dataField, metaData.getTemplateClass().getQualifiedName()));
        }//from w  w  w  .  j  ava2s .  c om
    }

    return dataFieldRefs;
}

From source file:org.eclipse.xtext.validation.impl.AssignmentQuantityAllocator.java

@Override
public IQuantities getAssignmentQuantities(EObject obj, ISyntaxConstraint rule,
        List<IConcreteSyntaxDiagnostic> acceptor) {
    Multimap<EStructuralFeature, ISyntaxConstraint> assignments = HashMultimap.create();
    collectAssignments(rule, obj, rule, assignments, acceptor);
    //      Map<EStructuralFeature, Integer> quantities = Maps.newHashMap();
    Quantities quants = createQuantities(obj);
    for (EStructuralFeature f : obj.eClass().getEAllStructuralFeatures()) {
        int quantity = getFeatureQuantity(obj, f);
        if (quantity > 0 && !assignments.containsKey(f))
            acceptor.add(diagnosticProvider.createAssignmentMissingDiagnostic(rule, obj, f,
                    Collections.<ISyntaxConstraint>emptySet()));
        else//  w  w  w .  j a v a2 s.c  om
            quants.setFeatureQuantity(f, quantity);
    }
    Multimap<EStructuralFeature, ISyntaxConstraint> multipleAssignments = HashMultimap.create();
    Multimap<EStructuralFeature, ISyntaxConstraint> allowTransients = HashMultimap.create();
    for (Map.Entry<EStructuralFeature, Integer> f : quants.getFeatureQuantities().entrySet()) {
        Collection<ISyntaxConstraint> ass = assignments.get(f.getKey());
        if (ass.isEmpty())
            continue;
        boolean allowTransient = f.getKey() instanceof EAttribute && !f.getKey().isMany() && f.getValue() == 0
                && allowTransient(obj, f.getKey(), ass);
        boolean multiNeeded = ass.size() > 1 && f.getValue() != 0;
        if (allowTransient)
            allowTransients.putAll(f.getKey(), ass);
        if (multiNeeded)
            multipleAssignments.putAll(f.getKey(), ass);
        if (!allowTransient && !multiNeeded)
            for (ISyntaxConstraint a : ass)
                quants.setAssignmentQuantity(a, f.getValue());
    }
    if (multipleAssignments.isEmpty() && allowTransients.isEmpty())
        return quants;
    for (Map.Entry<EStructuralFeature, Collection<ISyntaxConstraint>> e : allowTransients.asMap().entrySet()) {
        int min = 0;
        for (ISyntaxConstraint x : e.getValue())
            min += intervalProvider.getMin(quants, x, Sets.<ISyntaxConstraint>newHashSet());
        int val = min > 0 ? 1 : 0;
        quants.setFeatureQuantity(e.getKey(), val);
        if (e.getValue().size() == 1)
            quants.setAssignmentQuantity(e.getValue().iterator().next(), val);
    }
    //      System.out.println("AllowTransientsQuantities: " + quants.toString());
    if (multipleAssignments.isEmpty())
        return quants;
    return null;
    // TODO: implement an algorithm to handle multipleAssignments. For details, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=310454 
}

From source file:com.ansorgit.plugins.bash.lang.psi.impl.command.BashIncludeCommandImpl.java

@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state,
        PsiElement lastParent, @NotNull PsiElement place) {
    boolean result = PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
    if (!result) {
        //processing is done here
        return false;
    }//from w w w .  ja v a2  s .  co m

    PsiFile containingFile = getContainingFile();
    PsiFile includedFile = BashPsiUtils.findIncludedFile(this);

    Multimap<VirtualFile, PsiElement> visitedFiles = state.get(visitedIncludeFiles);
    if (visitedFiles == null) {
        visitedFiles = Multimaps.newListMultimap(Maps.<VirtualFile, Collection<PsiElement>>newHashMap(),
                new Supplier<List<PsiElement>>() {
                    public List<PsiElement> get() {
                        return Lists.newLinkedList();
                    }
                });
    }

    visitedFiles.put(containingFile.getVirtualFile(), null);

    if (includedFile != null && !visitedFiles.containsKey(includedFile.getVirtualFile())) {
        //mark the file as visited before the actual visit, otherwise we'll get a stack overflow
        visitedFiles.put(includedFile.getVirtualFile(), this);

        state = state.put(visitedIncludeFiles, visitedFiles);

        return includedFile.processDeclarations(processor, state, lastParent, place);
    }

    return true;
}

From source file:com.google.caliper.runner.ParsedOptions.java

private void addToMultimap(String nameAndValues, Multimap<String, String> multimap)
        throws InvalidCommandException {
    int eq = nameAndValues.indexOf('=');
    if (eq == -1) {
        throw new InvalidCommandException("no '=' found in: " + nameAndValues);
    }/*from w ww  . ja v a 2s .co m*/
    String name = nameAndValues.substring(0, eq);
    String values = nameAndValues.substring(eq + 1);

    if (multimap.containsKey(name)) {
        throw new InvalidCommandException("multiple parameter sets for: " + name);
    }
    multimap.putAll(name, split(values));
}

From source file:org.eigenbase.relopt.volcano.RuleQueue.java

void updateImportance(RelSubset subset, Double importance) {
    subsetImportances.put(subset, importance);

    for (PhaseMatchList matchList : matchListMap.values()) {
        Multimap<RelSubset, VolcanoRuleMatch> relMatchMap = matchList.matchMap;
        if (relMatchMap.containsKey(subset)) {
            for (VolcanoRuleMatch match : relMatchMap.get(subset)) {
                match.clearCachedImportance();
            }/* w  ww . ja  v  a2 s . c  o  m*/
        }
    }
}

From source file:com.github.scr.hashmap.sets.BufferCharSequenceSet.java

public BufferCharSequenceSet(@NotNull Set<? extends CharSequence> set, float loadFactor) {
    Objects.requireNonNull(set);/*w  ww . j  ava  2  s .  c o m*/
    if (loadFactor < 0f || loadFactor > 1f) {
        throw new IllegalArgumentException("loadFactor must be between 0 and 1");
    }

    SIZE = set.size();
    NUM_BUCKETS = (int) (SIZE / loadFactor) + 1;
    BUCKET_OFFSETS = IntBuffer.allocate(NUM_BUCKETS * 3);

    // Make Buckets
    AtomicInteger totalCharacters = new AtomicInteger(0);
    Multimap<Integer, CharSequence> buckets = HashMultimap.create();
    set.forEach(e -> {
        totalCharacters.addAndGet(e.length());
        int bucket = hashBucket(NUM_BUCKETS, e);
        buckets.put(bucket, e);
    });

    ELEMENTS = CharBuffer.allocate(totalCharacters.get() + (Character.BYTES * SIZE));

    int id = 0;
    int charOffset = 0;
    for (int i = 0; i < NUM_BUCKETS; ++i) {
        if (!buckets.containsKey(i)) {
            continue;
        }
        Collection<CharSequence> elements = buckets.get(i);
        int offsetIndex = i * 3;
        BUCKET_OFFSETS.put(offsetIndex++, id);
        BUCKET_OFFSETS.put(offsetIndex++, id += elements.size());
        BUCKET_OFFSETS.put(offsetIndex, charOffset);
        for (CharSequence element : elements) {
            int elementLength = element.length();
            if (elementLength > Character.MAX_VALUE) {
                throw new IllegalArgumentException("Size of string is too large to be described in a char.");
            }
            ELEMENTS.put(charOffset++, (char) elementLength);
            for (int j = 0; j < elementLength; ++j) {
                ELEMENTS.put(charOffset++, element.charAt(j));
            }
        }
    }
    LOGGER.debug("Finished initializing");
}

From source file:com.google.caliper.runner.options.ParsedOptions.java

private void addToMultimap(String nameAndValues, Multimap<String, String> multimap)
        throws InvalidCommandException {
    List<String> tokens = splitProperty(nameAndValues);
    String name = tokens.get(0);//w ww . ja va 2  s . c  o  m
    String values = tokens.get(1);

    if (multimap.containsKey(name)) {
        throw new InvalidCommandException("multiple parameter sets for: " + name);
    }
    multimap.putAll(name, split(values));
}

From source file:sf.net.experimaestro.manager.plans.Operator.java

/**
 * @param childrenMap/*w w w  . j  a  v a2 s . c  o m*/
 * @param needed
 * @return A collection of streams needed by this operator and its descendants
 */
private Collection<Operator> computeNeededStreams(Multimap<Operator, Operator> childrenMap,
        Multimap<Operator, Operator> needed) {
    if (needed.containsKey(this))
        return needed.get(this);

    Collection<Operator> streams = needed.get(this);
    Collection<Operator> children = childrenMap.get(this);

    // Add the needed streams from all children
    LOGGER.debug("Adding needed streams for %s", this);
    for (Operator child : children) {
        Collection<Operator> c = child.computeNeededStreams(childrenMap, needed);
        for (Operator op : c)
            // TODO: consider using the ancestors map to check if we need to add
            if (c != child)
                streams.add(op);
        child.addNeededStreams(streams);
    }

    return streams;
}

From source file:org.gradle.plugins.ide.internal.resolver.DefaultIdeDependencyResolver.java

private void findAllResolvedDependencyResultsAndTheirDependenciesAndRecordTheirParents(
        Multimap<ResolvedComponentResult, ResolvedComponentResult> parents, ResolvedComponentResult parent) {
    for (DependencyResult dependencyResult : parent.getDependencies()) {
        if (dependencyResult instanceof ResolvedDependencyResult) {
            ResolvedComponentResult child = ((ResolvedDependencyResult) dependencyResult).getSelected();
            // avoid circular dependencies by checking whether component result is already visited
            if (parents.containsKey(child)) {
                continue;
            }//from  w  ww .j  a  v a  2s. c  om
            recordParents(parents, parent, child);
            findAllResolvedDependencyResultsAndTheirDependenciesAndRecordTheirParents(parents, child);
        }
    }
}

From source file:io.redlink.sdk.impl.analysis.model.RDFStructureParser.java

private void setTopicAnnotationData(TopicAnnotation topicAnnotation, BindingSet result,
        RepositoryConnection conn, Multimap<Enhancement, String> relations) {

    if (!relations.containsKey(topicAnnotation)) {
        setEnhancementData(topicAnnotation, result);
        if (result.hasBinding("entityLabel")) {
            Binding entityLabel = result.getBinding("entityLabel");
            topicAnnotation.setTopicLabel(entityLabel.getValue().stringValue());
            if (!result.hasBinding("language") && (entityLabel.getValue() instanceof Literal))
                topicAnnotation.setLanguage(((Literal) entityLabel.getValue()).getLanguage());

        }/* w ww . j a  va 2  s  .c o m*/

        if (result.hasBinding("entityReference")) {
            topicAnnotation.setTopicReference(result.getBinding("entityReference").getValue().stringValue());
        }

        if (result.hasBinding("relation")) {
            String nextRelationUri = result.getBinding("relation").getValue().stringValue();
            relations.put(topicAnnotation, nextRelationUri);
        }

        if (result.hasBinding("site")) {
            topicAnnotation.setDataset(result.getBinding("site").getValue().stringValue());
        }
    } else {
        if (result.hasBinding("relation")) {
            final String nextRelationUri = result.getBinding("relation").getValue().stringValue();
            if (!relations.containsEntry(topicAnnotation, nextRelationUri))
                relations.put(topicAnnotation, nextRelationUri);
        }
    }
}