Class SlotHelper<T>
java.lang.Object
org.incenp.obofoundry.sssom.slots.SlotHelper<T>
- Type Parameters:
T- The SSSOM object (Mapping or MappingSet) this class is intended to ease the manipulation of.
A class to facilitate the manipulation of SSSOM slots. This class is mostly
intended to hide all the hideous hacks relying on Java reflection.
It provides a visitor-like pattern to easily apply treatments on all slots of
a mapping or a mapping set without having to explicitly call the accessor for
each slot. For example, to “visit” all (non-null) slots of a
Mapping object, serialise them as strings, and collect said strings:
ISlotVisitor<Mapping,String> myVisitor = ...; Mapping mapping = ...; List<String> slotsAsStrings = SlotHelper.getMappingHelper().visitSlots(mapping, myVisitor);
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidexcludeSlots(Collection<String> slotNames) Excludes the specified slots from being visited.voidexpandIdentifiers(T object, PrefixManager prefixManager) Expands identifiers in all slots holding entity references.static SlotHelper<Mapping> Gets the default helper object to manipulateMappingslots.static SlotHelper<Mapping> getMappingHelper(boolean newHelper) Gets a helper object to manipulateMappingslots.static SlotHelper<MappingSet> Gets the default helper object to manipulateMappingSetslots.static SlotHelper<MappingSet> getMappingSetHelper(boolean newHelper) Gets a helper object to manipulateMappingSetslots.static Collection<String> getMappingSlotList(String spec) Helper method to construct a list of slot names from a string specification.getSlotByName(String name) Finds a slot by its name.getSlotByURI(String uri) Finds a slot by its associated URI.Gets the current list of slot names to be visited.getSlots()Gets the current list of slots set to be visited.Gets a subset of the current list of slots, containing only the slots that are compatible with the given version of the SSSOM specification.Collection<Slot<T>> getSlotsByName(Collection<String> names) Finds slots by their names.voidConfigures this helper to visit slots in alphabetical order.voidsetSlots(Collection<String> slotNames) Explicitly sets the list of slots to visit.voidExplicitly sets the list of slots to visit.<V> List<V> visitSlots(T object, ISimpleSlotVisitor<T, V> visitor) Visits the slots of a given object, with a visitor that does not distinguish between slot types.<V> List<V> visitSlots(T object, ISimpleSlotVisitor<T, V> visitor, boolean visitNull) Visits the slots of a given object, with a visitor that does not distinguish between slot types.voidvisitSlots(T object, ISlotVisitor<T> visitor) Visits the slots of a given object.voidvisitSlots(T object, ISlotVisitor<T> visitor, boolean visitNull) Visits the slots of a given object.
-
Method Details
-
getMappingHelper
Gets the default helper object to manipulateMappingslots. The default helper is set to visit all slots in the default order.- Returns:
- The default slot helper for
Mappingobjects.
-
getMappingHelper
Gets a helper object to manipulateMappingslots. Use this method to get a distinct helper from the default one. Settings of the returned object can then be modified without altering the default helper.- Parameters:
newHelper-trueto return a distinct helper object, orfalseto return the default helper.- Returns:
- A helper for
Mappingobjects.
-
getMappingSetHelper
Gets the default helper object to manipulateMappingSetslots. The default helper is set to visit all slots in the default order.- Returns:
- The default slot helper for
MappingSetobjects.
-
getMappingSetHelper
Gets a helper object to manipulateMappingSetslots. Use this method to get a distinct helper from the default one. Settings of the returned object can then be modified without altering the default helper.- Parameters:
newHelper-trueto return a distinct helper object, orfalseto return the default helper.- Returns:
- A helper for
MappingSetobjects.
-
setAlphabeticalOrder
public void setAlphabeticalOrder()Configures this helper to visit slots in alphabetical order. -
setSlots
Explicitly sets the list of slots to visit.- Parameters:
slotNames- The names of the slots that this object should visit.forceOrder- Iftrue, slots will be visited in the order they appear in the list; otherwise, the order will remain unchanged.
-
setSlots
Explicitly sets the list of slots to visit.- Parameters:
slotNames- The names of the slots that this object should visit.
-
excludeSlots
Excludes the specified slots from being visited.- Parameters:
slotNames- The names of the slots that this object should not visit.
-
getSlots
Gets the current list of slots set to be visited. They are listed in the order they would be visited.- Returns:
- The current slots list.
-
getSlots
Gets a subset of the current list of slots, containing only the slots that are compatible with the given version of the SSSOM specification.- Parameters:
maxVersion- The version of the SSSOM specification for which to retrieve the slots.- Returns:
- A list of all the slots that are compatible with the given SSSOM version.
-
getSlotNames
Gets the current list of slot names to be visited. They are listed in the order they would be visited.- Returns:
- The current slot names list.
-
getSlotByName
Finds a slot by its name.- Parameters:
name- The name of the slot to find, as per the SSSOM specification.- Returns:
- The corresponding slot, or
nullif the given name is not a valid slot name.
-
getSlotsByName
Finds slots by their names.This is a convenience method, basically to avoid calling
getSlotByName(String)repeatedly.- Parameters:
names- The names of the slots to find, as per the SSSOM specification. If a given name is not a valid slot name, it is ignored.- Returns:
- The corresponding slots.
-
getSlotByURI
Finds a slot by its associated URI.- Parameters:
uri- The URI of the slot to find.- Returns:
- The corresponding slot, or
nullif the given URI is not the URI of a SSSOM slot.
-
visitSlots
Visits the slots of a given object.- Parameters:
object- The object whose slots should be visited.visitor- The visitor to use.
-
visitSlots
Visits the slots of a given object.- Parameters:
object- The object whose slots should be visited.visitor- The visitor to use.visitNull- Iftrue, slots with anullvalue will be visited as well.
-
visitSlots
Visits the slots of a given object, with a visitor that does not distinguish between slot types.- Type Parameters:
V- The type of object the visitor should return for each slot.- Parameters:
object- The object whose slots should be visited.visitor- The visitor to use.- Returns:
- A list of all values returned by the visitor for each slot.
-
visitSlots
Visits the slots of a given object, with a visitor that does not distinguish between slot types.- Type Parameters:
V- The type of objects the visitor should return for each slot.- Parameters:
object- The object whose slots should be visited.visitor- The visitor to use.visitNull- Iftrue, slots with anullvalue will be visited as well.- Returns:
- A list of all values returned by the visitor for each slot.
-
expandIdentifiers
Expands identifiers in all slots holding entity references.- Parameters:
object- The object whose entity reference slots should be visited.prefixManager- The prefix manager to use to expand the short identifiers.
-
getMappingSlotList
Helper method to construct a list of slot names from a string specification.The string is expected to be a comma-separated list of names. Each name should be the name of the slot to include, unless it is prefixed by a
-, in which case the slot is to be excluded. The following special names can also be used:all: represents all slots;mapping: represents the slots that are about the mapping itself (subject_id, predicate_id, object_id;- {code metadata}: represents the slots that are about the mapping metadata (all slots except the above three).
Examples:
subject_id,object_id
will construct a list comprising only the subject_id and object_id slots;all,-predicate_id
will construct a list comprising all slots except predicate_id;mapping,mapping_provider
will construct a list comprising the three slots describing the mapper proper (subject_id, predicate_id, object_id) plus mapping_provider;- Parameters:
spec- A textual specification of the slots list.- Returns:
- The corresponding list of slot names.
-