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

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

Introduction

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

Prototype

Map<K, Collection<V>> asMap();

Source Link

Document

Returns a view of this multimap as a Map from each distinct key to the nonempty collection of that key's associated values.

Usage

From source file:com.metamx.http.client.Request.java

public Request addHeaderValues(Multimap<String, String> inHeaders) {
    for (Map.Entry<String, Collection<String>> entry : inHeaders.asMap().entrySet()) {
        this.addHeaderValues(entry.getKey(), entry.getValue());
    }//w  w w . j  ava 2  s.c o m
    return this;
}

From source file:com.github.drbookings.ui.controller.BookingEntryMonthBins.java

@Override
public Collection<BookingEntryBin<YearMonth>> getBins() {
    Multimap<YearMonth, BookingEntry> result = ArrayListMultimap.create();
    elements.forEach(e -> result.put(YearMonth.from(e.getDate()), e));
    Collection<BookingEntryBin<YearMonth>> result2 = new ArrayList<>();
    result.asMap().forEach((k, v) -> result2.add(new BookingEntryBin<>(k, v)));
    return result2;
}

From source file:org.thiesen.jiffs.jobs.clusterer.Clusterer.java

private void storeClusters(Multimap<Long, String> clusters) {
    System.out.println("Found " + clusters.keySet().size() + " clusters");

    for (final Entry<Long, Collection<String>> entry : clusters.asMap().entrySet()) {
        final StoryClusterDBO clusterDBO = new StoryClusterDBO();

        clusterDBO.setCreatedAt(new DateTime());
        clusterDBO.setStoryUris(Lists.newArrayList(entry.getValue()));

        _storyClusterDAO.insert(clusterDBO);

    }// w ww.  ja v  a 2s  .c  o m

}

From source file:edu.buaa.satla.analysis.cfa.CProgramScope.java

private static Map<String, CType> extractTypeDefs(FluentIterable<CTypeDeclaration> pTypeDcls,
        LogManager pLogger) {//  w ww .ja  v  a 2 s.  co  m
    FluentIterable<CTypeDefDeclaration> plainTypeDefs = pTypeDcls.filter(CTypeDefDeclaration.class);

    // Construct multimap that may contain duplicates
    Multimap<String, CTypeDefDeclaration> typeDefDeclarationsMap = plainTypeDefs
            .index(new Function<CTypeDefDeclaration, String>() {

                @Override
                public String apply(CTypeDefDeclaration pArg0) {
                    return pArg0.getQualifiedName();
                }

            });

    // Get unique type defs
    Map<String, CType> uniqueTypeDefs = Maps.newHashMap();

    for (Map.Entry<String, Collection<CTypeDefDeclaration>> typeDefEntry : typeDefDeclarationsMap.asMap()
            .entrySet()) {
        String qualifiedName = typeDefEntry.getKey();
        FluentIterable<CType> types = from(typeDefEntry.getValue())
                .transform(new Function<CTypeDefDeclaration, CType>() {

                    @Override
                    public CType apply(CTypeDefDeclaration pArg0) {
                        return pArg0.getType();
                    }

                });
        putIfUnique(uniqueTypeDefs, qualifiedName, types, pLogger);
    }

    return Collections.unmodifiableMap(uniqueTypeDefs);
}

From source file:edu.buaa.satla.analysis.cfa.CProgramScope.java

private static Map<String, CComplexType> extractTypes(FluentIterable<? extends CSimpleDeclaration> pDcls,
        LogManager pLogger) {/*from www  .j  a v  a  2s. c  o  m*/

    // Collect all types
    TypeCollector typeCollector = new TypeCollector();
    for (CSimpleDeclaration declaration : pDcls) {
        declaration.getType().accept(typeCollector);
    }

    // Construct multimap that may contain duplicates
    Multimap<String, CComplexType> typesMap = from(typeCollector.getCollectedTypes()).filter(CComplexType.class)
            .index(new Function<CComplexType, String>() {

                @Override
                public String apply(CComplexType pArg0) {
                    return pArg0.getQualifiedName();
                }

            });

    // Get unique types
    Map<String, CComplexType> uniqueTypes = Maps.newHashMap();

    for (Map.Entry<String, Collection<CComplexType>> typeEntry : typesMap.asMap().entrySet()) {
        String qualifiedName = typeEntry.getKey();
        Collection<CComplexType> types = typeEntry.getValue();
        putIfUnique(uniqueTypes, qualifiedName, types, pLogger);
    }

    return Collections.unmodifiableMap(uniqueTypes);
}

