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:org.sonar.server.qualitygate.changeevent.QGChangeEventListenersImpl.java

@Override
public void broadcastOnIssueChange(List<DefaultIssue> issues, Collection<QGChangeEvent> changeEvents) {
    if (listeners.length == 0 || issues.isEmpty() || changeEvents.isEmpty()) {
        return;/*w w  w. j  a va2s.  co  m*/
    }

    try {
        Multimap<String, QGChangeEvent> eventsByComponentUuid = changeEvents.stream()
                .collect(MoreCollectors.index(t -> t.getProject().uuid()));
        Multimap<String, DefaultIssue> issueByComponentUuid = issues.stream()
                .collect(MoreCollectors.index(DefaultIssue::projectUuid));

        issueByComponentUuid.asMap().forEach((componentUuid, value) -> {
            Collection<QGChangeEvent> qgChangeEvents = eventsByComponentUuid.get(componentUuid);
            if (!qgChangeEvents.isEmpty()) {
                Set<ChangedIssue> changedIssues = value.stream().map(ChangedIssueImpl::new).collect(toSet());
                qgChangeEvents.forEach(changeEvent -> Arrays.stream(listeners)
                        .forEach(listener -> broadcastTo(changedIssues, changeEvent, listener)));
            }
        });
    } catch (Error e) {
        LOG.warn(format("Broadcasting to listeners failed for %s events", changeEvents.size()), e);
    }
}

From source file:org.onosproject.segmentrouting.web.McastWebResource.java

private ObjectNode json(Multimap<ConnectPoint, List<ConnectPoint>> mcastTree) {
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode jsonSinks = mapper.createObjectNode();
    mcastTree.asMap().forEach((sink, paths) -> {
        ArrayNode jsonPaths = mapper.createArrayNode();
        paths.forEach(path -> {/*from w  ww  .  j  ava2  s  . c om*/
            ArrayNode jsonPath = mapper.createArrayNode();
            path.forEach(connectPoint -> jsonPath.add(connectPoint.toString()));
            jsonPaths.addPOJO(jsonPath);
        });
        jsonSinks.putPOJO(sink.toString(), jsonPaths);
    });
    return jsonSinks;
}

From source file:org.sonar.plugins.core.notifications.violations.NewViolationsOnFirstDifferentialPeriod.java

@Override
public void dispatch(Notification notification, Context context) {
    int projectId = Integer.parseInt(notification.getFieldValue("projectId"));
    Multimap<String, NotificationChannel> subscribedRecipients = notificationManager
            .findSubscribedRecipientsForDispatcher(this, projectId);

    for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap()
            .entrySet()) {/*from w w w.  j a  v a2 s. com*/
        String userLogin = channelsByRecipients.getKey();
        for (NotificationChannel channel : channelsByRecipients.getValue()) {
            context.addUser(userLogin, channel);
        }
    }
}

From source file:com.facebook.presto.raptor.storage.TemporalCompactionSetCreator.java

@Override
public Set<CompactionSet> createCompactionSets(long tableId, Set<ShardMetadata> shardMetadata) {
    if (shardMetadata.isEmpty()) {
        return ImmutableSet.of();
    }/*ww  w  .  ja va2  s.  c o  m*/

    ImmutableSet.Builder<CompactionSet> compactionSets = ImmutableSet.builder();
    // don't compact shards across days
    Multimap<Long, ShardMetadata> shardsByDays = getShardsByDays(shardMetadata, type);

    for (Collection<ShardMetadata> shardSet : shardsByDays.asMap().values()) {
        List<ShardMetadata> shards = shardSet.stream()
                .filter(shard -> shard.getUncompressedSize() < maxShardSizeBytes)
                .filter(shard -> shard.getRowCount() < maxShardRows).sorted(new ShardSorter())
                .collect(toList());

        long consumedBytes = 0;
        long consumedRows = 0;
        ImmutableSet.Builder<ShardMetadata> shardsToCompact = ImmutableSet.builder();

        for (ShardMetadata shard : shards) {
            if (((consumedBytes + shard.getUncompressedSize()) > maxShardSizeBytes)
                    || (consumedRows + shard.getRowCount() > maxShardRows)) {
                // Finalize this compaction set, and start a new one for the rest of the shards
                compactionSets.add(new CompactionSet(tableId, shardsToCompact.build()));
                shardsToCompact = ImmutableSet.builder();
                consumedBytes = 0;
                consumedRows = 0;
            }
            shardsToCompact.add(shard);
            consumedBytes += shard.getUncompressedSize();
            consumedRows += shard.getRowCount();
        }
        if (!shardsToCompact.build().isEmpty()) {
            // create compaction set for the remaining shards of this day
            compactionSets.add(new CompactionSet(tableId, shardsToCompact.build()));
        }
    }
    return compactionSets.build();
}

