Example usage for com.google.common.collect Multimaps asMap

List of usage examples for com.google.common.collect Multimaps asMap

Introduction

In this page you can find the example usage for com.google.common.collect Multimaps asMap.

Prototype

@Beta
public static <K, V> Map<K, Collection<V>> asMap(Multimap<K, V> multimap) 

Source Link

Document

Returns Multimap#asMap multimap.asMap() .

Usage

From source file:com.opentable.jaxrs.JaxRsClientFactory.java

/**
 * Register many features at once.  Mostly a convenience for DI environments.
 *//*from   w  w w . j  a va 2 s . c  o  m*/
public synchronized JaxRsClientFactory addFeatureMap(SetMultimap<JaxRsFeatureGroup, Feature> map) {
    return addFeatureMap(Multimaps.asMap(map));
}

From source file:org.sonar.java.checks.OverwrittenKeyCheck.java

private void reportOverwrittenKeys(ListMultimap<CollectionAndKey, Tree> usedKeys) {
    Multimaps.asMap(usedKeys).forEach((key, trees) -> {
        if (trees.size() > 1) {
            Tree firstUse = trees.get(0);
            Tree firstOverwrite = trees.get(1);
            List<Tree> rest = trees.subList(2, trees.size());
            reportIssue(firstOverwrite,/*from   w  w  w.j  a  va2 s  .  co  m*/
                    "Verify this is the " + key.indexOrKey() + " that was intended; it was already set before.",
                    secondaryLocations(key, firstUse, rest), 0);
        }
    });
}

From source file:dagger.android.processor.DuplicateAndroidInjectorsChecker.java

private void validateMapKeyUniqueness(Binding dispatchingAndroidInjector, BindingGraph graph,
        DiagnosticReporter diagnosticReporter) {
    ImmutableSet<Binding> injectorFactories = injectorMapDependencies(dispatchingAndroidInjector, graph)
            .flatMap(injectorFactoryMap -> graph.requestedBindings(injectorFactoryMap).stream())
            .collect(collectingAndThen(toList(), ImmutableSet::copyOf));

    ImmutableListMultimap.Builder<String, Binding> mapKeyIndex = ImmutableListMultimap.builder();
    for (Binding injectorFactory : injectorFactories) {
        AnnotationMirror mapKey = mapKey(injectorFactory).get();
        Optional<String> injectedType = injectedTypeFromMapKey(mapKey);
        if (injectedType.isPresent()) {
            mapKeyIndex.put(injectedType.get(), injectorFactory);
        } else {/*from   ww  w  . jav  a  2  s .  c  o m*/
            diagnosticReporter.reportBinding(ERROR, injectorFactory, "Unrecognized class: %s", mapKey);
        }
    }

    Map<String, List<Binding>> duplicates = Maps.filterValues(Multimaps.asMap(mapKeyIndex.build()),
            bindings -> bindings.size() > 1);
    if (!duplicates.isEmpty()) {
        StringBuilder errorMessage = new StringBuilder(
                "Multiple injector factories bound for the same type:\n");
        Formatter formatter = new Formatter(errorMessage);
        duplicates.forEach((injectedType, duplicateFactories) -> {
            formatter.format("  %s:\n", injectedType);
            duplicateFactories.forEach(duplicate -> formatter.format("    %s\n", duplicate));
        });
        diagnosticReporter.reportBinding(ERROR, dispatchingAndroidInjector, errorMessage.toString());
    }
}

From source file:com.palantir.atlasdb.keyvalue.rdbms.utils.AtlasSqlUtils.java

public static <T> List<RowResult<Set<T>>> cellsToRows(ListMultimap<Cell, T> cells) {
    List<RowResult<Set<T>>> result = Lists.newArrayList();
    NavigableMap<byte[], SortedMap<byte[], List<T>>> s = Cells.breakCellsUpByRow(Multimaps.asMap(cells));
    for (Entry<byte[], SortedMap<byte[], List<T>>> e : s.entrySet()) {
        result.add(RowResult.create(e.getKey(), listSortedMapToSetSortedMap(e.getValue())));
    }/*  w  ww . ja v  a  2  s .  c  o  m*/
    return result;
}

From source file:springfox.documentation.spring.web.scanners.ApiDocumentationScanner.java

private Collection<? extends ApiListingReference> apiListingReferences(Multimap<String, ApiListing> apiListings,
        DocumentationContext context) {/*ww  w. j a  v a  2s  . c  o m*/
    Map<String, Collection<ApiListing>> grouped = Multimaps.asMap(apiListings);
    return FluentIterable.from(grouped.entrySet()).transform(toApiListingReference(context)).toSet();
}

