Example usage for com.google.common.collect HashMultimap create

List of usage examples for com.google.common.collect HashMultimap create

Introduction

In this page you can find the example usage for com.google.common.collect HashMultimap create.

Prototype

public static <K, V> HashMultimap<K, V> create() 

Source Link

Document

Creates a new, empty HashMultimap with the default initial capacities.

Usage

From source file:com.android.tools.idea.navigator.nodes.AndroidResFolderNode.java

/**
 * Returns the children of the res folder. Rather than showing the existing directory hierarchy, this merges together
 * all the folders by their {@link com.android.resources.ResourceFolderType}.
 *///w w  w  .j  a v  a  2 s  .  c o m
@NotNull
@Override
public Collection<? extends AbstractTreeNode> getChildren() {
    // collect all res folders from all source providers
    List<PsiDirectory> resFolders = Lists.newArrayList();
    for (PsiDirectory directory : getSourceDirectories()) {
        resFolders.addAll(Lists.newArrayList(directory.getSubdirectories()));
    }

    // group all the res folders by their folder type
    HashMultimap<ResourceFolderType, PsiDirectory> foldersByResourceType = HashMultimap.create();
    for (PsiDirectory resFolder : resFolders) {
        ResourceFolderType type = ResourceFolderType.getFolderType(resFolder.getName());
        if (type == null) {
            // skip unknown folder types inside res
            continue;
        }
        foldersByResourceType.put(type, resFolder);
    }

    // create a node for each res folder type that actually has some resources
    AndroidProjectTreeBuilder treeBuilder = (AndroidProjectTreeBuilder) myProjectViewPane.getTreeBuilder();
    List<AbstractTreeNode> children = Lists.newArrayListWithExpectedSize(foldersByResourceType.size());
    for (ResourceFolderType type : foldersByResourceType.keySet()) {
        Set<PsiDirectory> folders = foldersByResourceType.get(type);
        final AndroidResFolderTypeNode androidResFolderTypeNode = new AndroidResFolderTypeNode(myProject,
                getValue(), Lists.newArrayList(folders), getSettings(), type, myProjectViewPane);
        children.add(androidResFolderTypeNode);

        // Inform the tree builder of the node that this particular virtual file maps to
        for (PsiDirectory folder : folders) {
            treeBuilder.createMapping(folder.getVirtualFile(), androidResFolderTypeNode);
        }
    }
    return children;

}

From source file:org.eclipse.viatra.transformation.evm.api.RuleSpecification.java

/**
 * Creates a specification with the given life-cycle and job set.
 * //w ww  .  j  a v  a 2s  . co  m
 * @param lifeCycle
 * @param jobs
 */
public RuleSpecification(final EventSourceSpecification<EventAtom> sourceSpecification,
        final ActivationLifeCycle lifeCycle, final Set<Job<EventAtom>> jobs) {
    checkArgument(sourceSpecification != null, "Cannot create rule specification with null source definition!");
    this.sourceSpecification = sourceSpecification;
    this.lifeCycle = ActivationLifeCycle.copyOf(lifeCycle);
    this.jobs = HashMultimap.create();
    Set<ActivationState> states = new TreeSet<ActivationState>();
    if (jobs != null && !jobs.isEmpty()) {
        for (Job<EventAtom> job : jobs) {
            ActivationState state = job.getActivationState();
            this.jobs.put(state, job);
            states.add(state);
        }
    }
    this.enabledStates = ImmutableSet.copyOf(states);
}

From source file:com.enonic.cms.store.dao.ResourceUsageDaoImpl.java

private Multimap<ResourceKey, ResourceReferencer> getUsedBySites(final ResourceKey resourceKey) {
    Multimap<ResourceKey, ResourceReferencer> usedBy = HashMultimap.create();

    final List<SiteEntity> sites = siteDao.findAll();

    for (SiteEntity site : sites) {
        ResourceKey defaultCssKey = site.getDefaultCssKey();
        if (defaultCssKey != null && defaultCssKey.equals(resourceKey)) {
            usedBy.put(resourceKey, new ResourceReferencer(site, ResourceReferencerType.SITE_DEFAULT_CSS));
        }//w  w w .  j ava2s  .  co m

        ResourceKey defaultLocalizationResource = site.getDefaultLocalizationResource();
        if (defaultLocalizationResource != null && defaultLocalizationResource.equals(resourceKey)) {
            usedBy.put(resourceKey,
                    new ResourceReferencer(site, ResourceReferencerType.SITE_DEFAULT_LOCALIZATION_RESOURCE));
        }

        ResourceKey deviceClassResolver = site.getDeviceClassResolver();
        if (deviceClassResolver != null && deviceClassResolver.equals(resourceKey)) {
            usedBy.put(resourceKey,
                    new ResourceReferencer(site, ResourceReferencerType.SITE_DEVICE_CLASS_RESOLVER));
        }

        ResourceKey localeResolver = site.getLocaleResolver();
        if (localeResolver != null && localeResolver.equals(resourceKey)) {
            usedBy.put(resourceKey, new ResourceReferencer(site, ResourceReferencerType.SITE_LOCALE_RESOLVER));
        }
    }

    return usedBy;
}

