Java Code Examples for com.google.common.collect.SetMultimap#replaceValues()

The following examples show how to use com.google.common.collect.SetMultimap#replaceValues() . 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: BindingUtils.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void onChanged(Change<? extends K, ? extends V> change) {
	// This cast is safe, as a
	// UnidirectionalSetMultimapContentBinding<K, V> will only be used
	// for a SetMultimap<K, V>.
	final SetMultimap<K, V> source = (SetMultimap<K, V>) change
			.getSetMultimap();
	while (change.next()) {
		final SetMultimap<K, V> destination = setMultimapRef.get();
		if (destination == null) {
			change.getSetMultimap().removeListener(this);
		} else {
			// we use replaceValues() to perform an atomic change here
			// (and
			// thus don't use the added and removed values from the
			// change)
			destination.replaceValues(change.getKey(),
					new HashSet<>(source.get(change.getKey())));
		}
	}
}
 
Example 2
Source File: SetMultimapExpression.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Set<V> replaceValues(K key, Iterable<? extends V> values) {
	final SetMultimap<K, V> setMultimap = get();
	return (setMultimap == null)
			? EMPTY_SETMULTIMAP.replaceValues(key, values)
			: setMultimap.replaceValues(key, values);
}
 
Example 3
Source File: BindingUtils.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void onChanged(Change<? extends K, ? extends V> change) {
	if (!updating) {
		final ObservableSetMultimap<K, V> setMultimap1 = setMultimap1Ref
				.get();
		final ObservableSetMultimap<K, V> setMultimap2 = setMultimap2Ref
				.get();
		if ((setMultimap1 == null) || (setMultimap2 == null)) {
			if (setMultimap1 != null) {
				setMultimap1.removeListener(this);
			}
			if (setMultimap2 != null) {
				setMultimap2.removeListener(this);
			}
		} else {
			try {
				updating = true;
				final SetMultimap<K, V> source = setMultimap1 == change
						.getSetMultimap() ? setMultimap1 : setMultimap2;
				final SetMultimap<K, V> destination = setMultimap1 == change
						.getSetMultimap() ? setMultimap2 : setMultimap1;
				// we use replaceValues() to perform an atomic change
				// here (and thus don't use the added and removed values
				// from the change)
				while (change.next()) {
					destination.replaceValues(change.getKey(),
							new HashSet<>(source.get(change.getKey())));
				}
			} finally {
				updating = false;
			}
		}
	}
}
 
Example 4
Source File: DefaultDockerCmdExecFactory.java    From docker-java with Apache License 2.0 5 votes vote down vote up
@Override
public DefaultWebTarget queryParamsSet(String name, Set<?> values) {
    SetMultimap<String, String> newQueryParams = HashMultimap.create(queryParams);
    newQueryParams.replaceValues(name, values.stream().filter(Objects::nonNull).map(Object::toString).collect(Collectors.toSet()));

    return new DefaultWebTarget(path, newQueryParams);
}