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:org.onosproject.net.intent.impl.compiler.LinkCollectionIntentCompiler.java

@Override
public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable,
        Set<LinkResourceAllocations> resources) {
    SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create();
    SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();

    for (Link link : intent.links()) {
        inputPorts.put(link.dst().deviceId(), link.dst().port());
        outputPorts.put(link.src().deviceId(), link.src().port());
    }//from   ww w  .jav a 2  s .  co m

    for (ConnectPoint ingressPoint : intent.ingressPoints()) {
        inputPorts.put(ingressPoint.deviceId(), ingressPoint.port());
    }

    for (ConnectPoint egressPoint : intent.egressPoints()) {
        outputPorts.put(egressPoint.deviceId(), egressPoint.port());
    }

    List<FlowRule> rules = new ArrayList<>();
    for (DeviceId deviceId : outputPorts.keys()) {
        rules.addAll(createRules(intent, deviceId, inputPorts.get(deviceId), outputPorts.get(deviceId)));
    }
    return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources()));
}

From source file:com.google.devtools.build.lib.query2.output.ConditionalEdges.java

/** Inserts `conditions` for edge src --> dest. */
public void insert(Label src, Label dest, Set<Label> conditions) {
    map.computeIfAbsent(src, (k) -> HashMultimap.create());
    map.get(src).putAll(dest, conditions);
}

From source file:org.artifactory.maven.MavenPluginsMetadataCalculator.java

/**
 * Calculate maven metadata using folder as the base.
 *
 * @param localRepo Base folder to start calculating from.
 *//*w ww.  j a  v  a 2  s  . co  m*/
public void calculate(LocalRepo localRepo) {
    if (!localRepo.isLocal() || localRepo.isCache()) {
        log.warn("Maven metadata calculation is allowed only on local non-cache repositories");
        return;
    }

    log.debug("Calculating maven plugins metadata on repo '{}'", localRepo.getKey());
    FileService fileService = ContextHelper.get().beanForType(FileService.class);
    List<FileInfo> pluginPoms = fileService.searchFilesByProperty(localRepo.getKey(),
            PropertiesService.MAVEN_PLUGIN_PROPERTY_NAME, Boolean.TRUE.toString());
    log.debug("{} plugin poms found", pluginPoms.size());

    // aggregate one pom for each plugin under the plugins metadata container
    HashMultimap<RepoPath, RepoPath> pluginsMetadataContainers = HashMultimap.create();
    for (FileInfo pom : pluginPoms) {
        // great-grandparent is the plugins metadata container
        // eg, if the plugin pom is org/jfrog/maven/plugins/maven-test-plugin/1.0/maven-test-plugin-1.0.pom
        // the node that contains the plugins metadata is org/jfrog/maven/plugins
        RepoPath pluginsMetadataContainer = RepoPathUtils.getAncestor(pom.getRepoPath(), 3);
        if (pluginsMetadataContainer != null) {
            pluginsMetadataContainers.put(pluginsMetadataContainer, pom.getRepoPath());
        } else {
            log.info("Found plugin pom without maven GAV path: '{}'. Ignoring...", pom.getRepoPath());
        }
    }

    // for each plugins folder container, create plugins metadata on the parent
    Set<RepoPath> folders = pluginsMetadataContainers.keySet();
    for (RepoPath pluginsMetadataContainer : folders) {
        //Metadata metadata = getOrCreatePluginMetadata(pluginsMetadataContainer);
        Metadata metadata = new Metadata();
        for (RepoPath pomFile : pluginsMetadataContainers.get(pluginsMetadataContainer)) {
            String artifactId = RepoPathUtils.getAncestor(pomFile, 2).getName();
            if (hasPlugin(metadata, artifactId)) {
                continue;
            }

            // extract the plugin details and add to the metadata
            String pomStr = getRepositoryService().getStringContent(pomFile);
            Model pomModel = MavenModelUtils.stringToMavenModel(pomStr);
            artifactId = pomModel.getArtifactId();
            Plugin plugin = new Plugin();
            plugin.setArtifactId(artifactId);
            plugin.setPrefix(PluginDescriptor.getGoalPrefixFromArtifactId(pomModel.getArtifactId()));
            String pluginName = pomModel.getName();
            if (StringUtils.isBlank(pluginName)) {
                pluginName = "Unnamed - " + pomModel.getId();
            }
            plugin.setName(pluginName);
            metadata.addPlugin(plugin);
        }

        // save only if something changed
        if (modified(getPluginMetadata(pluginsMetadataContainer), metadata)) {
            saveMetadata(pluginsMetadataContainer, metadata);
        }
    }
    log.debug("Finished maven plugins metadata calculation on '{}'", localRepo.getKey());
}

