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

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

Introduction

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

Prototype

Collection<V> get(@Nullable K key);

Source Link

Document

Returns a view collection of the values associated with key in this multimap, if any.

Usage

From source file:com.griddynamics.jagger.engine.e1.aggregator.session.BasicAggregator.java

private static Object getFirst(Multimap<String, Object> all, String key) {
    Iterator<Object> iterator = all.get(key).iterator();
    if (!iterator.hasNext()) {
        throw new IllegalStateException("key " + key + " has not been saved during test execution");
    }/*from www .j  a  v  a  2s  . c om*/
    return iterator.next();
}

From source file:eu.esdihumboldt.util.resource.Resources.java

private static InputSupplier<? extends InputStream> tryResolve(Multimap<String, ResourceResolver> typeResolvers,
        URI uri) {//from www  . j av a 2  s.c  o  m
    for (ResourceResolver resolver : typeResolvers.get(uri.getHost())) {
        try {
            return resolver.resolve(uri);
        } catch (ResourceNotFoundException e) {
            // ignore
        }
    }

    return null;
}

From source file:org.sonar.server.issue.notification.ChangesOnMyIssueNotificationDispatcher.java

private static void addUserToContextIfSubscribed(Context context, @Nullable String user,
        Multimap<String, NotificationChannel> subscribedRecipients) {
    if (user != null) {
        Collection<NotificationChannel> channels = subscribedRecipients.get(user);
        for (NotificationChannel channel : channels) {
            context.addUser(user, channel);
        }/*from  www .ja va2 s  . c o  m*/
    }
}

From source file:io.helixservice.core.util.VertxTypeConverter.java

/**
 * Guava MultiMap to Vert.x  Multimap./* ww  w  . j  av a2 s  . co  m*/
 * Primarily used for request and response headers.
 *
 * @param multimap Guava multimap
 * @return Multimap converted to Vert.x MultiMap
 */
static MultiMap toVertxMultiMap(Multimap<String, String> multimap) {
    MultiMap result = MultiMap.caseInsensitiveMultiMap();

    for (String key : multimap.keys()) {
        result.set(key, multimap.get(key));
    }

    return result;
}

From source file:org.jclouds.openstack.marconi.v1.functions.ParseMessagesToStream.java

private static String getClaimIdFromHref(String rawMessageHref) {
    try {/*  w  w  w.  j  a  v  a2 s .c om*/
        String query = new URI(rawMessageHref).getQuery();

        if (query != null) {
            Multimap<String, String> queryParams = queryParser().apply(query);
            return getOnlyElement(queryParams.get("claim_id"), null);
        } else {
            return null;
        }
    } catch (URISyntaxException e) {
        return null;
    }
}

From source file:ca.sqlpower.dao.helper.AbstractSPPersisterHelper.java

/**
 * Finds a property from a {@link Multimap} of persisted
 * properties of a given {@link SPObject} without removing the property.
 * /*from   ww w. ja v  a2  s  .  co  m*/
 * @param uuid
 *            The UUID of the {@link SPObject} to find and remove the
 *            property from.
 * @param propertyName
 *            The JavaBean property name.
 * @param persistedProperties
 *            {@link Multimap} of persisted properties to retrieve and
 *            remove the property from.
 * @return The value of the property.
 */
public static PersistedSPOProperty findProperty(String uuid, String propertyName,
        Multimap<String, PersistedSPOProperty> persistedProperties) {
    for (PersistedSPOProperty property : persistedProperties.get(uuid)) {
        if (property.getPropertyName().equals(propertyName)) {
            return property;
        }
    }
    // Property might not be persisted because it might be null. 
    // We therefore need to return null.
    return null;
}

From source file:ca.sqlpower.dao.helper.AbstractSPPersisterHelper.java

/**
 * Finds and removes a property from a {@link Multimap} of persisted
 * properties of a given {@link SPObject}.
 * //from w w w.  j  av a 2 s  .  c o  m
 * @param uuid
 *            The UUID of the {@link SPObject} to find and remove the
 *            property from.
 * @param propertyName
 *            The JavaBean property name.
 * @param persistedProperties
 *            {@link Multimap} of persisted properties to retrieve and
 *            remove the property from.
 * @return The value of the property.
 */