From source file:org.jclouds.ec2.compute.functions.PresentInstances.java

@Override
public Set<RunningInstance> apply(Set<RegionAndName> regionAndIds) {
    if (checkNotNull(regionAndIds, "regionAndIds").isEmpty())
        return ImmutableSet.of();
    Builder<RunningInstance> builder = ImmutableSet.<RunningInstance>builder();
    Multimap<String, String> regionToInstanceIds = transformValues(index(regionAndIds, regionFunction()),
            nameFunction());//from   w  w w.j  a v a  2s  .com
    for (Map.Entry<String, Collection<String>> entry : regionToInstanceIds.asMap().entrySet()) {
        String region = entry.getKey();
        Collection<String> instanceIds = entry.getValue();
        logger.trace("looking for instances %s in region %s", instanceIds, region);
        builder.addAll(concat(client.getInstanceApi().get().describeInstancesInRegion(region,
                toArray(instanceIds, String.class))));
    }
    return builder.build();
}

From source file:org.jclouds.aws.ec2.compute.functions.PresentSpotRequestsAndInstances.java

protected Set<RunningInstance> getSpots(Set<RegionAndName> regionAndIds) {
    Builder<RunningInstance> builder = ImmutableSet.<RunningInstance>builder();
    Multimap<String, String> regionToSpotIds = transformValues(index(regionAndIds, regionFunction()),
            nameFunction());//from   w w  w.  java2 s  .  c o m
    for (Map.Entry<String, Collection<String>> entry : regionToSpotIds.asMap().entrySet()) {
        String region = entry.getKey();
        Collection<String> spotIds = entry.getValue();
        logger.trace("looking for spots %s in region %s", spotIds, region);
        builder.addAll(transform(client.getSpotInstanceApi().get().describeSpotInstanceRequestsInRegion(region,
                toArray(spotIds, String.class)), spotConverter));
    }
    return builder.build();
}

From source file:org.sonar.plugins.core.issue.notification.NewIssuesNotificationDispatcher.java

@Override
public void dispatch(Notification notification, Context context) {
    String projectKey = notification.getFieldValue("projectKey");
    Multimap<String, NotificationChannel> subscribedRecipients = manager.findNotificationSubscribers(this,
            projectKey);//from  w ww.  jav  a2s  .c  o  m

    for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap()
            .entrySet()) {
        String userLogin = channelsByRecipients.getKey();
        for (NotificationChannel channel : channelsByRecipients.getValue()) {
            context.addUser(userLogin, channel);
        }
    }
}

From source file:org.lightjason.agentspeak.action.builtin.collection.multimap.CGetSingle.java

@Override
protected final void apply(final boolean p_parallel, @Nonnull final Multimap<Object, Object> p_instance,
        @Nonnull final Object p_key, @Nonnull final List<ITerm> p_return) {
    p_return.add(CRawTerm
            .from(p_parallel ? Collections.synchronizedList(new ArrayList<>(p_instance.asMap().get(p_key)))
                    : new ArrayList<>(p_instance.asMap().get(p_key))));
}

From source file:org.eclipse.xtext.builder.standalone.incremental.ResourceURICollector.java

protected Set<URI> collectResources(final Iterable<URI> roots, final Set<String> fileExtensions) {
    Iterable<String> _plus = Iterables.<String>concat(fileExtensions,
            Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("java")));
    final Set<String> extensions = IterableExtensions.<String>toSet(_plus);
    PathTraverser _pathTraverser = new PathTraverser();
    final Function1<URI, String> _function = (URI it) -> {
        return it.toFileString();
    };//from  ww w .ja v a2s.  com
    Iterable<String> _map = IterableExtensions.<URI, String>map(roots, _function);
    List<String> _list = IterableExtensions.<String>toList(_map);
    final Predicate<URI> _function_1 = (URI it) -> {
        String _fileExtension = it.fileExtension();
        return extensions.contains(_fileExtension);
    };
    final Multimap<String, URI> modelsFound = _pathTraverser.resolvePathes(_list, _function_1);
    Map<String, Collection<URI>> _asMap = modelsFound.asMap();
    final BiConsumer<String, Collection<URI>> _function_2 = (String path, Collection<URI> resource) -> {
        final File file = new File(path);
        if ((((resource != null) && (!file.isDirectory())) && file.getName().endsWith(".jar"))) {
            this.registerBundle(file);
        }
    };
    _asMap.forEach(_function_2);
    Collection<URI> _values = modelsFound.values();
    return IterableExtensions.<URI>toSet(_values);
}