public class IdMap
extends java.lang.Object
id or name properties or class names (see putObject(Object), or explicitly definied (with putObject(Object).
Auto-generated IDs are suffixed with a running number if necessary.| Modifier and Type | Field and Description |
|---|---|
protected java.util.LinkedHashMap<java.lang.Object,java.lang.String> |
idObjMap |
protected int |
maxUsedIdNum |
protected java.util.LinkedHashMap<java.lang.String,java.lang.Object> |
objIdMap |
protected ReflectorMap |
reflectorMap |
protected java.lang.String |
userId |
| Constructor and Description |
|---|
IdMap(ReflectorMap reflectorMap) |
| Modifier and Type | Method and Description |
|---|---|
void |
discoverObjects(java.util.Collection<?> roots)
Discovers all objects reachable from the
roots and within the packages managed by the ReflectorMap
that was given in the constructor, and adds them via putObject(Object). |
void |
discoverObjects(java.lang.Object... roots)
Discovers all objects reachable from the
roots and within the packages managed by the ReflectorMap
that was given in the constructor, and adds them via putObject(Object). |
void |
discoverObjects(java.lang.Object root)
Discovers all objects reachable from the
root and within the packages managed by the ReflectorMap
that was given in the constructor, and adds them via putObject(Object). |
java.lang.String |
getId(java.lang.Object object) |
java.lang.Object |
getObject(java.lang.String id) |
Reflector |
getReflector(java.lang.Object object) |
java.lang.String |
getUserId() |
java.lang.String |
putObject(java.lang.Object object)
Adds the object with an automatically generated ID.
|
void |
putObject(java.lang.String id,
java.lang.Object object)
Adds the
object with the given id. |
void |
setUserId(java.lang.String userId) |
protected final ReflectorMap reflectorMap
protected java.lang.String userId
protected int maxUsedIdNum
protected final java.util.LinkedHashMap<java.lang.String,java.lang.Object> objIdMap
protected final java.util.LinkedHashMap<java.lang.Object,java.lang.String> idObjMap
public IdMap(ReflectorMap reflectorMap)
public java.lang.String getUserId()
public void setUserId(java.lang.String userId)
public Reflector getReflector(java.lang.Object object)
object - the objectReflectorMap.getReflector(Object)public java.lang.String getId(java.lang.Object object)
object - the objectobject, or null if not foundpublic java.lang.Object getObject(java.lang.String id)
id - the idnull if not foundpublic java.lang.String putObject(java.lang.Object object)
getId() method, we use that as the base ID
by replacing any non-word characters (regex \W) with _.getId() method but a getName() method,
the base ID becomes the result of that with the same replacement appliedThen,
object - the object to addpublic void putObject(java.lang.String id,
java.lang.Object object)
object with the given id.
If there is already an object with that id, the old object is removed.id - the idobject - the objectpublic void discoverObjects(java.lang.Object root)
root and within the packages managed by the ReflectorMap
that was given in the constructor, and adds them via putObject(Object).root - the root objectReflectorMap.discoverObjects(Object)public void discoverObjects(java.lang.Object... roots)
roots and within the packages managed by the ReflectorMap
that was given in the constructor, and adds them via putObject(Object).roots - the root objectsReflectorMap.discoverObjects(Object...)public void discoverObjects(java.util.Collection<?> roots)
roots and within the packages managed by the ReflectorMap
that was given in the constructor, and adds them via putObject(Object).roots - the root objectsReflectorMap.discoverObjects(Collection)