Perhaps the greatest strength of Genesis is that it provides a consistent and flexible data model for genealolgical data. Extensions can retrieve data from any source or format imaginable, as well as display data in both traditional and novel ways.
There are two main data model classes, IPerson and IEvent, representing an individual and an event respectively. Because the information you might want to record about an individual or an event is so diverse, these classes provide a very generic mechanism for querying attributes. However, convenience methods are provided in GenealogyUtils for querying the most common types of information:
public class DataTest { public void testPerson(IPerson person) { IName name = GenealogyUtils.getName(person); if (name != null) System.out.println("Name: " + name.getFullName()); Sex sex = GenealogyUtils.getSex(person); if (sex == Sex.Male) System.out.println("Sex: MALE"); else if (sex == Sex.Female) System.out.println("Sex: FEMALE"); } public void testEvent(IEvent event) { IDate date = GenealogyUtils.getDate(event); if (date != null) System.out.println("Date: " + date); IPlace place = GenealogyUtils.getPlace(event); if (place != null) System.out.println("Place: " + place); } }
If you want to query some other type of information, you'll need to use the generic mechanism. For example, this is how you would query an individual's name:
public class DataTest { public void getNames(IPerson person) { Set<IAttribute> attributes = person.getAttributes(GenealogyConstants.name); for (IAttribute attribute : attributes) { Object value = attribute.getValue(); if (value instanceof IName) System.out.println("Name: " + ((IName) value).getFullName()); } } }
You'll notice that, unlike the convenience methods, this technique gives you access to all of the values for a given attribute, not just an arbitrary one. You'll also notice that the value is mediated by an instance of the IAttribute class. This class provides additional information about this attribute, such as its source, trust rating, and other metadata.
Individuals and events are related by a fourth class: IRole. Both an individual and an event may have zero or more roles. A role links a single individual and event. For example, an individual is linked to his birth event by a "child" role. The individual's parents are linked to the same event by a "father" and a "mother" role.
Here is an example of how you would get a list of an individual's marriages and spouses:
public class DataTest { public void getMarriages(IPerson person) { for (IRole myRole : person.getRoles(GenealogyConstants.Spouse)) { IEvent marriage = myRole.getEvent(); System.out.println("Marriage: " + marriage); for (IRole spouseRole : marriage.getRoles(GenealogyConstants.Spouse)) { if (!person.equals(spouseRole.getPlayer())) System.out.println("Spouse: " + spouseRole.getPlayer()); } } } }
Relationships are determined by navigating individuals, roles, and events. This arrangement makes it possible to simultaneously model many different kinds of relationships, but convenience methods are again provided for querying the most common types of relationships:
public class DataTest { public void testRelationships(IPerson person) { IPerson father = GenealogyUtils.getFather(person); if (father != null) System.out.println("Father: " + father); IPerson mother = GenealogyUtils.getMother(person); if (mother != null) System.out.println("Mother: " + mother); Set<IPerson> siblings = GenealogyUtils.getSiblings(person); for (IPerson sibling : siblings) System.out.println("Sibling: " + sibling); Set<IPerson> spouses = GenealogyUtils.getSpouses(person); for (IPerson spouse : spouses) System.out.println("Spouse: " + spouse); Set<IPerson> children = GenealogyUtils.getChildren(person); for (IPerson child : children) System.out.println("Child: " + child); } }