From source file:com.facebook.buck.graph.MutableDirectedGraph.java

/**
 * Creates a new graph with no nodes or edges.
 *//*from   w  w  w.  java 2 s  .  c  o m*/
public MutableDirectedGraph() {
    this.nodes = Sets.newHashSet();
    this.outgoingEdges = HashMultimap.create();
    this.incomingEdges = HashMultimap.create();
}

From source file:org.projectreactor.bench.collection.CacheBenchmarks.java

@SuppressWarnings("unchecked")
@Setup/*from  w w  w  . j a va2  s .  co  m*/
public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
    random = new Random(System.nanoTime());
    index = 0;
    randomKeys = new int[length];
    objs = new Object[length];

    intMap = new ConcurrentHashMap<>();
    gsMap = FastListMultimap.newMultimap();
    guavaMap = HashMultimap.create();

    for (int i = 0; i < length; i++) {
        final int hashCode = i;
        Object obj = new Object() {
            @Override
            public int hashCode() {
                return hashCode;
            }
        };
        objs[i] = obj;

        randomKeys[i] = random.nextInt(length);
        List<Object> objs = new ArrayList<>();
        for (int j = 0; j < 100; j++) {
            objs.add(obj);
        }
        intMap.put(i, objs);
        gsMap.put(i, objs);
        guavaMap.putAll(i, objs);
    }
}

From source file:com.android.tools.idea.gradle.structure.configurables.android.dependencies.project.treeview.TargetModulesTreeStructure.java

void displayTargetModules(
        @NotNull List<AbstractDependencyNode<? extends PsAndroidDependency>> dependencyNodes) {
    // Key: module name, Value: pair of module and version of the dependency used in the module.
    Map<String, Pair<PsAndroidModule, String>> modules = Maps.newHashMap();

    // Key: module name, Value: configuration names.
    Multimap<String, Configuration> configurationNamesByModule = HashMultimap.create();

    // From the list of AbstractDependencyNode:
    //  1. Extract modules (to show them as top-level nodes)
    //  2. Extract variants/artifact (i.e. PsDependencyContainer) per module (to show them as children nodes of the module nodes)
    dependencyNodes.forEach(node -> {
        List<AbstractDependencyNode<? extends PsAndroidDependency>> declaredDependencyNodes = getDeclaredDependencyNodeHierarchy(
                node);//from   ww w  .  j  av a 2  s  . co  m

        // Create the module and version used.
        Map<String, String> versionByModule = Maps.newHashMap();
        for (PsAndroidDependency dependency : node.getModels()) {
            if (dependency instanceof PsLibraryAndroidDependency) {
                PsLibraryAndroidDependency libraryDependency = (PsLibraryAndroidDependency) dependency;
                PsArtifactDependencySpec spec = libraryDependency.getDeclaredSpec();
                if (spec == null) {
                    spec = libraryDependency.getResolvedSpec();
                }
                // For library dependencies we display the version of the library being used.
                PsAndroidModule module = dependency.getParent();
                versionByModule.put(module.getName(), spec.version);
            }
        }

        AbstractDependencyNode<? extends PsAndroidDependency> topParentNode = declaredDependencyNodes
                .get(declaredDependencyNodes.size() - 1);
        for (PsAndroidDependency dependency : topParentNode.getModels()) {
            PsAndroidModule module = dependency.getParent();
            String moduleName = module.getName();
            Pair<PsAndroidModule, String> existing = modules.get(moduleName);
            if (existing == null) {
                modules.put(moduleName, Pair.create(module, versionByModule.get(moduleName)));
            }
        }

        declaredDependencyNodes.forEach(declaredDependencyNode -> {
            List<PsAndroidDependency> declaredDependencies = getDeclaredDependencies(declaredDependencyNode);

            declaredDependencies.forEach(declaredDependency -> {
                List<String> configurationNames = declaredDependency.getConfigurationNames();
                assert !configurationNames.isEmpty();
                PsAndroidModule module = declaredDependency.getParent();
                String moduleName = module.getName();

                for (PsDependencyContainer container : declaredDependency.getContainers()) {
                    PsAndroidArtifact artifact = container.findArtifact(module, false);

                    for (String configurationName : configurationNames) {
                        if (artifact != null && artifact.containsConfigurationName(configurationName)) {
                            boolean transitive = declaredDependencyNode != node;

                            Collection<Configuration> configurations = configurationNamesByModule
                                    .get(moduleName);
                            boolean found = false;
                            for (Configuration configuration : configurations) {
                                if (configuration.getName().equals(configurationName)) {
                                    configuration.addType(transitive);
                                    found = true;
                                    break;
                                }
                            }

                            if (!found) {
                                Icon icon = artifact.getIcon();
                                configurationNamesByModule.put(moduleName,
                                        new Configuration(configurationName, icon, transitive));
                            }
                        }
                    }
                }
            });
        });
    });

    // Now we create the tree nodes.
    List<TargetAndroidModuleNode> children = Lists.newArrayList();

    for (Pair<PsAndroidModule, String> moduleAndVersion : modules.values()) {
        PsAndroidModule module = moduleAndVersion.getFirst();
        TargetAndroidModuleNode moduleNode = new TargetAndroidModuleNode(myRootNode, module,
                moduleAndVersion.getSecond());

        List<Configuration> configurations = Lists
                .newArrayList(configurationNamesByModule.get(module.getName()));
        Collections.sort(configurations);

        List<TargetConfigurationNode> nodes = Lists.newArrayList();
        configurations.forEach(configuration -> nodes.add(new TargetConfigurationNode(configuration)));

        moduleNode.setChildren(nodes);
        children.add(moduleNode);
    }

    Collections.sort(children, new SimpleNodeComparator<>());
    myRootNode.setChildren(children);
}