From source file:org.jclouds.joyent.cloudapi.v6_5.compute.JoyentCloudComputeService.java

@Override
protected void cleanUpIncidentalResourcesOfDeadNodes(Set<? extends NodeMetadata> deadNodes) {
    Multimap<String, String> zoneToZoneAndGroupNames = orphanedGroupsByDatacenterId.apply(deadNodes);
    for (Map.Entry<String, Collection<String>> entry : zoneToZoneAndGroupNames.asMap().entrySet()) {
        cleanupOrphanedKeysInZone(ImmutableSet.copyOf(entry.getValue()), entry.getKey());
    }//w w w . j a va2  s.  c  o m
}

From source file:org.tensorics.core.tensor.TensorPair.java

/**
 * Extracts pairs of values, according to the given multimap of position pairs and returns them again as a multimap.
 * The map will contain the same keys as the input map and as values all the values indexed by the given position
 * pairs (values of the input map). It is assumed that values exist in the tensors for all given positions. If this
 * is not the case, then an exception will be thrown. The returned value will be a {@link ListMultimap}, because it
 * is easily possible that the returned value pairs are the same for different keys.
 * //from   w  w w.  ja va  2s  .  co m
 * @param positionPairs a multimap K: pairs of positions for which to retrieve the values
 * @return a multimap K: pairs of values, extracted from the tensor pair
 */
public <K> ListMultimap<K, ValuePair<V>> mapValues(Multimap<K, PositionPair> positionPairs) {
    ImmutableListMultimap.Builder<K, ValuePair<V>> builder = ImmutableListMultimap.builder();
    for (Entry<K, Collection<PositionPair>> entry : positionPairs.asMap().entrySet()) {
        builder.putAll(entry.getKey(), getAll(entry.getValue()));
    }
    return builder.build();
}

From source file:com.facebook.presto.execution.scheduler.SourcePartitionedScheduler.java

private Set<RemoteTask> assignSplits(Multimap<Node, Split> splitAssignment) {
    ImmutableSet.Builder<RemoteTask> newTasks = ImmutableSet.builder();
    for (Entry<Node, Collection<Split>> taskSplits : splitAssignment.asMap().entrySet()) {
        newTasks.addAll(stage.scheduleSplits(taskSplits.getKey(), taskSplits.getValue()));
        scheduledNodes.add(taskSplits.getKey().getNodeIdentifier());
    }/*from w w w  . j  ava2  s. c o m*/
    return newTasks.build();
}

From source file:org.sonar.plugins.core.notifications.alerts.NewAlerts.java

@Override
public void dispatch(Notification notification, Context context) {
    String projectIdString = notification.getFieldValue("projectId");
    if (projectIdString != null) {
        int projectId = Integer.parseInt(projectIdString);
        Multimap<String, NotificationChannel> subscribedRecipients = notifications
                .findSubscribedRecipientsForDispatcher(this, projectId);

        for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients
                .asMap().entrySet()) {/*from   w ww.  j av a2  s.c  o  m*/
            String userLogin = channelsByRecipients.getKey();
            for (NotificationChannel channel : channelsByRecipients.getValue()) {
                context.addUser(userLogin, channel);
            }
        }
    }
}

From source file:org.sonar.server.event.NewAlerts.java

@Override
public void dispatch(Notification notification, Context context) {
    String projectUuid = notification.getFieldValue("projectUuid");
    if (projectUuid != null) {
        Multimap<String, NotificationChannel> subscribedRecipients = notifications
                .findSubscribedRecipientsForDispatcher(this, projectUuid);

        for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients
                .asMap().entrySet()) {/*from w  ww  .  j  a v a 2  s.c  o m*/
            String userLogin = channelsByRecipients.getKey();
            for (NotificationChannel channel : channelsByRecipients.getValue()) {
                context.addUser(userLogin, channel);
            }
        }
    }
}

From source file:org.apache.samza.execution.StreamManager.java

public void createStreams(List<StreamSpec> streams) {
    Multimap<String, StreamSpec> streamsGroupedBySystem = HashMultimap.create();
    streams.forEach(streamSpec -> streamsGroupedBySystem.put(streamSpec.getSystemName(), streamSpec));

    for (Map.Entry<String, Collection<StreamSpec>> entry : streamsGroupedBySystem.asMap().entrySet()) {
        String systemName = entry.getKey();
        SystemAdmin systemAdmin = sysAdmins.get(systemName);

        for (StreamSpec stream : entry.getValue()) {
            LOGGER.info("Creating stream {} with partitions {} on system {}",
                    new Object[] { stream.getPhysicalName(), stream.getPartitionCount(), systemName });
            systemAdmin.createStream(stream);
        }/*from   w  w  w  .j  a v a2s  .c o m*/
    }
}