Open gjwo opened 6 years ago
You're correct, of course, there isn't such a method. However, you can simply loop through the FamilyEvent collection looking for a matching type, which is exactly what Individual.getEventsOfType does
On Sat, Apr 7, 2018, 5:35 PM Graham Wood notifications@github.com wrote:
To find an individual event I can use the code
Individual person; ... List
events = person.getEventsOfType(IndividualEventType.BIRTH); but I can't find an equivalent construct for families such as
Family family ... List
events = family.getEventsOfType(FamilyEventType.MARRIAGE); there is no method getEventsOfType, what is the normal way to do this?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/frizbog/gedcom4j/issues/188, or mute the thread https://github.com/notifications/unsubscribe-auth/ACxHYdJrfmDzq0s1iSML1ajSFPiW0ie1ks5tmTEIgaJpZM4TLQ0U .
Thanks, this code worked fine
/**
* Get a list of events of the supplied type for the specified family
* @param family the family to be searched
* @param type the type of event to get
* @return a list of events of the specified type
*/
public static List<FamilyEvent> getEventsOfType(Family family,FamilyEventType type) {
List<FamilyEvent> result = new ArrayList<>(0);
List<FamilyEvent> events = family.getEvents();
if (events != null) {
for (FamilyEvent fe : events) {
if (fe.getType() == type) {
result.add(fe);
}
}
}
return Collections.unmodifiableList(result);
}
If you find the time it might be worth enhancing the code by adding methods in Family to match Individual where appropriate, or adding an event abstraction common. to both.
To find an individual event I can use the code
but I can't find an equivalent construct for families such as
there is no method getEventsOfType, what is the normal way to do this?