private <T> SetMultimap<T, T> createMapping(List<T> keys, List<T> values) { checkArgument(keys.size() == values.size(), "Inputs must have the same size"); ImmutableSetMultimap.Builder<T, T> builder = ImmutableSetMultimap.builder(); for (int i = 0; i < keys.size(); i++) { builder.put(keys.get(i), values.get(i)); } return builder.build(); }
/** * Returns an immutable multimap containing the given entries, in order. Repeated occurrences of * an entry (according to {@link Object#equals}) after the first are ignored. */ public static <K, V> ImmutableSetMultimap<K, V> of(K k1, V v1, K k2, V v2) { ImmutableSetMultimap.Builder<K, V> builder = ImmutableSetMultimap.builder(); builder.put(k1, v1); builder.put(k2, v2); return builder.build(); }
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); }
@Override public SetMultimap<String, Measure> getRawMeasures(Component component) { T componentKey = componentToKey.apply(component); Map<MeasureKey, Measure> rawMeasures = measures.get(componentKey); if (rawMeasures == null) { return ImmutableSetMultimap.of(); } ImmutableSetMultimap.Builder<String, Measure> builder = ImmutableSetMultimap.builder(); for (Map.Entry<MeasureKey, Measure> entry : rawMeasures.entrySet()) { builder.put(entry.getKey().getMetricKey(), entry.getValue()); } return builder.build(); }
/** * Returns an immutable multimap containing the given entries, in order. Repeated occurrences of * an entry (according to {@link Object#equals}) after the first are ignored. */ public static <K, V> ImmutableSetMultimap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) { ImmutableSetMultimap.Builder<K, V> builder = ImmutableSetMultimap.builder(); builder.put(k1, v1); builder.put(k2, v2); builder.put(k3, v3); return builder.build(); }
ImmutableMultimap<State, Service> servicesByState() { ImmutableSetMultimap.Builder<State, Service> builder = ImmutableSetMultimap.builder(); monitor.enter(); try { for (Entry<State, Service> entry : servicesByState.entries()) { if (!(entry.getValue() instanceof NoOpService)) { builder.put(entry); } } } finally { monitor.leave(); } return builder.build(); }
/** * Given a list of actual elements and a list of expected elements, finds a many:many mapping * between actual and expected elements where a pair of elements maps if it satisfies the * correspondence. Returns this mapping as a multimap where the keys are indexes into the actual * list and the values are indexes into the expected list. Any exceptions are treated as if the * elements did not correspond, and the exception added to the store. */ private ImmutableSetMultimap<Integer, Integer> findCandidateMapping( List<? extends A> actual, List<? extends E> expected, Correspondence.ExceptionStore exceptions) { ImmutableSetMultimap.Builder<Integer, Integer> mapping = ImmutableSetMultimap.builder(); for (int actualIndex = 0; actualIndex < actual.size(); actualIndex++) { for (int expectedIndex = 0; expectedIndex < expected.size(); expectedIndex++) { if (correspondence.safeCompare( actual.get(actualIndex), expected.get(expectedIndex), exceptions)) { mapping.put(actualIndex, expectedIndex); } } } return mapping.build(); }
/** * Returns an immutable multimap containing the given entries, in order. Repeated occurrences of * an entry (according to {@link Object#equals}) after the first are ignored. */ public static <K, V> ImmutableSetMultimap<K, V> of( K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { ImmutableSetMultimap.Builder<K, V> builder = ImmutableSetMultimap.builder(); builder.put(k1, v1); builder.put(k2, v2); builder.put(k3, v3); builder.put(k4, v4); return builder.build(); }
/** * 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(); }
public void testBuilderPutAllMultimapWithDuplicates() { Multimap<String, Integer> toPut = LinkedListMultimap.create(); toPut.put("foo", 1); toPut.put("bar", 4); toPut.put("foo", 2); toPut.put("foo", 1); toPut.put("bar", 5); ImmutableSetMultimap.Builder<String, Integer> builder = ImmutableSetMultimap.builder(); builder.putAll(toPut); ImmutableSetMultimap<String, Integer> multimap = builder.build(); assertEquals(4, multimap.size()); }
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()); }
/** * Returns an immutable multimap containing the given entries, in order. Repeated occurrences of * an entry (according to {@link Object#equals}) after the first are ignored. */ public static <K, V> ImmutableSetMultimap<K, V> of(K k1, V v1, K k2, V v2) { ImmutableSetMultimap.Builder<K, V> builder = ImmutableSetMultimap.builder(); builder.put(k1, v1); builder.put(k2, v2); return builder.build(); }
ImmutableMultimap<State, Service> servicesByState() { ImmutableSetMultimap.Builder<State, Service> builder = ImmutableSetMultimap.builder(); monitor.enter(); try { for (Entry<State, Service> entry : servicesByState.entries()) { if (!(entry.getValue() instanceof NoOpService)) { builder.put(entry); } } } finally { monitor.leave(); } return builder.build(); }
/** * {@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(); }