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.github.haixing_hu.io.OutputUtils.java

public static <K, V> void writeMultimap(final OutputStream out, @Nullable final Multimap<K, V> map,
        final Class<K> keyClass, final Class<V> valueClass) throws IOException {
    final BinarySerializer keySerializer = BinarySerialization.getSerializer(keyClass);
    if (keySerializer == null) {
        throw new NoBinarySerializerRegisteredException(keyClass);
    }//from  w  ww.ja  va2s. com
    final BinarySerializer valueSerializer = BinarySerialization.getSerializer(valueClass);
    if (valueSerializer == null) {
        throw new NoBinarySerializerRegisteredException(valueClass);
    }
    if (!writeNullMark(out, map)) {
        writeVarInt(out, map.size());
        for (final Map.Entry<K, V> entry : map.entries()) {
            final K key = entry.getKey();
            final V value = entry.getValue();
            keySerializer.serialize(out, key);
            valueSerializer.serialize(out, value);
        }
    }
}

From source file:org.wisdom.framework.filters.BalancerFilter.java

/**
 * Callback that can be overridden to customize the header ot the request. This method implements the reverse
 * routing. It updates URLs contained in the headers.
 *
 * @param context the request context//from  w ww  . j ava2 s . co m
 * @param headers the current set of headers, that need to be modified
 */
@Override
public void updateHeaders(RequestContext context, Multimap<String, String> headers) {
    if (!proxyPassReverse) {
        return;
    }
    for (Map.Entry<String, String> h : new LinkedHashSet<>(headers.entries())) {
        if (REVERSE_PROXY_HEADERS.contains(h.getKey())) {
            URI location = URI.create(h.getValue()).normalize();
            if (location.isAbsolute() && isBackendLocation(location)) {
                String initial = context.request().uri();
                URI uri = URI.create(initial);
                try {
                    URI newURI = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(),
                            location.getPath(), location.getQuery(), location.getFragment());
                    headers.remove(h.getKey(), h.getValue());
                    headers.put(h.getKey(), newURI.toString());
                } catch (URISyntaxException e) {
                    logger.error("Cannot manipulate the header {} (value={}) to enforce reverse routing",
                            h.getKey(), h.getValue(), e);
                }
            }
        }
    }
}

From source file:org.cinchapi.common.util.NonBlockingHashMultimap.java

@Override
public boolean putAll(Multimap<? extends K, ? extends V> multimap) {
    boolean changed = false;
    for (Map.Entry<? extends K, ? extends V> entry : multimap.entries()) {
        changed |= put(entry.getKey(), entry.getValue());
    }/*from   w w  w.  ja  v  a 2 s  . c o  m*/
    return changed;
}

From source file:com.kolich.curacao.examples.controllers.PostBodyExampleController.java

@RequestMapping(value = "^\\/api\\/postbody$", methods = Method.POST)
public final String postBody(
        // The encoded POST body, parsed into a Multimap.
        @RequestBody final Multimap<String, String> post,
        // The entire POST body as a single String.
        @RequestBody final String rawBody,
        // A single parameter from the POST body.
        @RequestBody("data") final String data,
        // Raw body as a byte[] array too.
        @RequestBody byte[] body) {
    final StringBuilder sb = new StringBuilder();
    for (final Map.Entry<String, String> entry : post.entries()) {
        sb.append(entry.getKey() + " -> " + entry.getValue() + LINE_SEPARATOR_UNIX);
    }/*from w  w w  .ja  v a2s . com*/
    sb.append("-------\n").append(rawBody).append("\n");
    sb.append("-------\n").append(data).append("\n");
    sb.append("-------\n").append(Arrays.toString(body));
    return sb.toString();
}

From source file:org.eclipse.incquery.runtime.evm.api.resolver.ScopedConflictSet.java

/**
 *
 *///from ww w  .ja v a  2  s .  c  o m
public ScopedConflictSet(final RuleBase ruleBase, final ConflictResolver conflictResolver,
        final Multimap<RuleSpecification<?>, EventFilter<?>> specificationFilters) {
    this.ruleBase = ruleBase;
    this.changeableConflictSet = conflictResolver.createConflictSet();
    this.specificationFilters = ImmutableMultimap.copyOf(specificationFilters);
    this.listener = new ConflictSetUpdater(changeableConflictSet);
    for (final Entry<RuleSpecification<?>, EventFilter<?>> entry : specificationFilters.entries()) {
        final RuleSpecification<?> ruleSpecification = entry.getKey();
        registerListenerFromInstance(ruleSpecification, entry.getValue());
    }
}

