/** * This method creates a mapping from each index source lookup symbol (directly applied to the index) * to the corresponding probe key Input */ private SetMultimap<Symbol, Integer> mapIndexSourceLookupSymbolToProbeKeyInput(IndexJoinNode node, Map<Symbol, Integer> probeKeyLayout) { Set<Symbol> indexJoinSymbols = node.getCriteria().stream() .map(IndexJoinNode.EquiJoinClause::getIndex) .collect(toImmutableSet()); // Trace the index join symbols to the index source lookup symbols // Map: Index join symbol => Index source lookup symbol Map<Symbol, Symbol> indexKeyTrace = IndexJoinOptimizer.IndexKeyTracer.trace(node.getIndexSource(), indexJoinSymbols); // Map the index join symbols to the probe key Input Multimap<Symbol, Integer> indexToProbeKeyInput = HashMultimap.create(); for (IndexJoinNode.EquiJoinClause clause : node.getCriteria()) { indexToProbeKeyInput.put(clause.getIndex(), probeKeyLayout.get(clause.getProbe())); } // Create the mapping from index source look up symbol to probe key Input ImmutableSetMultimap.Builder<Symbol, Integer> builder = ImmutableSetMultimap.builder(); for (Map.Entry<Symbol, Symbol> entry : indexKeyTrace.entrySet()) { Symbol indexJoinSymbol = entry.getKey(); Symbol indexLookupSymbol = entry.getValue(); builder.putAll(indexLookupSymbol, indexToProbeKeyInput.get(indexJoinSymbol)); } return builder.build(); }
/** * Returns an immutable set multimap containing the same mappings as {@code multimap}. The * generated multimap's key and value orderings correspond to the iteration ordering of the {@code * multimap.asMap()} view. Repeated occurrences of an entry in the multimap after the first are * ignored. * * <p>Despite the method name, this method attempts to avoid actually copying the data when it is * safe to do so. The exact circumstances under which a copy will or will not be performed are * undocumented and subject to change. * * @throws NullPointerException if any key or value in {@code multimap} is null */ public static <K, V> ImmutableSetMultimap<K, V> copyOf( Multimap<? extends K, ? extends V> multimap) { return copyOf(multimap, null); }
@Override SetMultimap<String, Integer> filter(SetMultimap<String, Integer> multimap) { ImmutableSetMultimap<String, Integer> badEntries = ImmutableSetMultimap.of("foo", 314, "one", 159, "two", 265, "bar", 358); multimap.putAll(badEntries); multimap = Multimaps.filterEntries( multimap, Predicates.not( Predicates.in(ImmutableMap.of("one", 159, "two", 265).entrySet()))); return Multimaps.filterKeys( multimap, Predicates.not(Predicates.in(ImmutableSet.of("foo", "bar")))); } })
/** Creates an ImmutableSetMultimap from an asMap.entrySet. */ static <K, V> ImmutableSetMultimap<K, V> fromMapEntries( Collection<? extends Map.Entry<? extends K, ? extends Collection<? extends V>>> mapEntries, @Nullable Comparator<? super V> valueComparator) { if (mapEntries.isEmpty()) { return of(); } ImmutableMap.Builder<K, ImmutableSet<V>> builder = new ImmutableMap.Builder<>(mapEntries.size()); int size = 0; for (Entry<? extends K, ? extends Collection<? extends V>> entry : mapEntries) { K key = entry.getKey(); Collection<? extends V> values = entry.getValue(); ImmutableSet<V> set = valueSet(valueComparator, values); if (!set.isEmpty()) { builder.put(key, set); size += set.size(); } } return new ImmutableSetMultimap<>(builder.build(), size, valueComparator); }
/** * {@inheritDoc} */ @Override public Multimap<String, NotificationChannel> findSubscribedRecipientsForDispatcher(NotificationDispatcher dispatcher, String projectKey, SubscriberPermissionsOnProject subscriberPermissionsOnProject) { requireNonNull(projectKey, "projectKey is mandatory"); String dispatcherKey = dispatcher.getKey(); Set<SubscriberAndChannel> subscriberAndChannels = Arrays.stream(notificationChannels) .flatMap(notificationChannel -> toSubscriberAndChannels(dispatcherKey, projectKey, notificationChannel)) .collect(Collectors.toSet()); if (subscriberAndChannels.isEmpty()) { return ImmutableMultimap.of(); } ImmutableSetMultimap.Builder<String, NotificationChannel> builder = ImmutableSetMultimap.builder(); try (DbSession dbSession = dbClient.openSession(false)) { Set<String> authorizedLogins = keepAuthorizedLogins(dbSession, projectKey, subscriberAndChannels, subscriberPermissionsOnProject); subscriberAndChannels.stream() .filter(subscriberAndChannel -> authorizedLogins.contains(subscriberAndChannel.getSubscriber().getLogin())) .forEach(subscriberAndChannel -> builder.put(subscriberAndChannel.getSubscriber().getLogin(), subscriberAndChannel.getChannel())); } return builder.build(); }
ImmutableMap.Builder<String, Pipeline> pipelineIdMap = ImmutableMap.builder(); pipelineService.loadAll().forEach(pipelineDao -> { Pipeline pipeline; pipelineIdMap.put(pipelineDao.id(), resolvePipeline(pipeline, ruleNameMap)); }); final ImmutableMap<String, Pipeline> currentPipelines = pipelineIdMap.build(); for (PipelineConnections streamConnection : pipelineStreamConnectionsService.loadAll()) { streamConnection.pipelineIds().stream() .map(currentPipelines::get) .filter(Objects::nonNull) .forEach(pipeline -> connections.put(streamConnection.streamId(), pipeline)); ImmutableSetMultimap<String, Pipeline> streamPipelineConnections = ImmutableSetMultimap.copyOf(connections);
private ImmutableSet<Pipeline> selectPipelines(InterpreterListener interpreterListener, Set<Tuple2<String, String>> processingBlacklist, Message message, Set<String> initialStreamIds, ImmutableSetMultimap<String, Pipeline> streamConnection) { final String msgId = message.getId(); // if a message-stream combination has already been processed (is in the set), skip that execution final Set<String> streamsIds = initialStreamIds.stream() .filter(streamId -> !processingBlacklist.contains(tuple(msgId, streamId))) .filter(streamConnection::containsKey) .collect(Collectors.toSet()); final ImmutableSet<Pipeline> pipelinesToRun = streamsIds.stream() .flatMap(streamId -> streamConnection.get(streamId).stream()) .collect(ImmutableSet.toImmutableSet()); interpreterListener.processStreams(message, pipelinesToRun, streamsIds); log.debug("[{}] running pipelines {} for streams {}", msgId, pipelinesToRun, streamsIds); return pipelinesToRun; }
.filter(service -> !failureDetector.getFailed().contains(service)) .collect(toImmutableSet()); ImmutableSet.Builder<Node> activeNodesBuilder = ImmutableSet.builder(); ImmutableSet.Builder<Node> inactiveNodesBuilder = ImmutableSet.builder(); ImmutableSet.Builder<Node> shuttingDownNodesBuilder = ImmutableSet.builder(); ImmutableSet.Builder<Node> coordinatorsBuilder = ImmutableSet.builder(); ImmutableSetMultimap.Builder<ConnectorId, Node> byConnectorIdBuilder = ImmutableSetMultimap.builder(); connectorIds = connectorIds.toLowerCase(ENGLISH); for (String connectorId : CONNECTOR_ID_SPLITTER.split(connectorIds)) { byConnectorIdBuilder.put(new ConnectorId(connectorId), node); byConnectorIdBuilder.put(new ConnectorId(GlobalSystemConnector.NAME), node); break; case INACTIVE: activeNodesByConnectorId = byConnectorIdBuilder.build(); coordinators = coordinatorsBuilder.build();
public void test_toImmutableSetMultimap_keyValue() { List<String> list = Arrays.asList("a", "ab", "b", "bb", "c", "a"); ImmutableSetMultimap<Integer, String> test = list.stream() .collect(Guavate.toImmutableSetMultimap(s -> s.length(), s -> "!" + s)); ImmutableSetMultimap<Object, Object> expected = ImmutableSetMultimap.builder() .put(1, "!a").put(2, "!ab").put(1, "!b").put(2, "!bb").put(1, "!c").build(); assertEquals(test, expected); }
private EqualityInference(Iterable<Set<Expression>> equalityGroups, Set<Expression> derivedExpressions) { ImmutableSetMultimap.Builder<Expression, Expression> setBuilder = ImmutableSetMultimap.builder(); for (Set<Expression> equalityGroup : equalityGroups) { if (!equalityGroup.isEmpty()) { setBuilder.putAll(CANONICAL_ORDERING.min(equalityGroup), equalityGroup); } } equalitySets = setBuilder.build(); ImmutableMap.Builder<Expression, Expression> mapBuilder = ImmutableMap.builder(); for (Map.Entry<Expression, Expression> entry : equalitySets.entries()) { Expression canonical = entry.getKey(); Expression expression = entry.getValue(); mapBuilder.put(expression, canonical); } canonicalMap = mapBuilder.build(); this.derivedExpressions = ImmutableSet.copyOf(derivedExpressions); }
/** * Construct a set of rules by which local files may not be named on the file-system. * @param transformationMatrix how to make specific characters safe, may be null * @param unsafePrefixes which name prefixes are proscribed, may be null * @param unsafeSuffixes which name suffixes are proscribed, may be null * @param unsafeNames which names are proscribed, may be null * @param safeCharacters safe characters that may be used in making file names safe, may <em>not</em> be null */ public FilePathRestrictions(SetMultimap<Integer, Integer> transformationMatrix, Set<String> unsafePrefixes, Set<String> unsafeSuffixes, Set<String> unsafeNames, Set<Character> safeCharacters) { this.transformationMatrix = transformationMatrix == null ? ImmutableSetMultimap.<Integer, Integer>of() : ImmutableSetMultimap.copyOf(transformationMatrix); this.unsafePrefixes = unsafePrefixes == null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(unsafePrefixes); this.unsafeSuffixes = unsafeSuffixes == null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(unsafeSuffixes); this.unsafeNames = unsafeNames == null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(unsafeNames); this.safeCharacters = ImmutableSet.copyOf(safeCharacters); this.safeCharacter = this.safeCharacters.iterator().next(); int safeCodePoint = FilePathRestrictionInstance.getCodePoint(this.safeCharacter); final ImmutableMap.Builder<Integer, Integer> transformationMapBuilder = ImmutableMap.builder(); for (final Entry<Integer, Collection<Integer>> transformation : this.transformationMatrix.asMap().entrySet()) { final Collection<Integer> values = transformation.getValue(); final Integer selectedValue = values.contains(safeCodePoint) ? safeCodePoint : values.iterator().next(); transformationMapBuilder.put(transformation.getKey(), selectedValue); } this.transformationMap = transformationMapBuilder.build(); } }
/** * Creates a {@link ResolvedBindings} appropriate for when there are no bindings for the key. */ static ResolvedBindings noBindings(Key key, ComponentDescriptor owningComponent) { return new AutoValue_ResolvedBindings( key, owningComponent.typeElement(), ImmutableSetMultimap.of(), ImmutableMap.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of()); }
/** Creates a {@link ResolvedBindings} for contribution bindings. */ static ResolvedBindings forContributionBindings( Key key, ComponentDescriptor owningComponent, Multimap<TypeElement, ContributionBinding> contributionBindings, Iterable<MultibindingDeclaration> multibindings, Iterable<SubcomponentDeclaration> subcomponentDeclarations, Iterable<OptionalBindingDeclaration> optionalBindingDeclarations) { return new AutoValue_ResolvedBindings( key, owningComponent.typeElement(), ImmutableSetMultimap.copyOf(contributionBindings), ImmutableMap.of(), ImmutableSet.copyOf(multibindings), ImmutableSet.copyOf(subcomponentDeclarations), ImmutableSet.copyOf(optionalBindingDeclarations)); }
private boolean memberIsWhitelisted(Entry<String, ClassMemberKey> member) { return allowedMembers.containsEntry(member.getKey(), member.getValue()) || allowedMembers.get(member.getKey()).stream() .anyMatch( memberKey -> memberKey.descriptor().isEmpty() && memberKey.identifier().equals(member.getValue().identifier())); }
private static <K, V> ImmutableSetMultimap<K, V> copyOf( Multimap<? extends K, ? extends V> multimap, Comparator<? super V> valueComparator) { checkNotNull(multimap); // eager for GWT if (multimap.isEmpty() && valueComparator == null) { return of(); } if (multimap instanceof ImmutableSetMultimap) { @SuppressWarnings("unchecked") // safe since multimap is not writable ImmutableSetMultimap<K, V> kvMultimap = (ImmutableSetMultimap<K, V>) multimap; if (!kvMultimap.isPartialView()) { return kvMultimap; } } ImmutableMap.Builder<K, ImmutableSet<V>> builder = ImmutableMap.builder(); int size = 0; for (Entry<? extends K, ? extends Collection<? extends V>> entry : multimap.asMap().entrySet()) { K key = entry.getKey(); Collection<? extends V> values = entry.getValue(); ImmutableSet<V> set = valueSet(valueComparator, values); if (!set.isEmpty()) { builder.put(key, set); size += set.size(); } } return new ImmutableSetMultimap<K, V>( builder.build(), size, valueComparator); }
public void testBuilderPutAllIterable() { ImmutableSetMultimap.Builder<String, Integer> builder = ImmutableSetMultimap.builder(); builder.putAll("foo", Arrays.asList(1, 2, 3)); builder.putAll("bar", Arrays.asList(4, 5)); builder.putAll("foo", Arrays.asList(6, 7)); Multimap<String, Integer> multimap = builder.build(); assertEquals(ImmutableSet.of(1, 2, 3, 6, 7), multimap.get("foo")); assertEquals(ImmutableSet.of(4, 5), multimap.get("bar")); assertEquals(7, multimap.size()); }
public void testAsMultimap() { ImmutableMap<String, Integer> map = ImmutableMap.of("one", 1, "won", 1, "two", 2, "too", 2, "three", 3); ImmutableSetMultimap<String, Integer> expected = ImmutableSetMultimap.of("one", 1, "won", 1, "two", 2, "too", 2, "three", 3); assertEquals(expected, map.asMultimap()); }