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

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

Introduction

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

Prototype

@Override
List<V> get(@Nullable K key);

Source Link

Document

Because the values for a given key may have duplicates and follow the insertion ordering, this method returns a List , instead of the java.util.Collection specified in the Multimap interface.

Usage

From source file:com.navercorp.pinpoint.web.mapper.SpanMapperV2.java

private List<SpanBo> bindSpanChunk(ListMultimap<AgentKey, SpanBo> spanMap, List<SpanChunkBo> spanChunkList) {
    for (SpanChunkBo spanChunkBo : spanChunkList) {
        AgentKey agentKey = newAgentKey(spanChunkBo);
        List<SpanBo> matchedSpanBoList = spanMap.get(agentKey);
        if (matchedSpanBoList != null) {
            final int spanIdCollisionSize = matchedSpanBoList.size();
            if (spanIdCollisionSize > 1) {
                // exceptional case dump
                logger.warn("spanIdCollision {}", matchedSpanBoList);
            }/*  w w  w  . j  a v a 2 s.c  o m*/

            int agentLevelCollisionCount = 0;
            for (SpanBo spanBo : matchedSpanBoList) {
                if (isChildSpanChunk(spanBo, spanChunkBo)) {
                    spanBo.addSpanChunkBo(spanChunkBo);
                    agentLevelCollisionCount++;
                }
            }
            if (agentLevelCollisionCount > 1) {
                // exceptional case dump
                logger.warn("agentLevelCollision {}", matchedSpanBoList);
            }
        } else {
            if (logger.isInfoEnabled()) {
                logger.info("Span not exist spanId:{} spanChunk:{}", agentKey, spanChunkBo);
            }
        }
    }
    return Lists.newArrayList(spanMap.values());
}

From source file:eu.esdihumboldt.cst.functions.geometric.aggregate.AggregateTransformation.java

@Override
protected Object evaluate(String transformationIdentifier, TransformationEngine engine,
        ListMultimap<String, PropertyValue> variables, String resultName,
        PropertyEntityDefinition resultProperty, Map<String, String> executionParameters, TransformationLog log)
        throws TransformationException, NoResultException {

    Iterable<Object> geometries = Iterables.transform(variables.get(null),
            new Function<PropertyValue, Object>() {

                @Override/*  w w  w.j a va  2 s  .  c o  m*/
                public Object apply(PropertyValue input) {
                    return input.getValue();
                }
            });
    return aggregateGeometries(geometries, log, getCell());
}

From source file:eu.esdihumboldt.hale.ui.functions.groovy.GroovyTransformationPage.java

/**
 * Get the list of source entities configured as variables.
 * /*from   w  w w .  ja v a 2s  . co m*/
 * @return the source entities configured as variables
 */
protected List<EntityDefinition> getVariables() {
    ListMultimap<String, ? extends Entity> source = getWizard().getUnfinishedCell().getSource();
    if (source != null) {
        List<EntityDefinition> result = new ArrayList<>();
        for (Entity entity : source.get(GroovyConstants.ENTITY_VARIABLE)) {
            result.add(entity.getDefinition());
        }
        return result;
    }
    return Collections.emptyList();
}

From source file:com.viadeo.kasper.core.id.AbstractByTypeConverter.java

@Override
public Map<ID, ID> convert(final Collection<ID> ids) {

    final ListMultimap<String, ID> idsByType = Multimaps.index(ids, new Function<ID, String>() {
        @Override//  w  ww  . j  a va2  s  . c  om
        public java.lang.String apply(ID input) {
            return checkNotNull(input).getType();
        }
    });

    final Map<ID, ID> convertResults = Maps.newHashMapWithExpectedSize(ids.size());

    for (final String type : idsByType.keySet()) {
        convertResults.putAll(doConvert(type, idsByType.get(type)));
    }

    return convertResults;
}

From source file:org.robotframework.ide.eclipse.main.plugin.assist.RedKeywordProposals.java

