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:edu.buaa.satla.analysis.core.arg.ARGToDotWriter.java

/**
 * Create String with ARG in the DOT format of Graphviz.
 * @param sb Where to write the ARG into.
 * @param rootStates the root elements of the ARGs
 * @param connections start- and end-points of edges between separate graphs
 * @param successorFunction A function giving all successors of an ARGState. Only states reachable from root by iteratively applying this function will be dumped.
 * @param displayedElements A predicate for selecting states that should be displayed. States which are only reachable via non-displayed states are ignored, too.
 * @param highlightEdge Which edges to highlight in the graph?
 * @throws IOException//  w w  w  . ja v a 2 s.  c o  m
 */
public static void write(final Appendable sb, final Set<ARGState> rootStates,
        final Multimap<ARGState, ARGState> connections,
        final Function<? super ARGState, ? extends Iterable<ARGState>> successorFunction,
        final Predicate<? super ARGState> displayedElements,
        final Predicate<? super Pair<ARGState, ARGState>> highlightEdge) throws IOException {

    ARGToDotWriter toDotWriter = new ARGToDotWriter(sb);
    for (ARGState rootState : rootStates) {
        toDotWriter.enterSubgraph("cluster_" + rootState.getStateId(), "reachedset_" + rootState.getStateId());
        toDotWriter.writeSubgraph(rootState, successorFunction, displayedElements, highlightEdge);
        toDotWriter.leaveSubgraph();
    }

    for (Map.Entry<ARGState, ARGState> connection : connections.entries()) {
        sb.append(connection.getKey().getStateId() + " -> " + connection.getValue().getStateId());
        sb.append(" [color=green style=bold]\n");
    }

    toDotWriter.finish();
}

From source file:com.zimbra.common.util.StringUtil.java

/**
 * Converts a Guava multimap to an old-style version.
 *//*from w ww  .  j  av a2 s.  c om*/
public static Map<String, Object> toOldMultimap(Multimap<String, String> newMultimap) {
    Map<String, Object> oldMap = new HashMap<String, Object>();
    for (Map.Entry<String, String> entry : newMultimap.entries()) {
        addToMultiMap(oldMap, entry.getKey(), entry.getValue());
    }
    return oldMap;
}

From source file:org.joda.beans.ser.GuavaSerIteratorFactory.java

/**
 * Gets an iterator wrapper for {@code Multimap}.
 * /*  ww w .  ja v a 2s . c  o m*/
 * @param map  the collection, not null
 * @param declaredType  the declared type, not null
 * @param keyType  the key type, not null
 * @param valueType  the value type, not null
 * @param valueTypeTypes  the generic parameters of the value type
 * @return the iterator, not null
 */
@SuppressWarnings("rawtypes")
public static final SerIterator multimap(final Multimap<?, ?> map, final Class<?> declaredType,
        final Class<?> keyType, final Class<?> valueType, final List<Class<?>> valueTypeTypes) {
    return new SerIterator() {
        private final Iterator it = map.entries().iterator();
        private Map.Entry current;

        @Override
        public String metaTypeName() {
            if (map instanceof SetMultimap) {
                return "SetMultimap";
            }
            if (map instanceof ListMultimap) {
                return "ListMultimap";
            }
            return "Multimap";
        }

        @Override
        public boolean metaTypeRequired() {
            if (map instanceof SetMultimap) {
                return SetMultimap.class.isAssignableFrom(declaredType) == false;
            }
            if (map instanceof ListMultimap) {
                return ListMultimap.class.isAssignableFrom(declaredType) == false;
            }
            return Multimap.class.isAssignableFrom(declaredType) == false;
        }

        @Override
        public SerCategory category() {
            return SerCategory.MAP;
        }

        @Override
        public int size() {
            return map.size();
        }

        @Override
        public boolean hasNext() {
            return it.hasNext();
        }

        @Override
        public void next() {
            current = (Map.Entry) it.next();
        }

        @Override
        public Class<?> keyType() {
            return keyType;
        }

        @Override
        public Object key() {
            return current.getKey();
        }

        @Override
        public Class<?> valueType() {
            return valueType;
        }

        @Override
        public List<Class<?>> valueTypeTypes() {
            return valueTypeTypes;
        }

        @Override
        public Object value() {
            return current.getValue();
        }
    };
}

From source file:org.hibernate.validator.test.internal.engine.cascaded.MultimapValueExtractor.java

@Override
public void extractValues(Multimap<?, ?> originalValue, ValueExtractor.ValueReceiver receiver) {
    for (Entry<?, ?> entry : originalValue.entries()) {
        receiver.keyedValue(entry.getValue(), "multimap_value", entry.getKey());
    }/* w w  w . j a va2 s. c o  m*/
}

From source file:org.jclouds.azure.storage.options.CreateOptions.java

/**
 * A name-value pair to associate with the container as metadata.
 * /*from ww w. ja  va2s . co m*/
 * Note that these are stored at the server under the prefix: x-ms-meta-
 */
public CreateOptions withMetadata(Multimap<String, String> metadata) {
    for (Entry<String, String> entry : metadata.entries()) {
        if (entry.getKey().startsWith(AzureStorageHeaders.USER_METADATA_PREFIX))
            headers.put(entry.getKey(), entry.getValue());
        else
            headers.put(AzureStorageHeaders.USER_METADATA_PREFIX + entry.getKey(), entry.getValue());
    }
    return this;
}

From source file:org.apache.cassandra.tools.nodetool.TpStats.java