From source file:com.adobe.acs.commons.httpcache.store.mem.impl.MemCachePersistenceObject.java

/**
 * Get the header in multimap format.//from   w  w  w.java 2s  .c  o  m
 *
 * @return Returned in <code>Map<String, List<String>></code> format.
 */
public Map<String, List<String>> getHeaders() {
    Map<String, List<String>> map = new HashMap<String, List<String>>();

    // Convert com.google.common.collect.AbstractMapBasedMultimap$WrappedSet to List<String> value to avoid cast
    // exception
    for (Map.Entry<String, Collection<String>> entry : Multimaps.asMap(headers).entrySet()) {
        map.put(entry.getKey(), new ArrayList<String>(entry.getValue()));
    }

    return map;
}

From source file:org.sonar.server.qualityprofile.DefinedQProfileRepositoryImpl.java

private static Map<String, List<DefinedQProfile>> toQualityProfilesByLanguage(
        ListMultimap<String, RulesProfile> rulesProfilesByLanguage) {
    Map<String, List<DefinedQProfile.Builder>> buildersByLanguage = Multimaps.asMap(rulesProfilesByLanguage)
            .entrySet().stream().collect(MoreCollectors.uniqueIndex(Map.Entry::getKey,
                    DefinedQProfileRepositoryImpl::toQualityProfileBuilders));
    return buildersByLanguage.entrySet().stream()
            .filter(DefinedQProfileRepositoryImpl::ensureAtMostOneDeclaredDefault)
            .filter(entry -> ensureParentExists(entry.getKey(), entry.getValue()))
            .collect(MoreCollectors.uniqueIndex(Map.Entry::getKey, entry -> toQualityProfiles(entry.getValue()),
                    buildersByLanguage.size()));
}

From source file:org.nmdp.service.epitope.service.EpitopeServiceImpl.java

/**
 * {@inheritDoc}//from w  w  w  .j  av a2s . co m
 */
@Override
public Map<Allele, Integer> getGroupsForAllAlleles() {
    return Maps.transformValues(Multimaps.asMap(alleleGroupMap), l -> l.get(0));
}

From source file:de.bund.bfr.knime.nls.NlsUtils.java

public static Map<String, List<Double>> getConditionValues(BufferedDataTable table, String id, Function f) {
    ListMultimap<String, Double> values = ArrayListMultimap.create();

    for (DataRow row : getRowsById(table, id)) {
        Map<String, Double> newValues = new LinkedHashMap<>();

        for (String var : f.getIndependentVariables()) {
            newValues.put(var, IO.getDouble(row.getCell(table.getSpec().findColumnIndex(var))));
        }/*from   w  ww.  j ava 2 s  . c o m*/

        if (newValues.values().stream().allMatch(v -> v != null && Double.isFinite(v))) {
            newValues.forEach((var, value) -> values.put(var, value));
        }
    }

    return Multimaps.asMap(values);
}

From source file:org.pentaho.di.trans.dataservice.optimization.paramgen.AutoParameterGenerationService.java

private List<PushDownOptimizationMeta> generateOptimizationList(SourceLineageMap sourceLineageMap) {
    Map<String, Set<List<StepFieldOperations>>> inputSteps = Multimaps.asMap(sourceLineageMap);
    List<PushDownOptimizationMeta> optimizationList = Lists.newArrayListWithExpectedSize(inputSteps.size());
    for (Map.Entry<String, Set<List<StepFieldOperations>>> inputStepLineage : inputSteps.entrySet()) {
        String inputStep = inputStepLineage.getKey();
        Set<List<StepFieldOperations>> lineageSet = inputStepLineage.getValue();
        PushDownOptimizationMeta pushDownOptimizationMeta = new PushDownOptimizationMeta();
        ParameterGeneration parameterGeneration = serviceProvider.createPushDown();
        pushDownOptimizationMeta.setName(MessageFormat.format("Parameter Generator: {0}", inputStep));
        pushDownOptimizationMeta.setStepName(inputStep);
        pushDownOptimizationMeta.setType(parameterGeneration);
        parameterGeneration/* w  w  w  .  j  ava  2 s  .c om*/
                .setParameterName("DATA_SERVICE_QUERY_" + inputStep.replaceAll("\\s", "_").toUpperCase());
        for (List<StepFieldOperations> fieldLineage : lineageSet) {
            StepFieldOperations origin = fieldLineage.get(0);
            StepFieldOperations last = Iterables.getLast(fieldLineage);
            parameterGeneration.createFieldMapping(last.getFieldName(), origin.getFieldName());
        }
        optimizationList.add(pushDownOptimizationMeta);
    }
    return optimizationList;
}