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

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

Introduction

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

Prototype

Collection<Map.Entry<K, V>> entries();

Source Link

Document

Returns a view collection of all key-value pairs contained in this multimap, as Map.Entry instances.

Usage

From source file:com.spotify.helios.client.HeliosClient.java

private URI uri(final String path, final Multimap<String, String> query) {
    checkArgument(path.startsWith("/"));

    final URIBuilder builder = new URIBuilder().setScheme("http").setHost("helios").setPath(path);
    for (final Map.Entry<String, String> q : query.entries()) {
        builder.addParameter(q.getKey(), q.getValue());
    }/*from  www .  ja  v  a  2s  .  co m*/
    builder.addParameter("user", user);

    try {
        return builder.build();
    } catch (URISyntaxException e) {
        throw Throwables.propagate(e);
    }
}

From source file:com.palantir.atlasdb.keyvalue.rocksdb.impl.RocksDbKeyValueService.java

@Override
public void putWithTimestamps(String tableName, Multimap<Cell, Value> cellValues) {
    try (Disposer d = new Disposer(); ColumnFamily table = columnFamilies.get(tableName)) {
        WriteOptions options = d.register(new WriteOptions().setSync(writeOptions.fsyncPut()));
        WriteBatch batch = d.register(new WriteBatch());
        for (Entry<Cell, Value> entry : cellValues.entries()) {
            Value value = entry.getValue();
            byte[] key = RocksDbKeyValueServices.getKey(entry.getKey(), value.getTimestamp());
            batch.put(table.getHandle(), key, value.getContents());
        }//from   www . j a  v a2s .  c o  m
        getDb().write(options, batch);
    } catch (RocksDBException e) {
        throw Throwables.propagate(e);
    }
}

From source file:eu.interedition.text.rdbms.RelationalAnnotationLinkRepository.java

public Map<AnnotationLink, Set<Annotation>> create(Multimap<Name, Set<Annotation>> links) {
    final Map<Name, Long> nameIdIndex = Maps.newHashMap();
    for (Name n : nameRepository.get(links.keySet())) {
        nameIdIndex.put(n, ((RelationalName) n).getId());
    }/*w  ww. j  a  v a  2s.  c  o  m*/

    final Map<AnnotationLink, Set<Annotation>> created = Maps.newLinkedHashMap();
    final List<SqlParameterSource> linkBatch = Lists.newArrayList();
    final List<SqlParameterSource> targetBatch = Lists.newArrayList();

    for (Map.Entry<Name, Set<Annotation>> link : links.entries()) {
        final Name linkName = link.getKey();
        final Set<Annotation> targets = link.getValue();

        final Long nameId = nameIdIndex.get(linkName);
        final long linkId = annotationLinkIdIncrementer.nextLongValue();

        linkBatch.add(new MapSqlParameterSource().addValue("id", linkId).addValue("name", nameId));

        for (Annotation target : targets) {
            targetBatch.add(new MapSqlParameterSource().addValue("link", linkId).addValue("target",
                    ((RelationalAnnotation) target).getId()));
        }

        created.put(new RelationalAnnotationLink(new RelationalName(linkName, nameId), linkId), targets);
    }

    annotationLinkInsert.executeBatch(linkBatch.toArray(new SqlParameterSource[linkBatch.size()]));
    annotationLinkTargetInsert.executeBatch(targetBatch.toArray(new SqlParameterSource[targetBatch.size()]));

    return created;
}

From source file:com.palantir.atlasdb.keyvalue.rdbms.PostgresKeyValueService.java

private void deleteInTransaction(final String tableName, final Multimap<Cell, Long> keys, final Handle handle) {
    batch(keys.entries(), new Function<Collection<Entry<Cell, Long>>, Void>() {
        @Override/*w  w  w  . j  av  a  2s  . co  m*/
        @Nullable
        public Void apply(@Nullable Collection<Entry<Cell, Long>> input) {
            deleteInternalInTransaction(tableName, input, handle);
            return null;
        }
    });
}

From source file:com.google.devtools.build.lib.pkgcache.LegacyLoadingPhaseRunner.java

