Example usage for com.google.common.collect SetMultimap get

List of usage examples for com.google.common.collect SetMultimap get

Introduction

In this page you can find the example usage for com.google.common.collect SetMultimap get.

Prototype

@Override
Set<V> get(@Nullable K key);

Source Link

Document

Because a SetMultimap has unique values for a given key, this method returns a Set , instead of the java.util.Collection specified in the Multimap interface.

Usage

From source file:org.robotframework.ide.eclipse.main.plugin.model.locators.KeywordDefinitionLocator.java

private ContinueDecision locateInLibraries(final RobotSuiteFile file, final KeywordDetector detector) {
    final SetMultimap<LibrarySpecification, String> librariesMap = file.getImportedLibraries();
    for (final LibrarySpecification libSpec : librariesMap.keySet()) {
        final List<KeywordSpecification> keywords = libSpec.getKeywords();
        for (final KeywordSpecification kwSpec : keywords) {
            final ContinueDecision shouldContinue = detector.libraryKeywordDetected(libSpec, kwSpec,
                    librariesMap.get(libSpec), file);
            if (shouldContinue == ContinueDecision.STOP) {
                return ContinueDecision.STOP;
            }//  w w  w.java 2  s. co  m
        }
    }
    return ContinueDecision.CONTINUE;
}

From source file:dagger2.internal.codegen.InjectProcessingStep.java

@Override
public void process(SetMultimap<Class<? extends Annotation>, Element> elementsByAnnotation) {
    // TODO(gak): add some error handling for bad source files
    final ImmutableSet.Builder<ProvisionBinding> provisions = ImmutableSet.builder();
    // TODO(gak): instead, we should collect reports by type and check later
    final ImmutableSet.Builder<DeclaredType> membersInjectedTypes = ImmutableSet.builder();

    for (Element injectElement : elementsByAnnotation.get(Inject.class)) {
        injectElement.accept(new ElementKindVisitor6<Void, Void>() {
            @Override//ww  w .  j a v  a  2s. com
            public Void visitExecutableAsConstructor(ExecutableElement constructorElement, Void v) {
                ValidationReport<ExecutableElement> report = constructorValidator.validate(constructorElement);

                report.printMessagesTo(messager);

                if (report.isClean()) {
                    provisions.add(provisionBindingFactory.forInjectConstructor(constructorElement,
                            Optional.<TypeMirror>absent()));
                }

                return null;
            }

            @Override
            public Void visitVariableAsField(VariableElement fieldElement, Void p) {
                ValidationReport<VariableElement> report = fieldValidator.validate(fieldElement);

                report.printMessagesTo(messager);

                if (report.isClean()) {
                    membersInjectedTypes.add(MoreTypes.asDeclared(fieldElement.getEnclosingElement().asType()));
                }

                return null;
            }

            @Override
            public Void visitExecutableAsMethod(ExecutableElement methodElement, Void p) {
                ValidationReport<ExecutableElement> report = methodValidator.validate(methodElement);

                report.printMessagesTo(messager);

                if (report.isClean()) {
                    membersInjectedTypes
                            .add(MoreTypes.asDeclared(methodElement.getEnclosingElement().asType()));
                }

                return null;
            }
        }, null);
    }

    for (DeclaredType injectedType : membersInjectedTypes.build()) {
        injectBindingRegistry.registerBinding(
                membersInjectionBindingFactory.forInjectedType(injectedType, Optional.<TypeMirror>absent()));
    }

    for (ProvisionBinding binding : provisions.build()) {
        injectBindingRegistry.registerBinding(binding);
    }
}

From source file:com.google.devtools.cyclefinder.ReferenceGraph.java

private void addSubtypeEdges() {
    SetMultimap<String, String> subtypes = HashMultimap.create();
    for (ITypeBinding type : allTypes.values()) {
        collectSubtypes(type.getKey(), type, subtypes);
    }/*from  w w  w  .j  ava2 s .  c  om*/
    for (String type : allTypes.keySet()) {
        for (Edge e : ImmutableList.copyOf(edges.get(type))) {
            Set<String> targetSubtypes = subtypes.get(e.getTarget().getKey());
            Set<String> whitelistKeys = Sets.newHashSet();
            IVariableBinding field = e.getField();
            for (String subtype : targetSubtypes) {
                ITypeBinding subtypeBinding = allTypes.get(subtype);
                if ((field != null && field.isField()
                        && whitelist.isWhitelistedTypeForField(field, subtypeBinding))
                        || whitelist.containsType(subtypeBinding)) {
                    whitelistKeys.add(subtype);
                    whitelistKeys.addAll(subtypes.get(subtype));
                }
            }
            for (String subtype : Sets.difference(targetSubtypes, whitelistKeys)) {
                addEdge(Edge.newSubtypeEdge(e, allTypes.get(subtype)));
            }
        }
    }
}

