List of usage examples for com.google.common.collect SetMultimap asMap
@Override Map<K, Collection<V>> asMap();
Note: The returned map's values are guaranteed to be of type Set .
From source file:org.sonar.server.notification.NotificationService.java
private static void dispatch(Notification notification, SetMultimap<String, NotificationChannel> recipients) { for (Map.Entry<String, Collection<NotificationChannel>> entry : recipients.asMap().entrySet()) { String username = entry.getKey(); Collection<NotificationChannel> userChannels = entry.getValue(); LOG.debug("For user {} via {}", username, userChannels); for (NotificationChannel channel : userChannels) { try { channel.deliver(notification, username); } catch (Exception e) { // catch all exceptions in order to deliver via other channels LOG.warn("Unable to deliver notification " + notification + " for user " + username + " via " + channel, e);//from ww w.j a va2 s.c om } } } }
From source file:com.google.caliper.runner.FullCartesianExperimentSelector.java
protected static <T> Set<List<T>> cartesian(SetMultimap<String, T> multimap) { @SuppressWarnings({ "unchecked", "rawtypes" }) // promised by spec ImmutableMap<String, Set<T>> paramsAsMap = (ImmutableMap) multimap.asMap(); return Sets.cartesianProduct(paramsAsMap.values().asList()); }
From source file:com.datatorrent.contrib.kafka.KafkaMetadataUtil.java
/** * @param brokers in multiple clusters, keyed by cluster id * @param topic/*from w ww .ja v a 2 s .c om*/ * @return Get the partition metadata list for the specific topic via the brokers * null if topic is not found */ public static Map<String, List<PartitionMetadata>> getPartitionsForTopic(SetMultimap<String, String> brokers, final String topic) { return Maps.transformEntries(brokers.asMap(), new EntryTransformer<String, Collection<String>, List<PartitionMetadata>>() { @Override public List<PartitionMetadata> transformEntry(String key, Collection<String> bs) { return getPartitionsForTopic(new HashSet<String>(bs), topic); } }); }
From source file:com.addthis.hydra.query.MeshFileRefCache.java
/** * This method filters the file references to ensure that only valid file references are returned. * <p/>/*ww w . jav a 2s.com*/ * The filter checks for two things. * <p/> * <ol> * <li>the last modified date for each file for the same task should be the same, if not it will take the * newest file</li> * <li>the size of the files should be equal, if not, take the files with the largest known size</li> * </ol> * * @param fileRefDataSet - the original unfiltered file reference set * @return - filtered file reference map containing only valid file references */ @Nonnull protected static SetMultimap<Integer, FileReference> filterFileReferences( @Nonnull SetMultimap<Integer, FileReference> fileRefDataSet) { if (fileRefDataSet.isEmpty()) { return fileRefDataSet; } int baseKeySetSize = fileRefDataSet.keySet().size(); SetMultimap<Integer, FileReference> filteredFileReferenceSet = HashMultimap.create(baseKeySetSize, fileRefDataSet.size() / baseKeySetSize); for (Map.Entry<Integer, Collection<FileReference>> entry : fileRefDataSet.asMap().entrySet()) { int key = entry.getKey(); final Collection<FileReference> fileReferences = entry.getValue(); long mostRecentTime = -1; for (FileReference fileReference : fileReferences) { if ((mostRecentTime < 0) || (fileReference.lastModified > mostRecentTime)) { mostRecentTime = fileReference.lastModified; } } final long mostRecentTimeF = mostRecentTime; Predicate<FileReference> isMostRecent = input -> (input != null) && (input.lastModified == mostRecentTimeF); Collection<FileReference> filteredFileReferences = Collections2.filter(fileReferences, isMostRecent); filteredFileReferenceSet.putAll(key, filteredFileReferences); } return filteredFileReferenceSet; }
From source file:omero.cmd.graphs.GraphUtil.java
/** * Make a copy of a multimap with the full class names in the keys replaced by the simple class names * and the ordering of the values preserved. * @param entriesByFullName a multimap//from w ww .j av a 2 s .c o m * @return a new multimap with the same contents, except for the package name having been trimmed off each key */ static <X> SetMultimap<String, X> trimPackageNames(SetMultimap<String, X> entriesByFullName) { final SetMultimap<String, X> entriesBySimpleName = LinkedHashMultimap.create(); for (final Map.Entry<String, Collection<X>> entriesForOneClass : entriesByFullName.asMap().entrySet()) { final String fullClassName = entriesForOneClass.getKey(); final String simpleClassName = fullClassName.substring(fullClassName.lastIndexOf('.') + 1); final Collection<X> values = entriesForOneClass.getValue(); entriesBySimpleName.putAll(simpleClassName, values); } return entriesBySimpleName; }
From source file:omero.cmd.graphs.GraphUtil.java
/** * Rearrange the deletion targets such that original files are listed before their containing directories. * @param session the Hibernate session/* w ww . j av a2 s . c om*/ * @param targetObjects the objects that are to be deleted * @return the given target objects with any original files suitably ordered for deletion */ static SetMultimap<String, Long> arrangeDeletionTargets(Session session, SetMultimap<String, Long> targetObjects) { if (targetObjects.get(OriginalFile.class.getName()).size() < 2) { /* no need to rearrange anything, as there are not multiple original files */ return targetObjects; } final SetMultimap<String, Long> orderedIds = LinkedHashMultimap.create(); for (final Map.Entry<String, Collection<Long>> targetObjectsByClass : targetObjects.asMap().entrySet()) { final String className = targetObjectsByClass.getKey(); Collection<Long> ids = targetObjectsByClass.getValue(); if (OriginalFile.class.getName().equals(className)) { final Collection<Collection<Long>> sortedIds = ModelObjectSequencer.sortOriginalFileIds(session, ids); ids = new ArrayList<Long>(ids.size()); for (final Collection<Long> idBatch : sortedIds) { ids.addAll(idBatch); } } orderedIds.putAll(className, ids); } return orderedIds; }
From source file:co.cask.cdap.etl.common.SetMultimapCodec.java
@Override public JsonElement serialize(SetMultimap<K, V> src, Type typeOfSrc, JsonSerializationContext context) { JsonObject obj = new JsonObject(); obj.add("map", context.serialize(src.asMap())); return obj;//from w w w .j ava2s . co m }
From source file:org.sonar.server.notifications.NotificationService.java
private void dispatch(Notification notification, SetMultimap<String, NotificationChannel> recipients) { for (Map.Entry<String, Collection<NotificationChannel>> entry : recipients.asMap().entrySet()) { String username = entry.getKey(); Collection<NotificationChannel> userChannels = entry.getValue(); LOG.debug("For user {} via {}", username, userChannels); for (NotificationChannel channel : userChannels) { try { channel.deliver(notification, username); } catch (Exception e) { // catch all exceptions in order to deliver via other channels LOG.warn("Unable to deliver notification " + notification + " for user " + username + " via " + channel, e);//from www .j av a 2s .c o m } } } }
From source file:com.google.devtools.build.xcode.xcodegen.PBXBuildFiles.java
/** * Returns new or cached instances of PBXBuildFiles corresponding to files that may or may not * belong to an aggregate reference (see {@link AggregateReferenceType}). Files specified by the * {@code paths} argument are grouped into individual PBXBuildFiles using the given * {@link AggregateReferenceType}. Files that are standalone are not put in an aggregate * reference, but are put in a standalone PBXBuildFile in the returned sequence. *//* ww w. ja v a 2 s.c om*/ public Iterable<PBXBuildFile> get(AggregateReferenceType type, Iterable<Path> paths) { ImmutableList.Builder<PBXBuildFile> result = new ImmutableList.Builder<>(); SetMultimap<AggregateKey, Path> keyedPaths = type.aggregates(paths); for (Map.Entry<AggregateKey, Collection<Path>> aggregation : keyedPaths.asMap().entrySet()) { if (!aggregation.getKey().isStandalone()) { ImmutableSet<Path> itemPaths = ImmutableSet.copyOf(aggregation.getValue()); result.add(aggregateBuildFile(itemPaths, type.create(aggregation.getKey(), fileReferences(itemPaths)))); } } for (Path generalResource : keyedPaths.get(AggregateKey.standalone())) { result.add(getStandalone(FileReference.of(generalResource.toString(), SourceTree.GROUP))); } return result.build(); }
From source file:com.addthis.hydra.query.MeshFileRefCache.java
@Nonnull public Set<FileReference> getTaskReferencesIfPresent(String job, int taskId) { SetMultimap<Integer, FileReference> refMap = fileReferenceCache.getIfPresent(job); if (refMap != null) { return (Set<FileReference>) refMap.asMap().get(taskId); }//from ww w .java2 s . c o m return Collections.emptySet(); }