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.b2international.snowowl.snomed.datastore.converter.SnomedConceptConverter.java

private void expandRelationships(List<SnomedConcept> results, final Set<String> conceptIds) {
    if (!expand().containsKey(SnomedConcept.Expand.RELATIONSHIPS)) {
        return;//w  ww  .  j  a  v a 2s . c om
    }

    final Options expandOptions = expand().get(SnomedConcept.Expand.RELATIONSHIPS, Options.class);
    final SnomedRelationships relationships = SnomedRequests.prepareSearchRelationship().all()
            .filterByActive(expandOptions.containsKey("active") ? expandOptions.getBoolean("active") : null)
            .filterByCharacteristicType(expandOptions.containsKey("characteristicType")
                    ? expandOptions.getString("characteristicType")
                    : null)
            .filterByType(
                    expandOptions.containsKey("typeId") ? expandOptions.getCollection("typeId", String.class)
                            : null)
            .filterByDestination(expandOptions.containsKey("destinationId")
                    ? expandOptions.getCollection("destinationId", String.class)
                    : null)
            .filterBySource(conceptIds).setExpand(expandOptions.get("expand", Options.class))
            .setLocales(locales()).build().execute(context());

    final ListMultimap<String, SnomedRelationship> relationshipsByConceptId = Multimaps.index(relationships,
            relationship -> relationship.getSourceId());

    for (SnomedConcept concept : results) {
        final List<SnomedRelationship> conceptRelationships = relationshipsByConceptId.get(concept.getId());
        concept.setRelationships(new SnomedRelationships(conceptRelationships, null, null,
                conceptRelationships.size(), conceptRelationships.size()));
    }
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.IndexAugmentorFactory.java

private void refreshFulltextQueryTermsProviders() {
    ListMultimap<String, FulltextQueryTermsProvider> providerMultimap = LinkedListMultimap.create();
    for (FulltextQueryTermsProvider provider : fulltextQueryTermsProviders) {
        Set<String> supportedNodeTypes = provider.getSupportedTypes();
        for (String nodeType : supportedNodeTypes) {
            providerMultimap.put(nodeType, provider);
        }/*from  w  ww .jav  a 2  s .c  om*/
    }

    Map<String, CompositeFulltextQueryTermsProvider> providerMap = Maps.newHashMap();
    for (String nodeType : providerMultimap.keySet()) {
        List<FulltextQueryTermsProvider> providers = providerMultimap.get(nodeType);
        CompositeFulltextQueryTermsProvider compositeFulltextQueryTermsProvider = new CompositeFulltextQueryTermsProvider(
                nodeType, providers);
        providerMap.put(nodeType, compositeFulltextQueryTermsProvider);
    }

    fulltextQueryTermsProviderMap = ImmutableMap.copyOf(providerMap);
}

From source file:com.jivesoftware.os.miru.plugin.index.BloomIndex.java

public <V extends HasValue> List<Mights<V>> wantBits(List<V> keys) {
    ListMultimap<Integer, Might<V>> valueBitIndexes = ArrayListMultimap.create();
    for (V key : keys) {
        Might<V> might = new Might<>(key, numHashFunctions);
        int[] bitIndexes = new int[numHashFunctions];
        createBitIndexesForValue(key.getBloomValue(), numHashFunctions, bitIndexes, 0);
        Arrays.sort(bitIndexes);/*w ww  .ja  v a2s .com*/
        for (Integer bitIndex : bitIndexes) {
            valueBitIndexes.put(bitIndex, might);
        }
    }

    List<Mights<V>> mights = new ArrayList<>();
    for (Integer key : valueBitIndexes.keySet()) {
        mights.add(new Mights<>(key, valueBitIndexes.get(key)));
    }
    Collections.sort(mights);
    return mights;
}

From source file:eu.esdihumboldt.hale.common.align.custom.groovy.CustomGroovyTransformation.java

private Binding createGroovyBinding(ListMultimap<String, PropertyValue> variables, Cell cell, Cell typeCell,
        InstanceBuilder builder, TransformationLog log, ExecutionContext executionContext,
        TypeDefinition targetInstanceType) {
    Binding binding = GroovyUtil.createBinding(builder, cell, typeCell, log, executionContext,
            targetInstanceType);/*  ww w .  j av  a2s . c om*/

    // create bindings for inputs
    for (DefaultCustomPropertyFunctionEntity source : customFunction.getSources()) {
        String varName = source.getName();

        boolean useInstanceVariable = useInstanceVariableForSource(source);
        List<PropertyValue> values = variables.get(varName);

        if (source.isEager() || source.getMaxOccurrence() > 1
                || source.getMaxOccurrence() == ParameterDefinition.UNBOUNDED) {
            // multiple values
            InstanceAccessorArrayList<Object> valueList = new InstanceAccessorArrayList<>();
            for (PropertyValue value : values) {
                valueList.add(GroovyTransformation.getUseValue(value.getValue(), useInstanceVariable));
            }
            binding.setVariable(varName, valueList);
        } else {
            // single value
            if (values.isEmpty()) {
                // no value
                // -> use null value for missing variable
                binding.setVariable(varName, null);
            } else {
                // value
                binding.setVariable(varName,
                        GroovyTransformation.getUseValue(values.get(0).getValue(), useInstanceVariable));
            }
        }
    }

    // create binding(s) for parameters
    binding.setVariable(BINDING_PARAMS, new ParameterBinding(cell, customFunction.getDescriptor()));

    return binding;
}

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

@Override
public String getExplanation(Cell cell, ServiceProvider provider, Locale locale) {
    Entity target = CellUtil.getFirstEntity(cell.getTarget());
    Entity source = CellUtil.getFirstEntity(cell.getSource());

    LookupTable lookup = ClassificationMappingUtil.getClassificationLookup(cell.getTransformationParameters(),
            provider);/*  w  w  w.  j a va  2s. co  m*/
    ListMultimap<Value, Value> revLookup = lookup.reverse();
    String notClassifiedAction = CellUtil.getFirstParameter(cell, PARAMETER_NOT_CLASSIFIED_ACTION)
            .as(String.class);

    if (target != null && source != null) {
        StringBuilder mappingString = new StringBuilder();
        for (Value targetValue : revLookup.keySet()) {
            mappingString.append(quoteValue(targetValue.as(String.class), false));
            mappingString.append(' ');
            mappingString.append(getMessage("oneOf", locale));
            mappingString.append(' ');
            int i = 1;
            for (Value sourceValue : revLookup.get(targetValue)) {
                if (i != 1) {
                    mappingString.append(", ");
                }
                mappingString.append(quoteValue(sourceValue.as(String.class), false));

                i++;
            }
            mappingString.append(".\n");
        }
        String notClassifiedResult = "null";
        if (USE_SOURCE_ACTION.equals(notClassifiedAction)) {
            notClassifiedResult = getMessage("useSource", locale);
        } else if (notClassifiedAction != null
                && notClassifiedAction.startsWith(USE_FIXED_VALUE_ACTION_PREFIX)) {
            notClassifiedResult = quoteText(notClassifiedAction.substring(notClassifiedAction.indexOf(':') + 1),
                    false);
        }
        // otherwise it's null or USE_NULL_ACTION

        return MessageFormat.format(getMessage("main", locale), formatEntity(target, false, true, locale),
                formatEntity(source, false, true, locale), mappingString.toString(), notClassifiedResult);
    }

    return null;
}

From source file:sql.CreateTable.java

ListMultimap<String, String> Create(String... s) throws Exception {

    int i = 0, j = 0, k, m = 0;

    StringBuilder path = new StringBuilder("C:\\Users");

    ListMultimap<String, String> map = ArrayListMultimap.create();

    for (i = 3; s[i] != null; i += 2) {
        /*if (i == 3) {//from   ww w .j  av  a  2  s. c o m
            s[3] = s[3].substring(1, s[3].length());
        }*/
        if (s[i + 1].toLowerCase().contains("varchar") || s[i + 1].toLowerCase().contains("int")) {
            map.put("attribute", s[i] + "-" + s[i + 1]);
            map.put(s[i], null);
        } else {
            map.clear();
            throw new Exception("SQL Syntax error! Unknown type...");
        }
        //System.out.println("attribute: "+s[i]);
    }
    /*       for (String value : myMultimap.values()) {
      System.out.println(value);
    }*/
    //System.out.println(i);
    List<String> Values = map.get("attribute");
    System.out.println(Values);

    return map;

}

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

private void computeNewViolationsPerSeverity(DecoratorContext context) {
    ListMultimap<RulePriority, Violation> violationsPerSeverities = ArrayListMultimap.create();
    for (Violation violation : context.getViolations()) {
        violationsPerSeverities.put(violation.getSeverity(), violation);
    }/*from   ww w  .  j a  v  a2  s  . com*/

    for (RulePriority severity : RulePriority.values()) {
        Metric metric = severityToMetric(severity);
        Measure measure = new Measure(metric);
        for (PastSnapshot pastSnapshot : timeMachineConfiguration.getProjectPastSnapshots()) {
            int variationIndex = pastSnapshot.getIndex();
            int count = countViolations(violationsPerSeverities.get(severity), pastSnapshot.getTargetDate());
            Collection<Measure> children = context.getChildrenMeasures(MeasuresFilters.metric(metric));
            double sum = MeasureUtils.sumOnVariation(true, variationIndex, children) + count;
            measure.setVariation(variationIndex, sum);
        }
        context.saveMeasure(measure);
    }
}

From source file:eu.esdihumboldt.cst.functions.groovy.GroovyGreedyTransformation.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 {
    // determine if instances should be used in variables or their values
    boolean useInstanceVariables = getOptionalParameter(PARAM_INSTANCE_VARIABLES, Value.of(false))
            .as(Boolean.class);

    // instance builder
    InstanceBuilder builder = GroovyTransformation.createBuilder(resultProperty);

    // create the script binding
    Binding binding = createGroovyBinding(variables.get(ENTITY_VARIABLE),
            getCell().getSource().get(ENTITY_VARIABLE), getCell(), getTypeCell(), builder, useInstanceVariables,
            log, getExecutionContext(), resultProperty.getDefinition().getPropertyType());

    Object result;/*  w w w  .j a v a  2  s. co m*/
    try {
        GroovyService service = getExecutionContext().getService(GroovyService.class);
        Script groovyScript = GroovyUtil.getScript(this, binding, service);

        // evaluate the script
        result = GroovyTransformation.evaluate(groovyScript, builder,
                resultProperty.getDefinition().getPropertyType(), service, log);
    } catch (NoResultException | TransformationException e) {
        throw e;
    } catch (Throwable e) {
        throw new TransformationException("Error evaluating the cell script", e);
    }

    if (result == null) {
        throw new NoResultException();
    }
    return result;
}

From source file:com.android.ide.common.res2.AbstractResourceRepository.java

@NonNull
private List<ResourceFile> getMatchingFiles(@NonNull String name, @NonNull ResourceType type,
        @NonNull FolderConfiguration config, @NonNull Set<String> seenNames, int depth) {
    assert !seenNames.contains(name);
    if (depth >= MAX_RESOURCE_INDIRECTION) {
        return Collections.emptyList();
    }/*from   ww w.jav a  2  s  . co  m*/
    List<ResourceFile> output;
    synchronized (ITEM_MAP_LOCK) {
        ListMultimap<String, ResourceItem> typeItems = getMap(type, false);
        if (typeItems == null) {
            return Collections.emptyList();
        }
        seenNames.add(name);
        output = new ArrayList<ResourceFile>();
        List<ResourceItem> matchingItems = typeItems.get(name);
        List<Configurable> matches = config.findMatchingConfigurables(matchingItems);
        for (Configurable conf : matches) {
            ResourceItem match = (ResourceItem) conf;
            // if match is an alias, check if the name is in seen names.
            ResourceValue resourceValue = match.getResourceValue(isFramework());
            if (resourceValue != null) {
                String value = resourceValue.getValue();
                if (value != null && value.startsWith(PREFIX_RESOURCE_REF)) {
                    ResourceUrl url = ResourceUrl.parse(value);
                    if (url != null && url.type == type && url.framework == isFramework()) {
                        if (!seenNames.contains(url.name)) {
                            // This resource alias needs to be resolved again.
                            output.addAll(getMatchingFiles(url.name, type, config, seenNames, depth + 1));
                        }
                        continue;
                    }
                }
            }
            output.add(match.getSource());

        }
    }

    return output;
}

From source file:de.metas.ui.web.pporder.PPOrderLinesLoader.java

/**
 * Loads {@link PPOrderLinesViewData}s.//from  ww w  . j  a  v a  2 s.c o  m
 *
 * @param viewId viewId to be set to newly created {@link PPOrderLineRow}s.
 */
public PPOrderLinesViewData retrieveData(final PPOrderId ppOrderId) {
    final I_PP_Order ppOrder = Services.get(IPPOrderDAO.class).getById(ppOrderId, I_PP_Order.class);

    final int mainProductBOMLineId = 0;
    final ListMultimap<Integer, I_PP_Order_Qty> ppOrderQtysByBOMLineId = ppOrderQtyDAO
            .streamOrderQtys(ppOrderId).collect(GuavaCollectors.toImmutableListMultimap(ppOrderQty -> Util
                    .firstGreaterThanZero(ppOrderQty.getPP_Order_BOMLine_ID(), mainProductBOMLineId)));

    final ImmutableList.Builder<PPOrderLineRow> records = ImmutableList.builder();

    // Main product
    final PPOrderLineRow rowForMainProduct = createRowForMainProduct(ppOrder,
            ppOrderQtysByBOMLineId.get(mainProductBOMLineId));
    records.add(rowForMainProduct);

    // BOM lines
    final List<PPOrderLineRow> bomLineRows = createRowsForBomLines(ppOrder, ppOrderQtysByBOMLineId);
    records.addAll(bomLineRows);

    // Source HUs
    final WarehouseId warehouseId = WarehouseId.ofRepoId(ppOrder.getM_Warehouse_ID());
    final List<PPOrderLineRow> sourceHuRowsForIssueProducts = createRowsForIssueProductSourceHUs(warehouseId,
            bomLineRows);
    records.addAll(sourceHuRowsForIssueProducts);

    final PPOrderPlanningStatus planningStatus = PPOrderPlanningStatus.ofCode(ppOrder.getPlanningStatus());
    return new PPOrderLinesViewData(extractDescription(ppOrder), planningStatus, records.build());
}