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:fr.ujm.tse.lt2c.satin.rules.run.RunRDFS12.java

@Override
protected int process(final TripleStore ts1, final TripleStore ts2, final Collection<Triple> outputTriples) {

    final long containerMembershipProperty = AbstractDictionary.containerMembershipProperty;
    final long type = AbstractDictionary.type;
    final long subPropertyOf = AbstractDictionary.subPropertyOf;
    final long member = AbstractDictionary.member;

    int loops = 0;

    final Multimap<Long, Long> typeMultimap = ts1.getMultiMapForPredicate(type);
    if (typeMultimap != null && !typeMultimap.isEmpty()) {
        for (final Long subject : typeMultimap.keySet()) {
            if (typeMultimap.get(subject).contains(containerMembershipProperty)) {
                loops++;//from w  w  w  .ja  v  a2 s . c om
                final Triple result = new ImmutableTriple(subject, subPropertyOf, member);
                outputTriples.add(result);
            }
        }
    }

    return loops;

}

From source file:org.pshdl.model.utils.HDLResolver.java

private <T> Iterable<T> checkCache(HDLQualifiedName var, Multimap<HDLQualifiedName, T> map) {
    if (map.get(var) != null)
        return map.get(var);
    if (var.length == 1) {
        final HDLQualifiedName fqn = resolveName.append(var);
        if (map.get(fqn) != null)
            return map.get(fqn);
    }//from   w  ww .j  a  va  2  s .c o  m
    return null;
}

From source file:com.facebook.presto.server.ResourceUtil.java

public static Session createSessionForRequest(HttpServletRequest servletRequest, AccessControl accessControl,
        SessionPropertyManager sessionPropertyManager, QueryId queryId) {
    String catalog = trimEmptyToNull(servletRequest.getHeader(PRESTO_CATALOG));
    String schema = trimEmptyToNull(servletRequest.getHeader(PRESTO_SCHEMA));
    assertRequest((catalog != null) || (schema == null), "Schema is set but catalog is not");

    String user = trimEmptyToNull(servletRequest.getHeader(PRESTO_USER));
    assertRequest(user != null, "User must be set");

    Principal principal = servletRequest.getUserPrincipal();
    try {/*from   w  w  w.  j ava  2 s .c  o  m*/
        accessControl.checkCanSetUser(principal, user);
    } catch (AccessDeniedException e) {
        throw new WebApplicationException(e.getMessage(), Status.FORBIDDEN);
    }

    Identity identity = new Identity(user, Optional.ofNullable(principal));
    SessionBuilder sessionBuilder = Session.builder(sessionPropertyManager).setQueryId(queryId)
            .setIdentity(identity).setSource(servletRequest.getHeader(PRESTO_SOURCE)).setCatalog(catalog)
            .setSchema(schema).setRemoteUserAddress(servletRequest.getRemoteAddr())
            .setUserAgent(servletRequest.getHeader(USER_AGENT));

    String timeZoneId = servletRequest.getHeader(PRESTO_TIME_ZONE);
    if (timeZoneId != null) {
        sessionBuilder.setTimeZoneKey(getTimeZoneKey(timeZoneId));
    }

    String language = servletRequest.getHeader(PRESTO_LANGUAGE);
    if (language != null) {
        sessionBuilder.setLocale(Locale.forLanguageTag(language));
    }

    // parse session properties
    Multimap<String, Entry<String, String>> sessionPropertiesByCatalog = HashMultimap.create();
    for (String sessionHeader : splitSessionHeader(servletRequest.getHeaders(PRESTO_SESSION))) {
        parseSessionHeader(sessionHeader, sessionPropertiesByCatalog, sessionPropertyManager);
    }

    // verify user can set the session properties
    try {
        for (Entry<String, Entry<String, String>> property : sessionPropertiesByCatalog.entries()) {
            String catalogName = property.getKey();
            String propertyName = property.getValue().getKey();
            if (catalogName == null) {
                accessControl.checkCanSetSystemSessionProperty(identity, propertyName);
            } else {
                accessControl.checkCanSetCatalogSessionProperty(identity, catalogName, propertyName);
            }
        }
    } catch (AccessDeniedException e) {
        throw new WebApplicationException(e.getMessage(), Status.BAD_REQUEST);
    }
    sessionBuilder.setSystemProperties(toMap(sessionPropertiesByCatalog.get(null)));
    for (Entry<String, Collection<Entry<String, String>>> entry : sessionPropertiesByCatalog.asMap()
            .entrySet()) {
        if (entry.getKey() != null) {
            sessionBuilder.setCatalogProperties(entry.getKey(), toMap(entry.getValue()));
        }
    }

    return sessionBuilder.build();
}

