Package org.goplanit.utils.misc
Class CustomIndexTracker
- java.lang.Object
-
- org.goplanit.utils.misc.CustomIndexTracker
-
public class CustomIndexTracker extends Object
Class that allows one to track multiple entities of classes by a custom index based on a provided mapping for a given instance. User should explicitly initialise for each class that requires a custom tracker container viainitialiseEntityContainer(Class, Function)
- Author:
- markr
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<Class<?>,MapWrapper<?,?>>
entitiyByIndexTracker
track PLANit entities by any single property via this map
-
Constructor Summary
Constructors Constructor Description CustomIndexTracker()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <V,K>
Vget(Class<V> clazz, K key)
Get an entry of register class by its custom id<V> MapWrapper<?,V>
getEntityContainer(Class<V> clazz)
access to the container with custom Ids<K,V>
voidinitialiseEntityContainer(Class<V> clazz, Function<V,K> valueToKey)
register a new source id tracker (empty) where a function is used to extract the source id from the entity and the class is used unique identifier for the underlying tracking container<K,V>
voidinitialiseEntityContainer(Class<V> clazz, Function<V,K> valueToKey, Iterable<V> addToSourceIdMap)
register a new source id tracker (empty) where a function is used to extract the source id from the entity and the class is used unique identifier for the underlying tracking container<U,V>
voidregister(Class<U> theClazz, V obj)
Stores an object by its source Id, after checking whether the external Id is a duplicate<V> void
register(V obj)
Stores an object by its source Id, after checking whether the external Id is a duplicatevoid
reset()
reset all tracked content
-
-
-
Field Detail
-
entitiyByIndexTracker
protected final Map<Class<?>,MapWrapper<?,?>> entitiyByIndexTracker
track PLANit entities by any single property via this map
-
-
Method Detail
-
register
public <V> void register(V obj)
Stores an object by its source Id, after checking whether the external Id is a duplicate- Type Parameters:
V
- type of object being stored- Parameters:
obj
- object being stored by its class signature, assuming ithat is the identifier it is registered under
-
register
public <U,V> void register(Class<U> theClazz, V obj)
Stores an object by its source Id, after checking whether the external Id is a duplicate- Type Parameters:
U
- type of object being storedV
- value to store- Parameters:
theClazz
- class to identify the correct containerobj
- object being stored
-
initialiseEntityContainer
public <K,V> void initialiseEntityContainer(Class<V> clazz, Function<V,K> valueToKey)
register a new source id tracker (empty) where a function is used to extract the source id from the entity and the class is used unique identifier for the underlying tracking container- Type Parameters:
K
- key type usedV
- value type used- Parameters:
clazz
- identifier in container of containersvalueToKey
- function mapping value to key
-
initialiseEntityContainer
public <K,V> void initialiseEntityContainer(Class<V> clazz, Function<V,K> valueToKey, Iterable<V> addToSourceIdMap)
register a new source id tracker (empty) where a function is used to extract the source id from the entity and the class is used unique identifier for the underlying tracking container- Type Parameters:
K
- key type usedV
- value type used- Parameters:
clazz
- identifier in container of containersvalueToKey
- function mapping value to keyaddToSourceIdMap
- add all entities in iterable to the newly created source id map upon creation
-
getEntityContainer
public <V> MapWrapper<?,V> getEntityContainer(Class<V> clazz)
access to the container with custom Ids- Type Parameters:
V
- value of the container- Parameters:
clazz
- to collect container for- Returns:
- the source id map wrapper, null if not present
-
get
public <V,K> V get(Class<V> clazz, K key)
Get an entry of register class by its custom id- Type Parameters:
V
- return typeK
- key to find it by- Parameters:
clazz
- class identifier for selecting the correct container trackerkey
- the actual key to use- Returns:
- value found, null if not present
-
reset
public void reset()
reset all tracked content
-
-