From source file:pt.ua.tm.neji.evaluation.IDConverter.java

private Multimap<String, String> loadCUI2GO() {
    String filePath = mappersFolderPath + "GO_CUI_mapping_db.txt";

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

    try (FileInputStream fis = new FileInputStream(filePath);
            InputStreamReader isr = new InputStreamReader(fis);) {
        BufferedReader br = new BufferedReader(isr);
        String line;/*from w w  w.j a v  a  2 s.c  om*/

        while ((line = br.readLine()) != null) {
            String parts[] = line.split("\t");
            String go = parts[0];
            String cui = "UMLS:" + parts[1];

            map.put(cui, go);
        }

    } catch (IOException ex) {
        throw new RuntimeException("There was a problem loading the ID mapper file: " + filePath, ex);
    }

    return map;
}

From source file:edu.cmu.lti.oaqa.baseqa.answer.score.scorers.TypeCoercionAnswerScorer.java

@Override
public void prepare(JCas jcas) throws AnalysisEngineProcessException {
    offset2ctypes = HashMultimap.create();
    for (Concept concept : TypeUtil.getConcepts(jcas)) {
        Set<String> ctypes = TypeUtil.getConceptTypes(concept).stream().map(ConceptType::getAbbreviation)
                .collect(toSet());/*  w ww .ja  v  a 2 s. c o m*/
        for (ConceptMention cmention : TypeUtil.getConceptMentions(concept))
            offset2ctypes.putAll(TypeUtil.annotationOffset(cmention), ctypes);
    }
    ats = TypeUtil.getLexicalAnswerTypes(jcas).stream().map(LexicalAnswerType::getLabel).collect(toList());
}

From source file:at.sti2.spark.core.collect.IndexStructure.java

public IndexStructure() {
    this.subjectIndexing = false;
    this.predicateIndexing = false;
    this.objectIndexing = false;
    this.windowInMillis = 0;

    subjectMap = HashMultimap.create();
    predicateMap = HashMultimap.create();
    objectMap = HashMultimap.create();/*from w  w  w. j a va  2 s.co  m*/

    tokenList = new ArrayList<Value>();
    expireTokenQueue = new ConcurrentLinkedQueue<TTLEntrySingle<Value>>();

    expireSubjectQueue = new ConcurrentLinkedQueue<TTLEntry<RDFValue, Value>>();
    expirePredicateQueue = new ConcurrentLinkedQueue<TTLEntry<RDFValue, Value>>();
    expireObjectQueue = new ConcurrentLinkedQueue<TTLEntry<RDFValue, Value>>();
}

From source file:org.smartloli.kafka.eagle.core.sql.schema.JSqlSchema.java

@Override
protected Multimap<String, Function> getFunctionMultimap() {
    ImmutableMultimap<String, ScalarFunction> funcs = ScalarFunctionImpl.createAll(JSONFunction.class);
    Multimap<String, Function> functions = HashMultimap.create();
    for (String key : funcs.keySet()) {
        for (ScalarFunction func : funcs.get(key)) {
            functions.put(key, func);//from   ww  w .ja  v  a2 s .  com
        }
    }
    return functions;
}