private ImmutableSet<Target> filterErrorFreeTargets(EventHandler eventHandler, EventBus eventBus,
        TransitivePackageLoader pkgLoader, Collection<Target> targetsToLoad,
        ListMultimap<String, Label> labelsToLoadUnconditionally) throws LoadingFailedException {
    // Error out if any of the labels needed for the configuration could not be loaded.
    Multimap<Label, Label> rootCauses = pkgLoader.getRootCauses();
    for (Map.Entry<String, Label> entry : labelsToLoadUnconditionally.entries()) {
        if (rootCauses.containsKey(entry.getValue())) {
            throw new LoadingFailedException(
                    "Failed to load required " + entry.getKey() + " target: '" + entry.getValue() + "'");
        }//  ww  w.  j  a  v a  2s . co  m
    }

    // Post root causes for command-line targets that could not be loaded.
    for (Map.Entry<Label, Label> entry : rootCauses.entries()) {
        eventBus.post(new LoadingFailureEvent(entry.getKey(), entry.getValue()));
    }

    LoadedPackageProvider.Bridge bridge = new LoadedPackageProvider.Bridge(packageManager, eventHandler);
    return ImmutableSet.copyOf(Sets.difference(ImmutableSet.copyOf(targetsToLoad),
            getTargetsForLabels(bridge, rootCauses.keySet())));
}

From source file:org.apache.storm.streams.processors.JoinProcessor.java

private <T1, T2> List<Tuple3<K, T1, T2>> join(Multimap<K, T1> tab, List<Pair<K, T2>> rows, JoinType leftType,
        JoinType rightType) {//w  w  w  .j a  v  a 2  s.c  om
    List<Tuple3<K, T1, T2>> res = new ArrayList<>();
    for (Pair<K, T2> row : rows) {
        K key = row.getFirst();
        Collection<T1> values = tab.removeAll(key);
        if (values.isEmpty()) {
            if (rightType == JoinType.OUTER) {
                res.add(new Tuple3<>(row.getFirst(), null, row.getSecond()));
            }
        } else {
            for (T1 mapValue : values) {
                res.add(new Tuple3<>(row.getFirst(), mapValue, row.getSecond()));
            }
        }
    }
    // whatever remains in the tab are non matching left rows.
    if (leftType == JoinType.OUTER) {
        for (Map.Entry<K, T1> row : tab.entries()) {
            res.add(new Tuple3<>(row.getKey(), row.getValue(), null));
        }
    }
    return res;
}

From source file:de.hpi.bp2013n1.anonymizer.Anonymizer.java

/**
 * Creates a multimap which maps applied strategies to a TableField
 * (table or attribtue) in the correct order of application.
 *///from  www. j a va  2  s .c  o m
void collectRulesBySite() {
    RuleConnector ruleConnector = new RuleConnector();
    ruleConnector.addRules(config.getRules());
    Multimap<TableField, Rule> rulesBySite = ruleConnector.getRulesBySite();
    comprehensiveRulesBySite = LinkedHashMultimap.create();
    for (Map.Entry<TableField, Rule> siteAndRule : rulesBySite.entries()) {
        TableField thisSite = siteAndRule.getKey();
        ArrayList<Rule> rulesToApplyToThisSite = new ArrayList<>();
        Rule rule = siteAndRule.getValue();
        rulesToApplyToThisSite.addAll(rule.transitiveParents());
        rulesToApplyToThisSite.add(rule);
        comprehensiveRulesBySite.putAll(thisSite, rulesToApplyToThisSite);
    }

    Iterator<Rule> rulesIterator = comprehensiveRulesBySite.values().iterator();
    while (rulesIterator.hasNext()) {
        Rule eachRule = rulesIterator.next();
        if (eachRule.getTransformation() == null) {
            eachRule.setTransformation(strategyByName.get(eachRule.getStrategy()));
        }
        if (eachRule.getTransformation() instanceof NoOperationStrategy) {
            rulesIterator.remove();
        }
    }
}

From source file:com.jcwhatever.nucleus.collections.MultiBiMap.java