From source file:org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfig.java

private void handleMisssingInstancesOnTransaction(ConfigTransactionClient ta, EditConfigExecution execution)
        throws NetconfDocumentedException {

    for (Multimap<String, ModuleElementDefinition> modulesToResolved : execution.getModulesDefinition(ta)
            .values()) {//from  w  w  w. j  a v a  2 s. c  om
        for (Map.Entry<String, ModuleElementDefinition> moduleToResolved : modulesToResolved.entries()) {
            String moduleName = moduleToResolved.getKey();

            ModuleElementDefinition moduleElementDefinition = moduleToResolved.getValue();

            EditConfigStrategy strategy = moduleElementDefinition.getEditStrategy();
            strategy.executeConfiguration(moduleName, moduleElementDefinition.getInstanceName(), null, ta,
                    execution.getServiceRegistryWrapper(ta));
        }
    }
}

From source file:org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfig.java

private void setOnTransaction(ConfigTransactionClient ta, EditConfigExecution execution)
        throws NetconfDocumentedException {

    for (Multimap<String, ModuleElementResolved> modulesToResolved : execution.getResolvedXmlElements(ta)
            .values()) {//from   w  ww .  jav  a  2s.  co m

        for (Map.Entry<String, ModuleElementResolved> moduleToResolved : modulesToResolved.entries()) {
            String moduleName = moduleToResolved.getKey();

            ModuleElementResolved moduleElementResolved = moduleToResolved.getValue();
            String instanceName = moduleElementResolved.getInstanceName();

            InstanceConfigElementResolved ice = moduleElementResolved.getInstanceConfigElementResolved();
            EditConfigStrategy strategy = ice.getEditStrategy();
            strategy.executeConfiguration(moduleName, instanceName, ice.getConfiguration(), ta,
                    execution.getServiceRegistryWrapper(ta));
        }
    }
}

From source file:org.sonar.java.symexec.ExecutionState.java

void invalidateRelationsOnValue(SymbolicValue value) {
    Multimap<SymbolicValue, SymbolicValue> pairs = HashMultimap.create();
    for (ExecutionState current = this; current != null; current = current.parentState) {
        pairs.putAll(value, current.findRelatedValues(value));
    }/*from   w w w  .  j a v  a 2s .  c om*/
    for (Map.Entry<SymbolicValue, SymbolicValue> entry : pairs.entries()) {
        setRelation(entry.getKey(), SymbolicRelation.UNKNOWN, entry.getValue());
    }
}

From source file:org.jclouds.cloudstack.binders.BindAccountSecurityGroupPairsToIndexedQueryParams.java

@SuppressWarnings("unchecked")
@Override/*  w  ww  .  j  a v  a2  s. co  m*/
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    checkArgument(input instanceof Multimap<?, ?>, "this binder is only valid for Multimaps!");
    Multimap<String, String> pairs = (Multimap<String, String>) checkNotNull(input, "account group pairs");
    checkArgument(pairs.size() > 0, "you must specify at least one account, group pair");

    Multimap<String, String> existingParams = queryParser().apply(request.getEndpoint().getQuery());
    Builder<String, String> map = ImmutableMultimap.<String, String>builder().putAll(existingParams);
    int i = 0;
    for (Entry<String, String> entry : pairs.entries())
        map.put(String.format("usersecuritygrouplist[%d].account", i), entry.getKey())
                .put(String.format("usersecuritygrouplist[%d].group", i++), entry.getValue());
    URI endpoint = uriBuilder(request.getEndpoint()).query(map.build()).build();
    return (R) request.toBuilder().endpoint(endpoint).build();
}

From source file:com.hubrick.vertx.rest.converter.MultipartHttpMessageConverter.java

private boolean isMultipart(Multimap<String, Part> map, MediaType contentType) {
    if (contentType != null) {
        if (!MediaType.MULTIPART_FORM_DATA.includes(contentType)) {
            return false;
        }//from w w  w.ja v  a2s .  c  o m
    }

    for (Map.Entry<String, Part> value : map.entries()) {
        if (!(value.getValue() instanceof Part)) {
            return false;
        }
    }

    return true;
}