Java Code Examples for com.google.common.collect.SetMultimap#putAll()
The following examples show how to use
com.google.common.collect.SetMultimap#putAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClasspathCache.java From glowroot with Apache License 2.0 | 6 votes |
synchronized void updateCache() { Multimap<String, Location> newClassNameLocations = HashMultimap.create(); for (ClassLoader loader : getKnownClassLoaders()) { updateCache(loader, newClassNameLocations); } updateCacheWithClasspathClasses(newClassNameLocations); updateCacheWithBootstrapClasses(newClassNameLocations); if (!newClassNameLocations.isEmpty()) { // multimap that sorts keys and de-dups values while maintains value ordering SetMultimap<String, Location> newMap = MultimapBuilder.treeKeys().linkedHashSetValues().build(); newMap.putAll(classNameLocations); newMap.putAll(newClassNameLocations); classNameLocations = ImmutableMultimap.copyOf(newMap); } }
Example 2
Source File: OwnersReport.java From buck with Apache License 2.0 | 6 votes |
@VisibleForTesting OwnersReport updatedWith(OwnersReport other) { // If either this or other are empty, the intersection below for missing files will get // screwed up. This mostly is just so that when we do a fold elsewhere in the class against // a default empty object, we don't obliterate inputsWithNoOwners if (this.isEmpty()) { return other; } else if (other.isEmpty()) { return this; } SetMultimap<TargetNode<?>, Path> updatedOwners = TreeMultimap.create(owners); updatedOwners.putAll(other.owners); return new OwnersReport( ImmutableSetMultimap.copyOf(updatedOwners), Sets.intersection(inputsWithNoOwners, other.inputsWithNoOwners).immutableCopy(), Sets.union(nonExistentInputs, other.nonExistentInputs).immutableCopy(), Sets.union(nonFileInputs, other.nonFileInputs).immutableCopy()); }
Example 3
Source File: PluginManager.java From raml-java-tools with Apache License 2.0 | 5 votes |
private static void buildPluginNames(SetMultimap<String, Class<?>> info, Properties properties) { for (String name : properties.stringPropertyNames()) { List<Class<?>> classList = classList(name, properties.getProperty(name)); if (info.containsKey(name)) { throw new GenerationException("duplicate name in plugins: " + name); } info.putAll(name, classList); } }
Example 4
Source File: Transaction.java From glowroot with Apache License 2.0 | 5 votes |
public SetMultimap<String, String> getAttributes() { synchronized (attributesLock) { if (attributes == null) { return ImmutableSetMultimap.of(); } SetMultimap<String, String> orderedAttributes = TreeMultimap.create(); orderedAttributes.putAll(attributes); return orderedAttributes; } }
Example 5
Source File: CommandLineTaskParser.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public Multimap<String, Task> parseTasks(List<String> taskPaths, TaskSelector taskSelector) { SetMultimap<String, Task> out = LinkedHashMultimap.create(); List<String> remainingPaths = new LinkedList<String>(taskPaths); while (!remainingPaths.isEmpty()) { String path = remainingPaths.remove(0); TaskSelector.TaskSelection selection = taskSelector.getSelection(path); Set<Task> tasks = selection.getTasks(); remainingPaths = taskConfigurer.configureTasks(tasks, remainingPaths); out.putAll(selection.getTaskName(), tasks); } return out; }
Example 6
Source File: BaggageImpl.java From tracing-framework with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Merge the contents of the other baggage into the contents of this baggage * * @param other The other baggage to merge with */ public void merge(BaggageImpl other) { if (other != null) { Handlers.preMerge(this, other); for (ByteString namespace : other.contents.keySet()) { SetMultimap<ByteString, ByteString> namespaceData = contents.get(namespace); if (namespaceData == null) { contents.put(namespace, other.contents.get(namespace)); } else { namespaceData.putAll(other.contents.get(namespace)); } } Handlers.postMerge(this); } }
Example 7
Source File: BaggageImpl.java From tracing-framework with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Replace the values for a key with the new provided values. Null keys ignored, while null values treated as * removing the key * * @param namespace The namespace the provided key resides in, * @param key The key to replace values for * @param values These values replace existing values for the key */ public void replace(ByteString namespace, ByteString key, Iterable<? extends ByteString> values) { if (namespace != null && key != null) { if (values == null) { remove(namespace, key); } else { SetMultimap<ByteString, ByteString> namespaceData = modifyKey(namespace, key); namespaceData.putAll(key, values); namespaceData.remove(key, null); if (namespaceData.isEmpty()) { contents.remove(namespace); } } } }
Example 8
Source File: AliasConfig.java From buck with Apache License 2.0 | 5 votes |
/** * In a {@link BuckConfig}, an alias can either refer to a fully-qualified build target, or an * alias defined earlier in the {@code alias} section. The mapping produced by this method * reflects the result of resolving all aliases as values in the {@code alias} section. */ private ImmutableSetMultimap<String, UnconfiguredBuildTarget> createAliasToBuildTargetMap( ImmutableMap<String, String> rawAliasMap) { // We use a LinkedHashMap rather than an ImmutableMap.Builder because we want both (1) order to // be preserved, and (2) the ability to inspect the Map while building it up. SetMultimap<String, UnconfiguredBuildTarget> aliasToBuildTarget = LinkedHashMultimap.create(); for (Map.Entry<String, String> aliasEntry : rawAliasMap.entrySet()) { String alias = aliasEntry.getKey(); validateAliasName(alias); // Determine whether the mapping is to a build target or to an alias. List<String> values = Splitter.on(' ').splitToList(aliasEntry.getValue()); for (String value : values) { Set<UnconfiguredBuildTarget> buildTargets; if (isValidAliasName(value)) { buildTargets = aliasToBuildTarget.get(value); if (buildTargets.isEmpty()) { throw new HumanReadableException("No alias for: %s.", value); } } else if (value.isEmpty()) { continue; } else { // Here we parse the alias values with a BuildTargetParser to be strict. We could be // looser and just grab everything between "//" and ":" and assume it's a valid base path. buildTargets = ImmutableSet.of( getDelegate().getUnconfiguredBuildTargetForFullyQualifiedTarget(value)); } aliasToBuildTarget.putAll(alias, buildTargets); } } return ImmutableSetMultimap.copyOf(aliasToBuildTarget); }
Example 9
Source File: DataBundleLogic.java From teammates with GNU General Public License v2.0 | 5 votes |
private void updateRespondents(FeedbackSessionAttributes session, Set<InstructorAttributes> courseInstructors, Set<FeedbackQuestionAttributes> sessionQuestions, Set<FeedbackResponseAttributes> sessionResponses) { String sessionKey = makeSessionKey(session.getFeedbackSessionName(), session.getCourseId()); SetMultimap<String, String> instructorQuestionKeysMap = HashMultimap.create(); for (InstructorAttributes instructor : courseInstructors) { List<FeedbackQuestionAttributes> questionsForInstructor = fqLogic.getFeedbackQuestionsForInstructor( new ArrayList<>(sessionQuestions), session.isCreator(instructor.email)); List<String> questionKeys = makeQuestionKeys(questionsForInstructor, sessionKey); instructorQuestionKeysMap.putAll(instructor.email, questionKeys); } Set<String> respondingInstructors = new HashSet<>(); Set<String> respondingStudents = new HashSet<>(); for (FeedbackResponseAttributes response : sessionResponses) { String respondent = response.giver; String responseQuestionNumber = response.feedbackQuestionId; // contains question number before injection String responseQuestionKey = makeQuestionKey(sessionKey, responseQuestionNumber); Set<String> instructorQuestionKeys = instructorQuestionKeysMap.get(respondent); if (instructorQuestionKeys.contains(responseQuestionKey)) { respondingInstructors.add(respondent); } else { respondingStudents.add(respondent); } } session.setRespondingInstructorList(respondingInstructors); session.setRespondingStudentList(respondingStudents); }
Example 10
Source File: ObservableSetMultimapTests.java From gef with Eclipse Public License 2.0 | 5 votes |
@Test public void clear() { // initialize maps with some values observable.putAll(1, Sets.newHashSet("1-1", "1-2", "1-3")); observable.putAll(2, Sets.newHashSet("2-1", "2-2", "2-3")); observable.putAll(null, Sets.newHashSet(null, "null")); // prepare backup map SetMultimap<Integer, String> backupMap = HashMultimap.create(); backupMap.putAll(1, Sets.newHashSet("1-1", "1-2", "1-3")); backupMap.putAll(2, Sets.newHashSet("2-1", "2-2", "2-3")); backupMap.putAll(null, Sets.newHashSet(null, "null")); check(observable, backupMap); registerListeners(); // remove all values invalidationListener.expect(1); setMultimapChangeListener.addAtomicExpectation(); setMultimapChangeListener.addElementaryExpectation(null, Sets.newHashSet(null, "null"), Collections.<String> emptySet()); setMultimapChangeListener.addElementaryExpectation(1, Sets.newHashSet("1-1", "1-2", "1-3"), Collections.<String> emptySet()); setMultimapChangeListener.addElementaryExpectation(2, Sets.newHashSet("2-1", "2-2", "2-3"), Collections.<String> emptySet()); observable.clear(); backupMap.clear(); check(observable, backupMap); checkListeners(); // clear again (while already empty) invalidationListener.expect(0); observable.clear(); backupMap.clear(); check(observable, backupMap); checkListeners(); }
Example 11
Source File: BindingUtils.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * Creates a unidirectional content binding from the given source * {@link SetMultimap} to the given target {@link ObservableSetMultimap}. * * @param <K> * The key type of the given {@link SetMultimap} and * {@link ObservableSetMultimap}. * @param <V> * The value type of the given {@link SetMultimap} and * {@link ObservableSetMultimap}. * @param source * The {@link SetMultimap} whose content to update when the given * {@link ObservableSetMultimap} changes. * @param target * The {@link ObservableSetMultimap} whose content is to be * observed. */ public static <K, V> void bindContent(SetMultimap<K, V> source, ObservableSetMultimap<? extends K, ? extends V> target) { if (source == null) { throw new NullPointerException("Cannot bind null value."); } if (target == null) { throw new NullPointerException("Cannot bind to null value."); } if (source == target) { throw new IllegalArgumentException("Cannot bind source to itself."); } if (source instanceof ObservableSetMultimap) { // ensure we use an atomic operation in case the source set-multimap // is // observable. ((ObservableSetMultimap<K, V>) source).replaceAll(target); } else { source.clear(); source.putAll(target); } final UnidirectionalSetMultimapContentBinding<K, V> contentBinding = new UnidirectionalSetMultimapContentBinding<>( source); // clear any previous bindings target.removeListener(contentBinding); // add new binding as listener target.addListener(contentBinding); }
Example 12
Source File: ScopedUnionFind.java From swift-t with Apache License 2.0 | 5 votes |
/** * Build a multimap with all set members * @return */ public SetMultimap<T, T> sets() { SetMultimap<T, T> result = HashMultimap.create(); ScopedUnionFind<T> curr = this; while (curr != null) { result.putAll(curr.canonical.inverse()); curr = curr.parent; } return result; }
Example 13
Source File: SystemKeyspace.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** * Return a map of stored tokens to IP addresses * */ public static SetMultimap<InetAddress, Token> loadTokens() { SetMultimap<InetAddress, Token> tokenMap = HashMultimap.create(); for (UntypedResultSet.Row row : executeInternal("SELECT peer, tokens FROM system." + PEERS_CF)) { InetAddress peer = row.getInetAddress("peer"); if (row.has("tokens")) tokenMap.putAll(peer, deserializeTokens(row.getSet("tokens", UTF8Type.instance))); } return tokenMap; }
Example 14
Source File: CommandLineTaskParser.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public Multimap<String, Task> parseTasks(List<String> taskPaths, TaskSelector taskSelector) { SetMultimap<String, Task> out = LinkedHashMultimap.create(); List<String> remainingPaths = new LinkedList<String>(taskPaths); while (!remainingPaths.isEmpty()) { String path = remainingPaths.remove(0); TaskSelector.TaskSelection selection = taskSelector.getSelection(path); Set<Task> tasks = selection.getTasks(); remainingPaths = taskConfigurer.configureTasks(tasks, remainingPaths); out.putAll(selection.getTaskName(), tasks); } return out; }
Example 15
Source File: ObservableSetMultimapTests.java From gef with Eclipse Public License 2.0 | 4 votes |
@Test public void remove_entry() { // initialize maps with some values observable.putAll(1, Sets.newHashSet("1-1", "1-2", "1-3")); observable.putAll(2, Sets.newHashSet("2-1", "2-2", "2-3")); observable.putAll(null, Sets.newHashSet(null, "null")); // prepare backup map SetMultimap<Integer, String> backupMap = HashMultimap.create(); backupMap.putAll(1, Sets.newHashSet("1-1", "1-2", "1-3")); backupMap.putAll(2, Sets.newHashSet("2-1", "2-2", "2-3")); backupMap.putAll(null, Sets.newHashSet(null, "null")); check(observable, backupMap); // register listeners registerListeners(); // remove a Compound value invalidationListener.expect(1); setMultimapChangeListener.addAtomicExpectation(); setMultimapChangeListener.addElementaryExpectation(1, Collections.singleton("1-1"), Collections.<String> emptySet()); assertEquals(backupMap.remove(1, "1-1"), observable.remove(1, "1-1")); check(observable, backupMap); checkListeners(); // remove null value from null key invalidationListener.expect(1); setMultimapChangeListener.addAtomicExpectation(); setMultimapChangeListener.addElementaryExpectation(null, Collections.<String> singleton(null), Collections.<String> emptySet()); assertEquals(backupMap.remove(null, null), observable.remove(null, null)); check(observable, backupMap); checkListeners(); // remove real value from null key invalidationListener.expect(1); setMultimapChangeListener.addAtomicExpectation(); setMultimapChangeListener.addElementaryExpectation(null, Collections.<String> singleton("null"), Collections.<String> emptySet()); assertEquals(backupMap.remove(null, "null"), observable.remove(null, "null")); check(observable, backupMap); checkListeners(); // try to remove not contained value assertEquals(backupMap.remove(1, "1-1"), observable.remove(1, "1-1")); check(observable, backupMap); checkListeners(); // try to remove entry with key of wrong type assertEquals(backupMap.remove("1", "1-1"), observable.remove("1", "1-1")); check(observable, backupMap); checkListeners(); // try to remove entry with value of wrong type assertEquals(backupMap.remove(1, 1), observable.remove(1, 1)); check(observable, backupMap); checkListeners(); }
Example 16
Source File: ObservableSetMultimapTests.java From gef with Eclipse Public License 2.0 | 4 votes |
@Test public void removeAll_CompoundKey() { // initialize maps with some values observable.putAll(1, Sets.newHashSet("1-1", "1-2", "1-3")); observable.putAll(2, Sets.newHashSet("2-1", "2-2", "2-3")); observable.putAll(null, Sets.newHashSet(null, "null")); // prepare backup map SetMultimap<Integer, String> backupMap = HashMultimap.create(); backupMap.putAll(1, Sets.newHashSet("1-1", "1-2", "1-3")); backupMap.putAll(2, Sets.newHashSet("2-1", "2-2", "2-3")); backupMap.putAll(null, Sets.newHashSet(null, "null")); check(observable, backupMap); // register listeners registerListeners(); // remove values for a single key invalidationListener.expect(1); setMultimapChangeListener.addAtomicExpectation(); setMultimapChangeListener.addElementaryExpectation(1, Sets.newHashSet("1-1", "1-2", "1-3"), Collections.<String> emptySet()); assertEquals(backupMap.removeAll(1), observable.removeAll(1)); check(observable, backupMap); checkListeners(); // remove values for null key invalidationListener.expect(1); setMultimapChangeListener.addAtomicExpectation(); setMultimapChangeListener.addElementaryExpectation(null, Sets.newHashSet(null, "null"), Collections.<String> emptySet()); assertEquals(backupMap.removeAll(null), observable.removeAll(null)); check(observable, backupMap); checkListeners(); // try to remove values for not contained key assertEquals(backupMap.removeAll(4711), observable.removeAll(4711)); check(observable, backupMap); checkListeners(); // try to remove values of key with wrong type assertEquals(backupMap.removeAll("4711"), observable.removeAll("4711")); check(observable, backupMap); checkListeners(); }
Example 17
Source File: ObservableSetMultimapTests.java From gef with Eclipse Public License 2.0 | 4 votes |
@Test public void replaceAll() { // initialize maps with some values observable.putAll(1, Sets.newHashSet("1-1", "1-2", "1-3")); observable.putAll(2, Sets.newHashSet("2-1", "2-2", "2-3")); observable.putAll(3, Sets.newHashSet("3-1", "3-2", "3-3")); observable.putAll(null, Sets.newHashSet(null, "null")); // prepare backup map SetMultimap<Integer, String> backupMap = HashMultimap.create(); backupMap.putAll(1, Sets.newHashSet("1-1", "1-2", "1-3")); backupMap.putAll(2, Sets.newHashSet("2-1", "2-2", "2-3")); backupMap.putAll(3, Sets.newHashSet("3-1", "3-2", "3-3")); backupMap.putAll(null, Sets.newHashSet(null, "null")); check(observable, backupMap); // register listeners registerListeners(); // remove all values invalidationListener.expect(1); setMultimapChangeListener.addAtomicExpectation(); setMultimapChangeListener.addElementaryExpectation(null, Sets.newHashSet(null, "null"), Collections.<String> emptySet()); // removed // null // key setMultimapChangeListener.addElementaryExpectation(2, Sets.newHashSet("2-1", "2-3"), Collections.<String> emptySet()); // removed // 2-1, // 2-3 setMultimapChangeListener.addElementaryExpectation(3, Sets.newHashSet("3-3"), Sets.newHashSet("3-4")); // removed 3-3, // added 3-4 setMultimapChangeListener.addElementaryExpectation(4, Collections.<String> emptySet(), Sets.newHashSet("4-1")); SetMultimap<Integer, String> toReplace = HashMultimap.create(); toReplace.putAll(1, Sets.newHashSet("1-1", "1-2", "1-3")); // leave // unchanged toReplace.putAll(2, Sets.newHashSet("2-2")); // remove values (2-1, 2-3) toReplace.putAll(3, Sets.newHashSet("3-1", "3-2", "3-4")); // change // values // (removed // 3-3, // added // 3-4) toReplace.putAll(4, Sets.newHashSet("4-1")); // add entry observable.replaceAll(toReplace); backupMap.clear(); backupMap.putAll(toReplace); check(observable, backupMap); checkListeners(); // replace with same contents (should not have any effect) invalidationListener.expect(0); observable.replaceAll(toReplace); check(observable, backupMap); checkListeners(); }
Example 18
Source File: ObservableSetMultimapTests.java From gef with Eclipse Public License 2.0 | 4 votes |
@Test public void replaceValues() { // initialize maps with some values observable.putAll(1, Sets.newHashSet("1-1", "1-2", "1-3")); observable.putAll(2, Sets.newHashSet("2-1", "2-2", "2-3")); observable.putAll(null, Sets.newHashSet(null, "null")); // prepare backup map SetMultimap<Integer, String> backupMap = HashMultimap.create(); backupMap.putAll(1, Sets.newHashSet("1-1", "1-2", "1-3")); backupMap.putAll(2, Sets.newHashSet("2-1", "2-2", "2-3")); backupMap.putAll(null, Sets.newHashSet(null, "null")); check(observable, backupMap); // register listeners registerListeners(); // replace all values of a specific key invalidationListener.expect(1); setMultimapChangeListener.addAtomicExpectation(); setMultimapChangeListener.addElementaryExpectation(1, Sets.newHashSet("1-1", "1-2", "1-3"), Sets.newHashSet("1-4", "1-5", "1-6")); assertEquals( backupMap.replaceValues(1, Sets.newHashSet("1-4", "1-5", "1-6")), observable.replaceValues(1, Sets.newHashSet("1-4", "1-5", "1-6"))); check(observable, backupMap); checkListeners(); // use replacement to clear values for a key invalidationListener.expect(1); setMultimapChangeListener.addAtomicExpectation(); setMultimapChangeListener.addElementaryExpectation(2, Sets.newHashSet("2-1", "2-2", "2-3"), Collections.<String> emptySet()); assertEquals( backupMap.replaceValues(2, Collections.<String> emptySet()), observable.replaceValues(2, Collections.<String> emptySet())); check(observable, backupMap); checkListeners(); // try to replace values for non existing key assertEquals( backupMap.replaceValues(4711, Sets.newHashSet("4", "7", "1")), observable.replaceValues(4711, Sets.newHashSet("4", "7", "1"))); check(observable, backupMap); checkListeners(); }
Example 19
Source File: SetMultimapExpression.java From gef with Eclipse Public License 2.0 | 4 votes |
@Override public boolean putAll(K key, Iterable<? extends V> values) { final SetMultimap<K, V> setMultimap = get(); return (setMultimap == null) ? EMPTY_SETMULTIMAP.putAll(key, values) : setMultimap.putAll(key, values); }
Example 20
Source File: ImmutableContextSetImpl.java From LuckPerms with MIT License | 4 votes |
@Override protected void copyTo(SetMultimap<String, String> other) { other.putAll(this.map); }