@Override
public boolean putAll(Multimap<? extends K, ? extends V> multimap) {
    PreCon.notNull(multimap);//from  w  w  w. j  a va 2  s. c o m

    boolean isChanged = false;

    for (Entry<? extends K, ? extends V> entry : multimap.entries()) {
        isChanged = put(entry.getKey(), entry.getValue()) || isChanged;
    }

    return isChanged;
}

From source file:co.cask.cdap.data2.datafabric.dataset.DatasetServiceClient.java

private HttpResponse doRequest(HttpMethod method, String resource, @Nullable Multimap<String, String> headers,
        @Nullable String body) throws DatasetManagementException {

    String url = resolve(resource);
    try {//w  w w .  ja  va  2 s. c om
        return HttpRequests.execute(
                processBuilder(HttpRequest.builder(method, new URL(url)).addHeaders(headers).withBody(body))
                        .build());
    } catch (IOException e) {
        throw new DatasetManagementException(String.format(
                "Error during talking to Dataset Service at %s while doing %s with headers %s and body %s", url,
                method,
                headers == null ? "null" : Joiner.on(",").withKeyValueSeparator("=").join(headers.entries()),
                body == null ? "null" : body), e);
    }
}

From source file:io.bazel.rules.closure.webfiles.Webset.java

/**
 * Loads graph of web files from proto manifests.
 *
 * @param manifests set of web rule target proto files in reverse topological order
 * @return set of web files and relationships between them, which could be mutated, although
 *     adding a single key will most likely result in a full rehash
 *//*from w w w  .j a v  a2s  .com*/
public static Webset load(Map<Path, WebfileManifestInfo> manifests, WebpathInterner interner) {
    int webfileCapacity = 0;
    int unlinkCapacity = 16; // LinkedHashMultimap#DEFAULT_KEY_CAPACITY
    for (WebfileManifestInfo manifest : manifests.values()) {
        webfileCapacity += manifest.getWebfileCount();
        unlinkCapacity = Math.max(unlinkCapacity, manifest.getUnlinkCount());
    }
    Map<Webpath, Webfile> webfiles = Maps.newLinkedHashMapWithExpectedSize(webfileCapacity);
    Multimap<Webpath, Webpath> links = LinkedHashMultimap.create(webfileCapacity, 4);
    Multimap<Webpath, Webpath> unlinks = LinkedHashMultimap.create(unlinkCapacity, 4);
    for (Map.Entry<Path, WebfileManifestInfo> entry : manifests.entrySet()) {
        Path manifestPath = entry.getKey();
        Path zipPath = WebfilesUtils.getIncrementalZipPath(manifestPath);
        WebfileManifestInfo manifest = entry.getValue();
        String label = manifest.getLabel();
        for (WebfileInfo info : manifest.getWebfileList()) {
            Webpath webpath = interner.get(info.getWebpath());
            webfiles.put(webpath, Webfile.create(webpath, zipPath, label, info));
        }
        for (MultimapInfo mapping : manifest.getLinkList()) {
            Webpath from = interner.get(mapping.getKey());
            for (Webpath to : Iterables.transform(mapping.getValueList(), interner)) {
                // When compiling web_library rules, if the strict dependency checking invariant holds
                // true, we can choose to only load adjacent manifests, rather than transitive ones. The
                // adjacent manifests may contain links to transitive web files which will not be in the
                // webfiles map.
                if (webfiles.containsKey(to)) {
                    links.put(from, to);
                    checkArgument(!unlinks.containsEntry(from, to),
                            "Has a use case for resurrected links been discovered? %s -> %s", from, to);
                }
            }
        }
        for (MultimapInfo mapping : manifest.getUnlinkList()) {
            unlinks.putAll(interner.get(mapping.getKey()),
                    Collections2.transform(mapping.getValueList(), interner));
        }
    }
    for (Map.Entry<Webpath, Webpath> entry : unlinks.entries()) {
        links.remove(entry.getKey(), entry.getValue());
    }
    unlinks.clear();
    return new AutoValue_Webset(webfiles, links, interner);
}