Set<Individual> result = new HashSet<Individual>();
// Get every family this individual was a child of
for (FamilyChild fc : individual.familiesWhereChild) {
// Add father and all his wives
Individual dad = fc.family.husband;
if (dad != null && !result.contains(dad)) {
result.add(dad);
for (FamilySpouse fs : dad.familiesWhereSpouse) {
Individual dadsWife = fs.family.wife;
if (dadsWife != null) {
result.add(dadsWife);
result.addAll(getExtendedAncestry(dadsWife));
}
}
// And include his extended ancestry as well (recursively)
result.addAll(getExtendedAncestry(dad));
}
// Add mother and all her husbands
Individual mom = fc.family.wife;
if (mom != null && !result.contains(mom)) {
result.add(mom);
for (FamilySpouse fs : mom.familiesWhereSpouse) {
Individual momsHusband = fs.family.husband;
if (momsHusband != null) {
result.add(momsHusband);
result.addAll(getExtendedAncestry(momsHusband));
}
}