public RedKeywordProposal getBestMatchingKeywordProposal(final String keywordName) {
    final AccessibleKeywordsEntities accessibleKeywordsEntities = getAccessibleKeywordsEntities(suiteFile, "");
    final ListMultimap<KeywordScope, KeywordEntity> keywords = accessibleKeywordsEntities
            .getPossibleKeywords(keywordName, false);

    for (final KeywordScope scope : KeywordScope.defaultOrder()) {
        for (final KeywordEntity keyword : keywords.get(scope)) {
            return (RedKeywordProposal) keyword;
        }//w ww .j  a  v  a 2s. c  om
    }
    return null;
}

From source file:eu.esdihumboldt.cst.functions.core.inline.InlineTransformation.java

@Override
protected Object evaluate(String transformationIdentifier, TransformationEngine engine,
        ListMultimap<String, PropertyValue> variables, String resultName,
        PropertyEntityDefinition resultProperty, Map<String, String> executionParameters, TransformationLog log)
        throws TransformationException, NoResultException {
    List<PropertyValue> sources = variables.get(null);
    if (sources.isEmpty()) {
        throw new NoResultException("No source available to transform");
    }//from  w ww  . j  av  a2  s  . c o  m

    PropertyValue source = sources.get(0);
    Object sourceValue = source.getValue();
    if (sourceValue == null) {
        throw new NoResultException("Source value is null");
    }
    if (!(sourceValue instanceof Instance)) {
        throw new TransformationException("Sources for inline transformation must be instances");
    }
    Instance sourceInstance = (Instance) sourceValue;
    TypeDefinition sourceType = sourceInstance.getDefinition();

    // get the original alignment
    Alignment orgAlignment = getExecutionContext().getAlignment();
    MutableAlignment alignment = new DefaultAlignment(orgAlignment);

    // identify relevant type cell(s)
    MutableCell queryCell = new DefaultCell();
    ListMultimap<String, Type> sourceEntities = ArrayListMultimap.create();
    sourceEntities.put(null, new DefaultType(new TypeEntityDefinition(sourceType, SchemaSpaceID.SOURCE, null)));
    queryCell.setSource(sourceEntities);
    ListMultimap<String, Type> targetEntities = ArrayListMultimap.create();
    targetEntities.put(null,
            new DefaultType(new TypeEntityDefinition(resultProperty.getDefinition().getPropertyType(),
                    SchemaSpaceID.TARGET, null)));
    queryCell.setTarget(targetEntities);
    Collection<? extends Cell> candidates = alignment.getTypeCells(queryCell);
    if (candidates.isEmpty()) {
        log.error(log.createMessage("No type transformations found for inline transformation", null));
        throw new NoResultException();
    }

    // filter alignment -> only keep relevant type relations
    List<Cell> allTypeCells = new ArrayList<>(alignment.getTypeCells());
    for (Cell cell : allTypeCells) {
        // remove cell
        alignment.removeCell(cell);

        if (!cell.getTransformationMode().equals(TransformationMode.disabled)) {
            // only readd if not disabled

            MutableCell copy = new DefaultCell(cell);
            if (candidates.contains(cell)) {
                // readd as active
                copy.setTransformationMode(TransformationMode.active);
            } else {
                // readd as passive
                copy.setTransformationMode(TransformationMode.passive);
            }
            alignment.addCell(copy);
        }
    }

    // prepare transformation input/output
    DefaultInstanceCollection sourceInstances = new DefaultInstanceCollection();
    sourceInstances.add(sourceInstance);
    DefaultInstanceSink target = new DefaultInstanceSink();

    // run transformation
    TransformationService ts = getExecutionContext().getService(TransformationService.class);
    if (ts == null) {
        throw new TransformationException("Transformation service not available for inline transformation");
    }

    ProgressIndicator progressIndicator = new LogProgressIndicator();
    TransformationReport report = ts.transform(alignment, sourceInstances,
            new ThreadSafeInstanceSink<InstanceSink>(target), getExecutionContext(), progressIndicator);

    // copy report messages
    log.importMessages(report);

    if (!report.isSuccess()) {
        // copy report messages
        log.importMessages(report);
        throw new TransformationException("Inline transformation failed");
    }

    // extract result
    List<Instance> targetList = target.getInstances();
    if (targetList.isEmpty()) {
        log.error(log.createMessage("Inline transformation yielded no result", null));
        throw new NoResultException("No result from inline transformation");
    }

    if (targetList.size() > 1) {
        log.error(log.createMessage("Inline transformation yielded multiple results, only first result is used",
                null));
    }

    return targetList.get(0);
}

