Package org.incenp.linkml.core
Class ObjectCache
- java.lang.Object
-
- org.incenp.linkml.core.ObjectCache
-
public class ObjectCache extends Object
Cache for LinkML objects.Several LinkML objects (especially all definitions, e.g. class definitions, slot definitions, etc.) live in a global namespace where they are identified by the value of their identifier slot. This object represents that global namespace.
-
-
Constructor Summary
Constructors Constructor Description ObjectCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> TgetObject(Class<T> type, String name)Looks up for an object with the specified name.<T> TgetObject(Class<T> type, String name, boolean create)Looks up for an object with the specified name.intgetSize()Gets the number of objects in the cache.
-
-
-
Method Detail
-
getObject
public <T> T getObject(Class<T> type, String name, boolean create) throws LinkMLRuntimeException
Looks up for an object with the specified name.- Type Parameters:
T- The type of object to return.- Parameters:
type- The type of object to return.name- The name of the object to return.create- Iftrue, the object will be created and added to the cache if it did not already exist.- Returns:
- The object that was in the cache or have been newly created, or
nullif (1) the object that was in the cache was not of the expected type, or (2) the object was not in the cache andcreateisfalse. - Throws:
LinkMLRuntimeException- If the specified type of object is not one that can be cached (because it has no identifier slot), or if the object could not be created as needed.
-
getObject
public <T> T getObject(Class<T> type, String name) throws LinkMLRuntimeException
Looks up for an object with the specified name.- Type Parameters:
T- The type of object to return.- Parameters:
type- The type of object to return.name- The name of the object to return.- Returns:
- The requested object, or
nullif the object was not in the cache or was not of the expected type. - Throws:
LinkMLRuntimeException- If the specified type of object is not one that can be cached, because it has no identifier slot.
-
getSize
public int getSize()
Gets the number of objects in the cache.
-
-