Class 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 via initialiseEntityContainer(Class, Function)
    Author:
    markr
    • Field Detail

      • entitiyByIndexTracker

        protected final Map<Class<?>,​MapWrapper<?,​?>> entitiyByIndexTracker
        track PLANit entities by any single property via this map
    • Constructor Detail

      • CustomIndexTracker

        public CustomIndexTracker()
    • 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 stored
        V - value to store
        Parameters:
        theClazz - class to identify the correct container
        obj - 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 used
        V - value type used
        Parameters:
        clazz - identifier in container of containers
        valueToKey - 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 used
        V - value type used
        Parameters:
        clazz - identifier in container of containers
        valueToKey - function mapping value to key
        addToSourceIdMap - 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 type
        K - key to find it by
        Parameters:
        clazz - class identifier for selecting the correct container tracker
        key - the actual key to use
        Returns:
        value found, null if not present
      • reset

        public void reset()
        reset all tracked content