public static Object findPropertyAndRemove(String uuid, String propertyName,
        Multimap<String, PersistedSPOProperty> persistedProperties) {
    for (PersistedSPOProperty property : persistedProperties.get(uuid)) {
        if (property.getPropertyName().equals(propertyName)) {
            Object newValue = property.getNewValue();
            persistedProperties.remove(uuid, property);
            return newValue;
        }
    }
    // Property might not be persisted because it might be null. 
    // We therefore need to return null.
    return null;
}

From source file:org.jclouds.openstack.nova.v1_1.util.NovaUtils.java

/**
 * The traditional way to represent a graph in Java is Map<V, Set<V>>, which is awkward in a
 * number of ways. Guava's Multimap framework makes it easy to handle a mapping from keys to
 * multiple values.//w ww .  j a va 2  s .  c  o  m
 * <p/>
 * Until we write or discover a gson Multimap deserializer, we may be stuck with this.
 * 
 * TODO: ask on stackoverflow and/or jesse wilson
 */
@Deprecated
public static <K, V> Map<K, Set<V>> toOldSchool(Multimap<K, V> in) {
    ImmutableMap.Builder<K, Set<V>> out = ImmutableMap.<K, Set<V>>builder();
    for (K type : in.keySet())
        out.put(type, ImmutableSet.copyOf(in.get(type)));
    return out.build();
}

From source file:eu.esdihumboldt.hale.common.align.model.functions.ClassificationMappingUtil.java

/**
 * Get the classification lookup table from the transformation parameters.
 * //w  ww.  j a  va 2 s.  c o m
 * @param parameters the transformation parameters
 * @param serviceProvider service provider in case a lookup table has to be
 *            retrieved through a service
 * @return the classification lookup table
 */
public static LookupTable getClassificationLookup(Multimap<String, ? extends Value> parameters,
        ServiceProvider serviceProvider) {

    try {
        if (!(parameters.get(PARAMETER_LOOKUPTABLE).isEmpty())) {
            Collection<? extends Value> tmpMap = parameters.get(PARAMETER_LOOKUPTABLE);
            return tmpMap.iterator().next().as(LookupTable.class);
        }
        if (!(parameters.get(PARAMETER_LOOKUPTABLE_ID).isEmpty())) {
            LookupService lookupServiceImpl = serviceProvider.getService(LookupService.class);
            Collection<? extends Value> tmpMap = parameters.get(PARAMETER_LOOKUPTABLE_ID);
            LookupTableInfo lookupTableInfo = lookupServiceImpl
                    .getTable(tmpMap.iterator().next().as(String.class));
            return lookupTableInfo.getTable();
        }
    } catch (NullPointerException e) {
        log.error("Service provider not accessible for retrieving lookup table", e);
    }

    // For reason of compatibility we need the following code
    // lookup table in strangely encoded string parameter
    Collection<? extends Value> mappings = parameters.get(PARAMETER_CLASSIFICATIONS);
    try {
        Map<Value, Value> lookupMap = new HashMap<Value, Value>();
        for (Value mapping : mappings) {
            String[] parts = mapping.as(String.class).split(" ");
            if (parts.length > 0) {
                Value target = Value.of(URLDecoder.decode(parts[0], "UTF-8"));
                for (int i = 1; i < parts.length; i++) {
                    lookupMap.put(Value.of(URLDecoder.decode(parts[i], "UTF-8")), target);
                }
            }
        }
        return new LookupTableImpl(lookupMap);
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException("Failed to decode classification mapping.");
    }
}

From source file:com.torodb.torod.db.postgresql.query.processors.InProcessor.java

@Nullable
private static ProcessedQueryCriteria getProcessedQuery(InQueryCriteria criteria,
        Multimap<BasicType, Value<?>> byTypeValues, BasicType type) {
    Collection<Value<?>> values = byTypeValues.get(type);
    if (values.isEmpty()) {
        return null;
    }/* w  w  w. j  ava  2  s  . c om*/
    ImmutableList.Builder<Value<?>> newInBuilder = new ImmutableList.Builder();
    for (Value<?> value : values) {
        newInBuilder.add(value);
    }

    return new ProcessedQueryCriteria(new TypeIsQueryCriteria(criteria.getAttributeReference(), type),
            new InQueryCriteria(criteria.getAttributeReference(), newInBuilder.build()));
}