Package org.gedcomx.util
Class DocMap
- java.lang.Object
-
- org.gedcomx.util.DocMap
-
public class DocMap extends Object
Utility class for simplifying the lookup of Person, SourceDescription, RecordDescription or Agent objects in a GedcomX document. Each object can be looked up by its local 'id' (with or without a preceding "#"), using a String or URI. Persons can also be looked up by any of their identifiers, and SourceDescriptions can be looked up by any of the identifiers of the entity they are describing. User: Randy Wilson Date: 6/9/14 Time: 3:53 PM
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AgentgetAgent(String agentId)Find the Agent with the given local id.AgentgetAgent(URI agentId)Find the Agent with the given local id.static Map<String,Agent>getAgentMap(Gedcomx doc)Create a map of local id (and "#" + id) to the Agent that has that id.GedcomxgetDocument()Get the Gedcomx document that was used to create this DocMap.PersongetMainPerson()Get the Person described by the main SourceDescription.SourceDescriptiongetMainSourceDescription()Get the SourceDescription referenced by the GedcomX document's descriptionRef.PersongetPerson(String idOrUrl)Get the person from the GedcomX document that has the given id (with or without "#") or an identifier that matches the given idOrUrl.PersongetPerson(ResourceReference resourceReference)Get the person from the GedcomX document that has the id given in the URI of the given ResourceReference.PersongetPerson(URI uri)Get the person from the GedcomX document that has the given id (with or without "#") or identifier.static Map<String,Person>getPersonMap(Gedcomx doc)Create a map of local id (and "#" + id) as well as all person identifiers to the local Person object with that id or identifier.PlaceDescriptiongetPlaceDescription(String idOrUri)Find the PlaceDescription with the given local id (or "#" + local id) or the given URI.PlaceDescriptiongetPlaceDescription(URI placeDescriptionUri)Find the PlaceDescription with the given local id (or "#" + local id) or the given URI.PlaceDescriptiongetPlaceDescription(PlaceReference placeReference)Find the PlaceDescription with the given PlaceReference.static Map<String,PlaceDescription>getPlaceMap(Gedcomx doc)Create a map of local id (and "#" + id) and identifier URIs to the PlaceDescription that has that id or URL.RecordDescriptorgetRecordDescriptor(String recordDescriptorIdOrUrl)Find the RecordDescriptor referenced by the given id (with or without a "#"), or URL (with "#" and a local id).RecordDescriptorgetRecordDescriptor(URI recordDescriptorId)Find the RecordDescriptor referenced by the given id (with or without a "#").static Map<String,RecordDescriptor>getRecordDescriptorMap(Gedcomx doc)Create a map of local id (and "#" + id) to the RecordDescriptor that has that id.SourceDescriptiongetSourceDescription(String idOrUrl)Get the SourceDescription from the GedcomX document that has the given id (with or without "#") or an identifier that matches the given idOrUrl.SourceDescriptiongetSourceDescription(URI uri)Get the SourceDescription from the GedcomX document that has the given id (with or without "#") or an identifier that matches the given idOrUrl.SourceDescriptiongetSourceDescription(SourceReference sourceReference)Get the SourceDescription referenced by the given SourceReference.static Map<String,SourceDescription>getSourceDescriptionMap(Gedcomx doc)Create a map of id (and "#" + id) and all identifier URI strings to SourceDescription with that ID, to make it easier to look up SourceDescriptions that are referenced elsewhere.voidupdate(Gedcomx doc)Update the maps with the given GedcomX document (e.g., when the document has changed).
-
-
-
Constructor Detail
-
DocMap
public DocMap(Gedcomx doc)
Constructor. Create an object that allows convenient lookup of things in a GedcomX document.- Parameters:
doc- - GedcomX document to build maps for.
-
-
Method Detail
-
update
public void update(Gedcomx doc)
Update the maps with the given GedcomX document (e.g., when the document has changed).- Parameters:
doc- - GedcomX document to rebuild maps for.
-
getDocument
public Gedcomx getDocument()
Get the Gedcomx document that was used to create this DocMap.- Returns:
- GedcomX document that was used to create this DocMap.
-
getMainSourceDescription
public SourceDescription getMainSourceDescription()
Get the SourceDescription referenced by the GedcomX document's descriptionRef.- Returns:
- SourceDescription referenced by the GedcomX document's descriptionRef, or null if none.
-
getMainPerson
public Person getMainPerson()
Get the Person described by the main SourceDescription. Returns null if there is no main SourceDescription or if this document's main thing is not a Person.- Returns:
- Person referenced by the main SourceDescription.
-
getPerson
public Person getPerson(String idOrUrl)
Get the person from the GedcomX document that has the given id (with or without "#") or an identifier that matches the given idOrUrl. Can look a person up by "p1", "#p1" or "http://whatever.com/persons/12345".- Parameters:
idOrUrl- - local person id (with or without "#") or any person identifier- Returns:
- Person with the given id or identifier.
-
getPerson
public Person getPerson(URI uri)
Get the person from the GedcomX document that has the given id (with or without "#") or identifier. Can look a person up by "p1", "#p1" or "http://whatever.com/persons/12345".- Parameters:
uri- - local person id (with or without "#") or any person identifier- Returns:
- Person with the given id or identifier.
-
getPerson
public Person getPerson(ResourceReference resourceReference)
Get the person from the GedcomX document that has the id given in the URI of the given ResourceReference. Can look a person up by "p1", "#p1" or "http://whatever.com/persons/12345".- Parameters:
resourceReference- - local person id (with or without "#") or any person identifier- Returns:
- Person with the given id or identifier.
-
getSourceDescription
public SourceDescription getSourceDescription(String idOrUrl)
Get the SourceDescription from the GedcomX document that has the given id (with or without "#") or an identifier that matches the given idOrUrl. Can look a source description up by "sd1", "#sd1" or "http://whatever.com/records/12345", if that is an identifier that the source description is describing and has listed as one of the identifiers.- Parameters:
idOrUrl- - local person id (with or without "#") or any person identifier- Returns:
- Person with the given id or identifier.
-
getSourceDescription
public SourceDescription getSourceDescription(URI uri)
Get the SourceDescription from the GedcomX document that has the given id (with or without "#") or an identifier that matches the given idOrUrl. Can look a source description up by "sd1", "#sd1" or "http://whatever.com/records/12345", if that is an identifier that the source description is describing and has listed as one of the identifiers.- Parameters:
uri- - local source description id (with or without "#") or any identifier in the source description.- Returns:
- Person with the given id or identifier.
-
getSourceDescription
public SourceDescription getSourceDescription(SourceReference sourceReference)
Get the SourceDescription referenced by the given SourceReference. Typically the SourceReference will reference the SourceDescription by "#" + its local id.- Parameters:
sourceReference- - SourceReference that points to a SourceDescription.- Returns:
- SourceDescription referenced by the given SourceReference.
-
getRecordDescriptor
public RecordDescriptor getRecordDescriptor(String recordDescriptorIdOrUrl)
Find the RecordDescriptor referenced by the given id (with or without a "#"), or URL (with "#" and a local id).- Parameters:
recordDescriptorIdOrUrl- - local id of a RecordDescriptor (with or without a "#"), or URL of recordDescriptor (with "#" + local id at end).- Returns:
- RecordDescriptor referenced by the given id or URL.
-
getRecordDescriptor
public RecordDescriptor getRecordDescriptor(URI recordDescriptorId)
Find the RecordDescriptor referenced by the given id (with or without a "#").- Parameters:
recordDescriptorId- - URI containing the local id of a RecordDescriptor (with or without a "#").- Returns:
- RecordDescriptor referenced by the given id.
-
getAgent
public Agent getAgent(String agentId)
Find the Agent with the given local id.- Parameters:
agentId- - id of an agent (with or without an initial "#").- Returns:
- Agent with the given id.
-
getAgent
public Agent getAgent(URI agentId)
Find the Agent with the given local id.- Parameters:
agentId- - URI containing the id of an agent (with or without an initial "#").- Returns:
- Agent with the given id.
-
getPlaceDescription
public PlaceDescription getPlaceDescription(String idOrUri)
Find the PlaceDescription with the given local id (or "#" + local id) or the given URI.- Parameters:
idOrUri- - local id (with or without "#") or full identifier URI of a PlaceDescription.- Returns:
- PlaceDescription object with the given local id or URI.
-
getPlaceDescription
public PlaceDescription getPlaceDescription(URI placeDescriptionUri)
Find the PlaceDescription with the given local id (or "#" + local id) or the given URI.- Parameters:
placeDescriptionUri- - local id (with or without "#") or full identifier URI of a PlaceDescription.- Returns:
- PlaceDescription object with the given local id or URI.
-
getPlaceDescription
public PlaceDescription getPlaceDescription(PlaceReference placeReference)
Find the PlaceDescription with the given PlaceReference.- Parameters:
placeReference- - PlaceReference that contains the (probably local) id of a PlaceDescription.- Returns:
- PlaceDescription object with the given local id or URI.
-
getSourceDescriptionMap
public static Map<String,SourceDescription> getSourceDescriptionMap(Gedcomx doc)
Create a map of id (and "#" + id) and all identifier URI strings to SourceDescription with that ID, to make it easier to look up SourceDescriptions that are referenced elsewhere.- Parameters:
doc- - GedcomX document to create a map for.- Returns:
- map of id (and "#" + id) to SourceDescription.
-
getPersonMap
public static Map<String,Person> getPersonMap(Gedcomx doc)
Create a map of local id (and "#" + id) as well as all person identifiers to the local Person object with that id or identifier.- Parameters:
doc- - GedcomX document to create a map for.- Returns:
- map of local id, "#" + id, and all URIs for each Person in the document to that Person.
-
getAgentMap
public static Map<String,Agent> getAgentMap(Gedcomx doc)
Create a map of local id (and "#" + id) to the Agent that has that id. If there are no agents, an empty (but non-null) map is returned.- Parameters:
doc- - document to find agents for- Returns:
- Map of local id (and "#" + id) to each Agent in the doc.
-
getRecordDescriptorMap
public static Map<String,RecordDescriptor> getRecordDescriptorMap(Gedcomx doc)
Create a map of local id (and "#" + id) to the RecordDescriptor that has that id. If there are no record descriptors, an empty (but non-null) map is returned.- Parameters:
doc- - document to find record descriptors for- Returns:
- Map of local id (and "#" + id) to each RecordDescriptor in the doc.
-
getPlaceMap
public static Map<String,PlaceDescription> getPlaceMap(Gedcomx doc)
Create a map of local id (and "#" + id) and identifier URIs to the PlaceDescription that has that id or URL. If there are no place descriptions, an empty (but non-null) map is returned.- Parameters:
doc- - document to find place descriptions for- Returns:
- Map of local id (and "#" + id) and URI string to each PlaceDescription in the doc.
-
-