From source file:com.icosilune.fn.nodes.NodeGraph.java

private void propagateChanges(Set<AbstractNode> changedNodes, EvaluationContext context) {
    Set<AbstractNode> nodesToUpdate = changedNodes;

    Set<AbstractNode> updatedNodes = new HashSet();

    SetMultimap<AbstractNode, AbstractNode> downstreamConnections = getDownstreamConnections();

    // It is possible that we will have cycles in this graph,
    // so if there is a cycle, only update a node once.
    while (!nodesToUpdate.isEmpty()) {
        Set<AbstractNode> touchedNodes = new HashSet();

        for (AbstractNode node : nodesToUpdate) {
            node.evaluate(context);/*from  w w  w  . jav  a 2  s . c  o m*/
            touchedNodes.addAll(downstreamConnections.get(node));
        }

        updatedNodes.addAll(nodesToUpdate);
        touchedNodes.removeAll(updatedNodes);

        nodesToUpdate = touchedNodes;
    }
}

From source file:org.jetbrains.jet.lang.resolve.calls.smartcasts.DelegatingDataFlowInfo.java

@NotNull
@Override//  ww w .ja v  a  2  s . c  o m
public DataFlowInfo or(@NotNull DataFlowInfo otherInfo) {
    if (otherInfo == EMPTY)
        return EMPTY;
    if (this == EMPTY)
        return EMPTY;
    if (this == otherInfo)
        return this;

    assert otherInfo instanceof DelegatingDataFlowInfo : "Unknown DataFlowInfo type: " + otherInfo;
    DelegatingDataFlowInfo other = (DelegatingDataFlowInfo) otherInfo;

    Map<DataFlowValue, Nullability> nullabilityMapBuilder = Maps.newHashMap();
    for (Map.Entry<DataFlowValue, Nullability> entry : other.getCompleteNullabilityInfo().entrySet()) {
        DataFlowValue key = entry.getKey();
        Nullability otherFlags = entry.getValue();
        Nullability thisFlags = getNullability(key);
        nullabilityMapBuilder.put(key, thisFlags.or(otherFlags));
    }

    SetMultimap<DataFlowValue, JetType> myTypeInfo = getCompleteTypeInfo();
    SetMultimap<DataFlowValue, JetType> otherTypeInfo = other.getCompleteTypeInfo();
    SetMultimap<DataFlowValue, JetType> newTypeInfo = newTypeInfo();

    for (DataFlowValue key : Sets.intersection(myTypeInfo.keySet(), otherTypeInfo.keySet())) {
        Set<JetType> thisTypes = myTypeInfo.get(key);
        Set<JetType> otherTypes = otherTypeInfo.get(key);
        newTypeInfo.putAll(key, Sets.intersection(thisTypes, otherTypes));
    }

    if (nullabilityMapBuilder.isEmpty() && newTypeInfo.isEmpty()) {
        return EMPTY;
    }

    return new DelegatingDataFlowInfo(null, ImmutableMap.copyOf(nullabilityMapBuilder), newTypeInfo);
}

From source file:com.palantir.atlasdb.keyvalue.impl.TableSplittingKeyValueService.java

@Override
public void truncateTables(Set<String> tableNames) {
    SetMultimap<KeyValueService, String> tablesToTruncateByKvs = HashMultimap.create();
    for (String tableName : tableNames) {
        tablesToTruncateByKvs.put(getDelegate(tableName), tableName);
    }//from w ww  . ja va 2s  .c o  m
    for (KeyValueService kvs : tablesToTruncateByKvs.keySet()) {
        kvs.truncateTables(tablesToTruncateByKvs.get(kvs));
    }
}

From source file:eu.esdihumboldt.hale.ui.cst.debug.metadata.internal.TreeGraphMLProvider.java

/**
 * @see eu.esdihumboldt.hale.ui.cst.debug.metadata.internal.TreeGraphProvider#generateGraph()
 *//*from  w ww .j  av  a  2s  .  co m*/
