import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
class Person {
this.id = id;
}
return id;
}
}
public class Main {
public static void main
(String[] args
) { Set
<Person
> initialSet
= Set.
of(new Person
("123"),
new Person
("456")); Set
<Person
> currentSet
= Set.
of(new Person
("456"));
Function<Person, String> idMapper = Person::getId;
boolean result = areEntriesRemoved(currentSet, initialSet, idMapper);
System.
out.
println(result
); // This will print true }
private static <T> boolean areEntriesRemoved(Set<T> currentSet, Set<T> initialSet, Function<T, String> idMapper) {
Set<String> currentIds = currentSet.stream().map(idMapper).collect(Collectors.toSet());
return initialSet.stream()
.map(idMapper)
.anyMatch(id -> !currentIds.contains(id));
}
}
aW1wb3J0IGphdmEudXRpbC5TZXQ7CmltcG9ydCBqYXZhLnV0aWwuZnVuY3Rpb24uRnVuY3Rpb247CmltcG9ydCBqYXZhLnV0aWwuc3RyZWFtLkNvbGxlY3RvcnM7CgpjbGFzcyBQZXJzb24gewogICAgcHJpdmF0ZSBTdHJpbmcgaWQ7CgogICAgcHVibGljIFBlcnNvbihTdHJpbmcgaWQpIHsKICAgICAgICB0aGlzLmlkID0gaWQ7CiAgICB9CgogICAgcHVibGljIFN0cmluZyBnZXRJZCgpIHsKICAgICAgICByZXR1cm4gaWQ7CiAgICB9Cn0KCnB1YmxpYyBjbGFzcyBNYWluIHsKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgICAgICBTZXQ8UGVyc29uPiBpbml0aWFsU2V0ID0gU2V0Lm9mKG5ldyBQZXJzb24oIjEyMyIpLCBuZXcgUGVyc29uKCI0NTYiKSk7CiAgICAgICAgU2V0PFBlcnNvbj4gY3VycmVudFNldCA9IFNldC5vZihuZXcgUGVyc29uKCI0NTYiKSk7CgogICAgICAgIEZ1bmN0aW9uPFBlcnNvbiwgU3RyaW5nPiBpZE1hcHBlciA9IFBlcnNvbjo6Z2V0SWQ7CgogICAgICAgIGJvb2xlYW4gcmVzdWx0ID0gY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