From source file:org.gradle.execution.TaskNameResolvingBuildExecuter.java

public void select(GradleInternal gradle) {
    Multimap<String, Task> selectedTasks = doSelect(gradle, names, taskNameResolver);

    this.executer = gradle.getTaskGraph();
    for (String name : selectedTasks.keySet()) {
        executer.addTasks(selectedTasks.get(name));
    }//from   w  w  w  .  j a va 2 s  . c  o  m
    if (selectedTasks.keySet().size() == 1) {
        description = String.format("primary task %s", GUtil.toString(selectedTasks.keySet()));
    } else {
        description = String.format("primary tasks %s", GUtil.toString(selectedTasks.keySet()));
    }
}

From source file:org.sonar.db.version.v451.AddMissingCustomRuleParametersMigrationStep.java

private void insertCustomRuleParameterIfNotAlreadyExisting(RuleParameter templateRuleParam,
        Integer templateRuleId, Multimap<Integer, Integer> customRuleIdsByTemplateRuleId,
        Multimap<Integer, RuleParameter> customRuleParamsByRuleId, DbSession session) {
    for (Integer customRuleId : customRuleIdsByTemplateRuleId.get(templateRuleId)) {
        if (!hasParameter(templateRuleParam.getName(), customRuleParamsByRuleId.get(customRuleId))) {
            // Insert new custom rule parameter
            session.getMapper(Migration45Mapper.class)
                    .insertRuleParameter(new RuleParameter().setRuleId(customRuleId)
                            .setRuleTemplateId(templateRuleId).setName(templateRuleParam.getName())
                            .setDescription(templateRuleParam.getDescription())
                            .setType(templateRuleParam.getType()));

            // Update updated at date of custom rule in order to allow E/S indexation
            session.getMapper(Migration45Mapper.class).updateRuleUpdateAt(customRuleId, new Date(system.now()));

            counter.getAndIncrement();/*w  w w  .j  av  a2 s  .c om*/
        }
    }
}

From source file:org.opencms.ui.dialogs.embedded.CmsDataViewParams.java

/**
 * Creates a new instance by parsing the query string of the given URI.<p>
 *
 * @param uri the URI from which to read the configuration
 */// w  ww.  ja  va2s  . c  o  m
