// Iterate over the slices
Iterator<Map.Entry<Key<ActivitySlice>, ActivitySlice>> it = slices
.entrySet().iterator();
while (it.hasNext()) {
// Get the key of the parent activity
ActivitySlice slice = it.next().getValue();
Key<Activity> activityKey = slice.getActivity();
// If the parent is not in the activities result set
if (!activityKeys.contains(activityKey)) {
// Remove the slice from the map
it.remove();
}