static <T> Predicate<T> idIn(Set<T> set) { return idIn(identityMap(set)); }
/** * update the contents of a set with the provided sets, ensuring that the items to remove are * really present, and that the items to add are not (unless we're also removing them) * @return a new set with the contents of the provided one modified */ static <T> Set<T> replace(Set<T> original, Set<T> remove, Iterable<T> add) { return ImmutableSet.copyOf(replace(identityMap(original), remove, add).keySet()); }
static <T> Predicate<T> idIn(Set<T> set) { return idIn(identityMap(set)); }
/** * update the contents of a set with the provided sets, ensuring that the items to remove are * really present, and that the items to add are not (unless we're also removing them) * @return a new set with the contents of the provided one modified */ static <T> Set<T> replace(Set<T> original, Set<T> remove, Iterable<T> add) { return ImmutableSet.copyOf(replace(identityMap(original), remove, add).keySet()); }
/** * update the contents of a set with the provided sets, ensuring that the items to remove are * really present, and that the items to add are not (unless we're also removing them) * @return a new set with the contents of the provided one modified */ static <T> Set<T> replace(Set<T> original, Set<T> remove, Iterable<T> add) { return ImmutableSet.copyOf(replace(identityMap(original), remove, add).keySet()); }
static <T> Predicate<T> idIn(Set<T> set) { return idIn(identityMap(set)); }
static <T> Predicate<T> idIn(Set<T> set) { return idIn(identityMap(set)); }
/** * update the contents of an "identity map" with the provided sets, ensuring that the items to remove are * really present, and that the items to add are not (unless we're also removing them) * @return a new identity map with the contents of the provided one modified */ static <T> Map<T, T> replace(Map<T, T> original, Set<T> remove, Iterable<T> add) { // ensure the ones being removed are the exact same ones present for (T reader : remove) assert original.get(reader) == reader; // ensure we don't already contain any we're adding, that we aren't also removing assert !any(add, and(not(in(remove)), in(original.keySet()))) : String.format("original:%s remove:%s add:%s", original.keySet(), remove, add); Map<T, T> result = identityMap(concat(add, filter(original.keySet(), not(in(remove))))); assert result.size() == original.size() - remove.size() + Iterables.size(add) : String.format("Expecting new size of %d, got %d while replacing %s by %s in %s", original.size() - remove.size() + Iterables.size(add), result.size(), remove, add, original.keySet()); return result; }
/** * update the contents of an "identity map" with the provided sets, ensuring that the items to remove are * really present, and that the items to add are not (unless we're also removing them) * @return a new identity map with the contents of the provided one modified */ static <T> Map<T, T> replace(Map<T, T> original, Set<T> remove, Iterable<T> add) { // ensure the ones being removed are the exact same ones present for (T reader : remove) assert original.get(reader) == reader; // ensure we don't already contain any we're adding, that we aren't also removing assert !any(add, and(not(in(remove)), in(original.keySet()))) : String.format("original:%s remove:%s add:%s", original.keySet(), remove, add); Map<T, T> result = identityMap(concat(add, filter(original.keySet(), not(in(remove))))); assert result.size() == original.size() - remove.size() + Iterables.size(add) : String.format("Expecting new size of %d, got %d while replacing %s by %s in %s", original.size() - remove.size() + Iterables.size(add), result.size(), remove, add, original.keySet()); return result; }
/** * update the contents of an "identity map" with the provided sets, ensuring that the items to remove are * really present, and that the items to add are not (unless we're also removing them) * @return a new identity map with the contents of the provided one modified */ static <T> Map<T, T> replace(Map<T, T> original, Set<T> remove, Iterable<T> add) { // ensure the ones being removed are the exact same ones present for (T reader : remove) assert original.get(reader) == reader; // ensure we don't already contain any we're adding, that we aren't also removing assert !any(add, and(not(in(remove)), in(original.keySet()))) : String.format("original:%s remove:%s add:%s", original.keySet(), remove, add); Map<T, T> result = identityMap(concat(add, filter(original.keySet(), not(in(remove))))); assert result.size() == original.size() - remove.size() + Iterables.size(add) : String.format("Expecting new size of %d, got %d while replacing %s by %s in %s", original.size() - remove.size() + Iterables.size(add), result.size(), remove, add, original.keySet()); return result; }
/** * update the contents of a set with the provided sets, ensuring that the items to remove are * really present, and that the items to add are not (unless we're also removing them) * @return a new set with the contents of the provided one modified */ static <T> Set<T> replace(Set<T> original, Set<T> remove, Iterable<T> add) { return ImmutableSet.copyOf(replace(identityMap(original), remove, add).keySet()); }
/** * update the contents of an "identity map" with the provided sets, ensuring that the items to remove are * really present, and that the items to add are not (unless we're also removing them) * @return a new identity map with the contents of the provided one modified */ static <T> Map<T, T> replace(Map<T, T> original, Set<T> remove, Iterable<T> add) { // ensure the ones being removed are the exact same ones present for (T reader : remove) assert original.get(reader) == reader; // ensure we don't already contain any we're adding, that we aren't also removing assert !any(add, and(not(in(remove)), in(original.keySet()))) : String.format("original:%s remove:%s add:%s", original.keySet(), remove, add); Map<T, T> result = identityMap(concat(add, filter(original.keySet(), not(in(remove))))); assert result.size() == original.size() - remove.size() + Iterables.size(add) : String.format("Expecting new size of %d, got %d while replacing %s by %s in %s", original.size() - remove.size() + Iterables.size(add), result.size(), remove, add, original.keySet()); return result; }