@Override
public void execute(NodeProbe probe) {
    System.out.printf("%-25s%10s%10s%15s%10s%18s%n", "Pool Name", "Active", "Pending", "Completed", "Blocked",
            "All time blocked");

    Multimap<String, String> threadPools = probe.getThreadPools();

    for (Map.Entry<String, String> tpool : threadPools.entries()) {
        System.out.printf("%-25s%10s%10s%15s%10s%18s%n", tpool.getValue(),
                probe.getThreadPoolMetric(tpool.getKey(), tpool.getValue(), "ActiveTasks"),
                probe.getThreadPoolMetric(tpool.getKey(), tpool.getValue(), "PendingTasks"),
                probe.getThreadPoolMetric(tpool.getKey(), tpool.getValue(), "CompletedTasks"),
                probe.getThreadPoolMetric(tpool.getKey(), tpool.getValue(), "CurrentlyBlockedTasks"),
                probe.getThreadPoolMetric(tpool.getKey(), tpool.getValue(), "TotalBlockedTasks"));
    }//  w  w  w  .  jav  a  2 s  .c o  m

    System.out.printf("%n%-20s%10s%n", "Message type", "Dropped");
    for (Map.Entry<String, Integer> entry : probe.getDroppedMessages().entrySet())
        System.out.printf("%-20s%10s%n", entry.getKey(), entry.getValue());
}

From source file:io.helixservice.feature.health.QueryParameterOfflineProcessor.java

public void processInstruction(Multimap<String, String> queryParameters) {
    Stream<Map.Entry<String, String>> stream = queryParameters.entries().stream();
    boolean passwordMatch = stream.filter(queryParam -> queryParam.getKey().equals(OFFLINE_PASSWORD_KEY)
            && queryParam.getValue().equals(forcedDownPassword)).count() == 1;

    if (passwordMatch) {
        queryParameters.entries().stream()
                .filter(queryParam -> queryParam.getKey().equals(OFFLINE_PARAMETER_KEY)
                        && queryParam.getValue().equals(SET_OFFLINE_VAL))
                .forEach(offlineInstruction -> {
                    LOG.info("Setting server offline");
                    Status.INSTANCE.setOffLine();
                });//from  ww  w  . jav  a  2  s  .c om

        queryParameters.entries().stream()
                .filter(queryParam -> queryParam.getKey().equals(OFFLINE_PARAMETER_KEY)
                        && queryParam.getValue().equals(SET_ONLINE_VAL))
                .forEach(offlineInstruction -> {
                    LOG.info("Setting server online");
                    Status.INSTANCE.setOnLine();
                });
    }
}

From source file:com.proofpoint.http.client.MediaType.java

private static MediaType create(String type, String subtype, Multimap<String, String> parameters) {
    checkNotNull(type);/*  w  ww.  j av a 2  s.c om*/
    checkNotNull(subtype);
    checkNotNull(parameters);
    String normalizedType = normalizeToken(type);
    String normalizedSubtype = normalizeToken(subtype);
    checkArgument(!WILDCARD.equals(normalizedType) || WILDCARD.equals(normalizedSubtype),
            "A wildcard type cannot be used with a non-wildcard subtype");
    ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();
    for (Entry<String, String> entry : parameters.entries()) {
        String attribute = normalizeToken(entry.getKey());
        builder.put(attribute, normalizeParameterValue(attribute, entry.getValue()));
    }
    MediaType mediaType = new MediaType(normalizedType, normalizedSubtype, builder.build());
    // Return one of the constants if the media type is a known type.
    return Objects.firstNonNull(KNOWN_TYPES.get(mediaType), mediaType);
}

From source file:org.fcrepo.http.commons.api.HttpHeaderInjector.java

/**
 * Add additional Http Headers//  w  w w .ja v a  2  s.c  o  m
 *
 * @param servletResponse the response
 * @param uriInfo the URI context
 * @param resource the resource
 */
public void addHttpHeaderToResponseStream(final HttpServletResponse servletResponse, final UriInfo uriInfo,
        final FedoraResource resource) {

    getUriAwareHttpHeaderFactories().forEach((bean, factory) -> {
        LOGGER.debug("Adding HTTP headers using: {}", bean);
        final Multimap<String, String> h = factory.createHttpHeadersForResource(uriInfo, resource);

        h.entries().forEach(entry -> {
            servletResponse.addHeader(entry.getKey(), entry.getValue());
        });
    });
}

From source file:com.netflix.genie.common.client.BaseGenieClient.java

/**
 * Build a HTTP request from the given parameters.
 *
 * @param verb       The type of HTTP request to use. Not null.
 * @param requestUri The URI to send the request to. Not null/empty/blank.
 * @param params     Any query parameters to send along with the request.
 * @param entity     An entity. Required for POST or PUT.
 * @return The HTTP request.//w  ww. j a  v  a  2 s.  c om
 * @throws GenieException On any error.
 */
public static HttpRequest buildRequest(final Verb verb, final String requestUri,
        final Multimap<String, String> params, final Object entity) throws GenieException {
    if (verb == null) {
        throw new GeniePreconditionException("No http verb entered unable to continue.");
    }
    if ((verb == Verb.POST || verb == Verb.PUT) && entity == null) {
        throw new GeniePreconditionException("Must have an entity to perform a post or a put.");
    }
    if (StringUtils.isBlank(requestUri)) {
        throw new GeniePreconditionException("No request uri entered. Unable to continue.");
    }
    try {
        final HttpRequest.Builder builder = HttpRequest.newBuilder().verb(verb)
                .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
                .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON).uri(new URI(requestUri)).entity(entity);
        if (params != null) {
            for (final Entry<String, String> param : params.entries()) {
                builder.queryParams(param.getKey(), param.getValue());
            }
        }
        return builder.build();
    } catch (final URISyntaxException use) {
        LOGGER.error(use.getMessage(), use);
        throw new GenieBadRequestException(use);
    }
}