public CmsDataViewParams(URI uri) {
    Multimap<String, String> params = CmsRequestUtil.getParameters(uri);
    if (params.containsKey(CmsDataViewConstants.PARAM_CONFIG)) {
        String encodedConfig = params.get(CmsDataViewConstants.PARAM_CONFIG).iterator().next();
        try {
            JSONObject json = new JSONObject(CmsDataViewParamEncoder.decodeString(encodedConfig));

            m_callback = json.optString(CmsDataViewConstants.PARAM_CALLBACK);
            m_callbackArg = json.optString(CmsDataViewConstants.PARAM_CALLBACK_ARG);
            m_viewClass = json.optString(CmsDataViewConstants.CONFIG_VIEW_CLASS);
            m_viewArg = json.optString(CmsDataViewConstants.CONFIG_VIEW_ARG);
            m_multiSelect = json.optString(CmsDataViewConstants.CONFIG_MULTI_SELECT);
        } catch (JSONException e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
    }
}

From source file:org.softinica.maven.jmeter.report.analyser.SummaryReportAnalyzer.java

@Override
protected void fillTable(Table table, Multimap<Object, Sample> grouped) {
    StandardDeviation deviation = new StandardDeviation();
    for (Object key : grouped.keySet()) {
        double total = 0D;
        int sampleCount = grouped.get(key).size();
        double[] values = new double[sampleCount];
        double min = Double.MAX_VALUE;
        double max = Double.MIN_VALUE;
        long minTimestamp = Long.MAX_VALUE;
        long maxTimestamp = Long.MIN_VALUE;
        long totalBytes = 0;
        int errorCount = 0;
        int i = 0;
        for (Sample sample : grouped.get(key)) {
            total += sample.getValue();//from w w w.java  2  s. com
            values[i] = sample.getValue();
            i++;
            if (min > sample.getValue()) {
                min = sample.getValue();
            }
            if (max < sample.getValue()) {
                max = sample.getValue();
            }
            if (!sample.isSuccess()) {
                errorCount++;
            }
            if (minTimestamp > sample.getTimestamp()) {
                minTimestamp = sample.getTimestamp();
            }
            if (maxTimestamp < sample.getTimestamp()) {
                maxTimestamp = sample.getTimestamp();
            }
            totalBytes += sample.getByteCount();
        }
        table.put(key, LABEL, key.toString());
        table.put(key, SAMPLES, String.valueOf(sampleCount));
        table.put(key, AVERAGE, NUMBER_FORMAT.format(total / sampleCount));
        table.put(key, MIN, NUMBER_FORMAT.format(min));
        table.put(key, MAX, NUMBER_FORMAT.format(max));
        table.put(key, STD_DEV, NUMBER_FORMAT.format(deviation.evaluate(values)));
        table.put(key, ERROR, NUMBER_FORMAT.format(100.0D * errorCount / sampleCount));
        table.put(key, THROUGHPUT, NUMBER_FORMAT.format(sampleCount / total * 1000));
        table.put(key, KB_PER_SEC, NUMBER_FORMAT.format(totalBytes / total * 1000));
        table.put(key, AVERAGE_BYTES, NUMBER_FORMAT.format(totalBytes / sampleCount));
    }
}

From source file:edu.umn.msi.tropix.client.directory.impl.UserIterableImpl.java

public Iterator<GridUser> iterator() {
    final Collection<GridUser> users = new LinkedList<GridUser>();
    final Multimap<String, Person> persons = personSupplier.get();
    for (String institution : persons.keySet()) {
        Iterables.addAll(users,//  www.  j a va2 s .  co  m
                Iterables.filter(
                        Collections2.transform(persons.get(institution), new PersonFunction(institution)),
                        Predicates.not(Predicates.isNull())));
    }
    for (final GridUser user : users) {
        gridUserMap.put(user.getGridId(), user);
    }
    return users.iterator();
}

From source file:games.stendhal.server.core.engine.db.StendhalBuddyDAO.java

/**
 * saves the buddy list for the specified charname
 * /*from  w w w . j a  va2s .com*/
 * @param transaction transaction
 * @param charname name of char
 * @param player player
 * @throws SQLException in case of an database error
 */
public void saveRelations(DBTransaction transaction, String charname, Player player) throws SQLException {
    Multimap<String, String> oldList = loadRelations(transaction, charname);

    Set<String> buddies = player.getBuddies();
    buddies.add(charname);
    syncBuddyListToDB(transaction, charname, "buddy", oldList.get("buddy"), buddies);
    syncBuddyListToDB(transaction, charname, "ignore", oldList.get("ignore"), player.getIgnores());
}

From source file:org.richfaces.cdk.resource.scan.impl.reflections.ReflectionsExt.java

public Collection<Class<?>> getMarkedClasses() {
    Map<String, Multimap<String, String>> storeMap = getStore().getStoreMap();
    Multimap<String, String> scannerMMap = storeMap.get(MarkerResourcesScanner.class.getName());
    if (scannerMMap == null) {
        return Collections.emptySet();
    }//w  w w  .j ava2  s  . c  o m

    return Collections2.filter(
            Collections2.transform(scannerMMap.get(MarkerResourcesScanner.STORE_KEY), CLASS_FOR_NAME),
            Predicates.notNull());
}