From source file:com.google.javascript.jscomp.deps.ClosureSortedDependencies.java

public ClosureSortedDependencies(List<INPUT> inputs) throws CircularDependencyException {
    this.inputs = new ArrayList<>(inputs);
    noProvides = new ArrayList<>();

    // Collect all symbols provided in these files.
    for (INPUT input : inputs) {
        Collection<String> currentProvides = input.getProvides();
        if (currentProvides.isEmpty()) {
            noProvides.add(input);/*www . j a v  a 2 s  . c  o  m*/
        }

        for (String provide : currentProvides) {
            provideMap.put(provide, input);
        }
    }

    // Get the direct dependencies.
    final Multimap<INPUT, INPUT> deps = HashMultimap.create();
    for (INPUT input : inputs) {
        for (String req : input.getRequires()) {
            INPUT dep = provideMap.get(req);
            if (dep != null && dep != input) {
                deps.put(input, dep);
            }
        }
    }

    // Sort the inputs by sucking in 0-in-degree nodes until we're done.
    sortedList = topologicalStableSort(inputs, deps);

    // The dependency graph of inputs has a cycle iff sortedList is a proper
    // subset of inputs. Also, it has a cycle iff the subgraph
    // (inputs - sortedList) has a cycle. It's fairly easy to prove this
    // by the lemma that a graph has a cycle iff it has a subgraph where
    // no nodes have out-degree 0. I'll leave the proof of this as an exercise
    // to the reader.
    if (sortedList.size() < inputs.size()) {
        List<INPUT> subGraph = new ArrayList<>(inputs);
        subGraph.removeAll(sortedList);

        throw new CircularDependencyException(cycleToString(findCycle(subGraph, deps)));
    }
}

From source file:matteroverdrive.items.android.BionicPart.java

public Multimap<String, AttributeModifier> getModifiers(AndroidPlayer player, ItemStack itemStack) {
    Multimap multimap = HashMultimap.create();
    loadCustomAttributes(itemStack, multimap);
    return multimap;
}

From source file:edu.uci.ics.sourcerer.tools.java.component.identifier.internal.ComponentRepositoryBuilder.java

private ComponentRepositoryBuilder(JarCollection jars, ClusterCollection clusters) {
    this.task = TaskProgressLogger.get();

    this.jars = jars;
    this.clusters = clusters;

    this.jarsToClusters = HashMultimap.create();

    this.repo = ComponentRepository.create(jars, clusters);
}

From source file:org.lanternpowered.server.world.chunk.LanternLoadingTicketIO.java

