Package org.goplanit.converter
Class BaseReaderImpl<T>
- java.lang.Object
-
- org.goplanit.converter.BaseReaderImpl<T>
-
- All Implemented Interfaces:
ConverterEntity,ConverterReader<T>
- Direct Known Subclasses:
NetworkReaderImpl,PlanitDemandsReader,PlanitRoutedServicesReader,PlanitZoningReader,TntpDemandsReader,TntpNetworkReader,TntpZoningReader
public abstract class BaseReaderImpl<T> extends Object implements ConverterReader<T>
Abstract base class implementation for converter readers which has a mechanism to (optionally) keep track of entities by their source id as PLANit only indexes by internal id- Author:
- markr
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<Class<?>,MapWrapper<?,?>>sourceIdTrackerMaptrack PLANit entities by something else than their internal id via this map
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseReaderImpl()Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <V,K>
VgetBySourceId(Class<V> clazz, K key)Get an entry by its source idprotected <V> MapWrapper<?,V>getSourceIdContainer(Class<V> clazz)access to the container with sourceIdsprotected <K,V>
voidinitialiseSourceIdMap(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 containerprotected <K,V>
voidinitialiseSourceIdMap(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 containerprotected <U,V>
voidregisterBySourceId(Class<U> theClazz, V obj)Stores an object by its source Id, after checking whether the external Id is a duplicateprotected <V> voidregisterBySourceId(V obj)Stores an object by its source Id, after checking whether the external Id is a duplicate-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.goplanit.converter.ConverterEntity
getTypeDescription, reset
-
Methods inherited from interface org.goplanit.converter.ConverterReader
getSettings, read
-
-
-
-
Field Detail
-
sourceIdTrackerMap
protected final Map<Class<?>,MapWrapper<?,?>> sourceIdTrackerMap
track PLANit entities by something else than their internal id via this map
-
-
Method Detail
-
registerBySourceId
protected <V> void registerBySourceId(V obj) throws PlanItExceptionStores 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- Throws:
PlanItException- thrown if error
-
registerBySourceId
protected <U,V> void registerBySourceId(Class<U> theClazz, V obj) throws PlanItException
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- Throws:
PlanItException- thrown if duplicate or not possible to register due to lack of initialised container
-
initialiseSourceIdMap
protected <K,V> void initialiseSourceIdMap(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
-
initialiseSourceIdMap
protected <K,V> void initialiseSourceIdMap(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
-
getSourceIdContainer
protected <V> MapWrapper<?,V> getSourceIdContainer(Class<V> clazz)
access to the container with sourceIds- Type Parameters:
V- value of the container- Parameters:
clazz- to collect container for- Returns:
- the source id map wrapper, null if not present
-
getBySourceId
protected <V,K> V getBySourceId(Class<V> clazz, K key)
Get an entry by its source 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
-
-