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 TypeMethodDescriptionvoid
excludeSlots
(Collection<String> slotNames) Excludes the specified slots from being visited.void
expandIdentifiers
(T object, PrefixManager prefixManager) Expands identifiers in all slots holding entity references.static SlotHelper
<Mapping> Gets the default helper object to manipulateMapping
slots.static SlotHelper
<Mapping> getMappingHelper
(boolean newHelper) Gets a helper object to manipulateMapping
slots.static SlotHelper
<MappingSet> Gets the default helper object to manipulateMappingSet
slots.static SlotHelper
<MappingSet> getMappingSetHelper
(boolean newHelper) Gets a helper object to manipulateMappingSet
slots.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.Collection
<Slot<T>> getSlotsByName
(Collection<String> names) Finds slots by their names.void
Configures this helper to visit slots in alphabetical order.void
setSlots
(Collection<String> slotNames) Explicitly sets the list of slots to visit.void
Explicitly 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.void
visitSlots
(T object, ISlotVisitor<T> visitor) Visits the slots of a given object.void
visitSlots
(T object, ISlotVisitor<T> visitor, boolean visitNull) Visits the slots of a given object.
-
Method Details
-
getMappingHelper
Gets the default helper object to manipulateMapping
slots. The default helper is set to visit all slots in the default order.- Returns:
- The default slot helper for
Mapping
objects.
-
getMappingHelper
Gets a helper object to manipulateMapping
slots. 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
-true
to return a distinct helper object, orfalse
to return the default helper.- Returns:
- A helper for
Mapping
objects.
-
getMappingSetHelper
Gets the default helper object to manipulateMappingSet
slots. The default helper is set to visit all slots in the default order.- Returns:
- The default slot helper for
MappingSet
objects.
-
getMappingSetHelper
Gets a helper object to manipulateMappingSet
slots. 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
-true
to return a distinct helper object, orfalse
to return the default helper.- Returns:
- A helper for
MappingSet
objects.
-
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.
-
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
null
if 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
null
if 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 anull
value 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 anull
value 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.
-