static void save(Path worldFolder, Set<LanternLoadingTicket> tickets) throws IOException {
    final Path file = worldFolder.resolve(TICKETS_FILE);
    if (!Files.exists(file)) {
        Files.createFile(file);/*from   w  ww .  j ava2  s.c o  m*/
    }

    final Multimap<String, LanternLoadingTicket> sortedByPlugin = HashMultimap.create();
    for (LanternLoadingTicket ticket : tickets) {
        sortedByPlugin.put(ticket.getPlugin(), ticket);
    }

    final List<DataView> ticketHolders = new ArrayList<>();
    for (Entry<String, Collection<LanternLoadingTicket>> entry : sortedByPlugin.asMap().entrySet()) {
        final Collection<LanternLoadingTicket> tickets0 = entry.getValue();

        final List<DataView> ticketEntries = new ArrayList<>();
        for (LanternLoadingTicket ticket0 : tickets0) {
            final DataContainer ticketData = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
            ticketData.set(TICKET_TYPE, ticket0 instanceof EntityLoadingTicket ? TYPE_ENTITY : TYPE_NORMAL);
            final int numChunks = ticket0.getNumChunks();
            // Store the list depth for backwards compatible or something,
            // the current forge version doesn't use it either
            ticketData.set(CHUNK_LIST_DEPTH, (byte) Math.min(numChunks, 127));
            // Storing the chunks number, this number is added by us
            ticketData.set(CHUNK_NUMBER, numChunks);
            if (ticket0 instanceof PlayerLoadingTicket) {
                final PlayerLoadingTicket ticket1 = (PlayerLoadingTicket) ticket0;
                // This is a bit strange, since it already added,
                // but if forge uses it...
                ticketData.set(MOD_ID, entry.getKey());
                ticketData.set(PLAYER_UUID, ticket1.getPlayerUniqueId().toString());
            }
            if (ticket0.extraData != null) {
                ticketData.set(MOD_DATA, ticket0.extraData);
            }
            if (ticket0 instanceof EntityChunkLoadingTicket) {
                final EntityChunkLoadingTicket ticket1 = (EntityChunkLoadingTicket) ticket0;
                ticket1.getOrCreateEntityReference().ifPresent(ref -> {
                    final Vector2i position = ref.getChunkCoords();
                    final UUID uniqueId = ref.getUniqueId();
                    ticketData.set(CHUNK_X, position.getX());
                    ticketData.set(CHUNK_Z, position.getY());
                    ticketData.set(ENTITY_UUID_MOST, uniqueId.getMostSignificantBits());
                    ticketData.set(ENTITY_UUID_LEAST, uniqueId.getLeastSignificantBits());
                });
            }
            ticketEntries.add(ticketData);
        }

        ticketHolders.add(DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED)
                .set(HOLDER_NAME, entry.getKey()).set(TICKETS, ticketEntries));
    }

    final DataContainer dataContainer = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED)
            .set(HOLDER_LIST, ticketHolders);
    NbtStreamUtils.write(dataContainer, Files.newOutputStream(file), true);
}

From source file:com.zimbra.cs.db.DbPendingAclPush.java

public static Multimap<Integer, Integer> getEntries(Date uptoTime) throws ServiceException {
    Multimap<Integer, Integer> mboxIdToItemIds = HashMultimap.create();
    DbConnection conn = null;/*from w w  w .  j  av  a  2s . c om*/
    PreparedStatement stmt = null;
    ResultSet rs = null;
    ZimbraLog.misc.debug("Getting entries recorded before %s for ACL push", uptoTime);
    try {
        conn = DbPool.getConnection();
        stmt = conn.prepareStatement(
                "SELECT mailbox_id, item_id FROM " + TABLE_PENDING_ACL_PUSH + " WHERE date < ?");
        stmt.setLong(1, uptoTime.getTime());
        rs = stmt.executeQuery();
        while (rs.next()) {
            mboxIdToItemIds.put(rs.getInt(1), rs.getInt(2));
        }
    } catch (SQLException e) {
        throw ServiceException.FAILURE("Unable to get entries recorded before " + uptoTime + " for ACL push",
                e);
    } finally {
        DbPool.closeResults(rs);
        DbPool.closeStatement(stmt);
        DbPool.quietClose(conn);
    }
    return mboxIdToItemIds;
}

From source file:org.sosy_lab.cpachecker.core.algorithm.invariants.LazyLocationMapping.java

public Iterable<AbstractState> get0(CFANode pLocation) {
    if (reachedSet instanceof LocationMappedReachedSet) {
        return AbstractStates.filterLocation(reachedSet, pLocation);
    }//from   w  w w  . jav a 2s . c  o m
    if (statesByLocationRef.get() == null) {
        Multimap<CFANode, AbstractState> statesByLocation = HashMultimap.create();
        for (AbstractState state : reachedSet) {
            for (CFANode location : AbstractStates.extractLocations(state)) {
                statesByLocation.put(location, state);
            }
        }
        this.statesByLocationRef.set(statesByLocation);
        return statesByLocation.get(pLocation);
    }
    return statesByLocationRef.get().get(pLocation);
}

From source file:org.overlord.rtgov.ui.client.local.pages.AbstractPage.java

/**
 * Creates an href to a page.// ww  w.j  a va2s .co  m
 *
 * @param pageName
 * @param stateKey
 * @param stateValue
 */
protected String createPageHref(String pageName, String stateKey, String stateValue) {
    Multimap<String, String> state = HashMultimap.create();
    state.put(stateKey, stateValue);
    return createPageHref(pageName, state);
}