From source file:eu.esdihumboldt.hale.ui.functions.inspire.IdentifierParameterPage.java

@Override
public void setParameter(Set<FunctionParameterDefinition> params,
        ListMultimap<String, ParameterValue> initialValues) {
    if (initialValues != null) {
        initialCountry = initialValues.get(COUNTRY_PARAMETER_NAME).get(0).as(String.class);
        initialProvider = initialValues.get(DATA_PROVIDER_PARAMETER_NAME).get(0).as(String.class);
        initialProduct = initialValues.get(PRODUCT_PARAMETER_NAME).get(0).as(String.class);
        initialVersion = initialValues.get(VERSION).get(0).as(String.class);
        initialVersionNil = initialValues.get(VERSION_NIL_REASON).get(0).as(String.class);
    } else {/*from ww w . ja  v a 2 s  .  co  m*/
        initialCountry = "";
        initialProvider = "";
        initialProduct = "";
        initialVersion = "";
        initialVersionNil = "";
    }
}

From source file:org.sonar.plugins.core.timemachine.TendencyDecorator.java

public void decorate(Resource resource, DecoratorContext context) {
    if (shouldDecorateResource(resource)) {
        resetQuery(context.getProject(), resource);
        List<Object[]> fields = timeMachine.getMeasuresFields(query);
        ListMultimap<Metric, Double> valuesPerMetric = ArrayListMultimap.create();
        for (Object[] field : fields) {
            valuesPerMetric.put((Metric) field[1], (Double) field[2]);
        }/*w ww . j  a v  a  2 s  . c  o  m*/

        for (Metric metric : query.getMetrics()) {
            Measure measure = context.getMeasure(metric);
            if (measure != null) {
                List<Double> values = valuesPerMetric.get(metric);
                values.add(measure.getValue());

                measure.setTendency(analyser.analyseLevel(valuesPerMetric.get(metric)));
                context.saveMeasure(measure);
            }
        }
    }
}

From source file:org.sonar.plugins.checkstyle.CheckstyleProfileExporter.java

private void appendTreeWalker(Writer writer, ListMultimap<String, ActiveRule> activeRulesByConfigKey)
        throws IOException {
    writer.append("<module name=\"TreeWalker\">");
    writer.append("<module name=\"FileContentsHolder\"/> ");
    for (String configKey : activeRulesByConfigKey.keySet()) {
        if (isInTreeWalker(configKey)) {
            List<ActiveRule> activeRules = activeRulesByConfigKey.get(configKey);
            for (ActiveRule activeRule : activeRules) {
                appendModule(writer, activeRule);
            }//from   ww  w .j a  v  a  2s  . co m
        }
    }
    writer.append("</module>");
}

From source file:com.echosource.ada.rules.AdaProfileExporter.java

private void appendTreeWalker(Writer writer, ListMultimap<String, ActiveRule> activeRulesByConfigKey)
        throws IOException {
    writer.append("<module name=\"TreeWalker\">");
    writer.append("<module name=\"FileContentsHolder\"/> ");
    for (String configKey : activeRulesByConfigKey.keySet()) {
        if (isInTreeWalker(configKey)) {
            List<ActiveRule> activeRules = activeRulesByConfigKey.get(configKey);
            for (ActiveRule activeRule : activeRules) {
                appendModule(writer, activeRule, activeRules.size() > 1);
            }/*w w  w  . j a va  2  s.  co m*/
        }
    }
    writer.append("</module>");
}