@Override
public Graph generateGraph() {

    tree.accept(graphVisitor);

    SetMultimap<String, String> connections = graphVisitor.getAllConnections();
    Set<String> ids = graphVisitor.getAllIds();

    TinkerGraph graph = new TinkerGraph();

    // add nodes to the graph
    for (String key : ids) {
        TransformationNode node = graphVisitor.getNode(key);
        Vertex vertex = graph.addVertex(key);
        setVertexProperty(node, vertex);
    }

    for (String key : connections.keySet()) {
        for (String value : connections.get(key)) {
            graph.addEdge(null, graph.getVertex(key), graph.getVertex(value), " ");
        }
    }
    return graph;
}

From source file:com.android.build.gradle.shrinker.IncrementalShrinker.java

/**
 * Decides which classes need to be updated on disk and which need to be deleted. It puts
 * appropriate entries in the lists passed as arguments.
 */// ww w. j  a v  a2 s  .  c o  m
private void chooseClassesToWrite(@NonNull Iterable<TransformInput> inputs,
        @NonNull TransformOutputProvider output, @NonNull Collection<T> classesToWrite,
        @NonNull Collection<File> classFilesToDelete, @NonNull SetMultimap<T, String> oldState) {
    for (T klass : mGraph.getReachableClasses(CounterSet.SHRINK)) {
        if (!oldState.containsKey(klass)) {
            classesToWrite.add(klass);
        } else {
            Set<String> newMembers = mGraph.getReachableMembersLocalNames(klass, CounterSet.SHRINK);
            Set<String> oldMembers = oldState.get(klass);

            // Reverse of the trick above, where we store one artificial member for empty
            // classes.
            if (oldMembers.size() == 1) {
                oldMembers.remove(mGraph.getClassName(klass));
            }

            if (!newMembers.equals(oldMembers)) {
                classesToWrite.add(klass);
            }
        }

        oldState.removeAll(klass);
    }

    // All keys that remained in oldState should be deleted.
    for (T klass : oldState.keySet()) {
        File sourceFile = mGraph.getSourceFile(klass);
        checkState(sourceFile != null, "One of the inputs has no source file.");

        Optional<File> outputFile = chooseOutputFile(klass, sourceFile, inputs, output);
        if (!outputFile.isPresent()) {
            throw new IllegalStateException("Can't determine path of " + mGraph.getClassName(klass));
        }
        classFilesToDelete.add(outputFile.get());
    }
}

From source file:org.grouplens.lenskit.eval.traintest.JobGraphBuilder.java

private void addSharedNodeDependencies(DAGNode<Component, Dependency> graph,
        DAGNodeBuilder<JobGraph.Node, JobGraph.Edge> builder) {
    logger.debug("scanning for dependencies of {}", builder.getLabel());
    SetMultimap<DAGNode<JobGraph.Node, JobGraph.Edge>, DAGNode<Component, Dependency>> edges;
    edges = HashMultimap.create();/*from  w w w. ja  v a  2 s .  c o  m*/
    for (DAGNode<Component, Dependency> node : graph.getReachableNodes()) {
        if (seenNodes.containsKey(node)) {
            edges.put(seenNodes.get(node), node);
        }
    }
    for (DAGNode<JobGraph.Node, JobGraph.Edge> dep : edges.keySet()) {
        if (logger.isDebugEnabled()) {
            logger.debug("depends on {} for {} nodes", dep, edges.get(dep).size());
            for (DAGNode<Component, Dependency> shared : edges.get(dep)) {
                logger.debug("reuses {}", shared);
            }
        }
        builder.addEdge(dep, JobGraph.edge(edges.get(dep)));
    }
}

From source file:tiger.ComponentGeneratorProcessor.java

/**
 * Checks if there are duplicated bindings for the a key.
 *///from  w ww . j  a  va  2 s  . c o m
private void checkDuplicateBindings(Collection<NewDependencyInfo> deps) {
    SetMultimap<NewBindingKey, NewDependencyInfo> map = NewDependencyCollector.collectionToMultimap(deps);
    for (NewBindingKey key : map.keySet()) {
        Set<NewDependencyInfo> dependencies = map.get(key);
        if (dependencies.size() == 1) {
            continue;
        }
        for (NewDependencyInfo info : dependencies) {
            if (info.isUnique()) {
                messager.printMessage(Kind.ERROR,
                        String.format(
                                "Key %s has multiple bindings including unique type one(s). Bindings found: %s",
                                key, dependencies));
                break;
            }
        }
    }
}