Package org.goplanit.utils.id
Class ManagedIdEntitiesImpl<E extends ManagedId>
- java.lang.Object
-
- org.goplanit.utils.wrapper.MapWrapperImpl<Long,V>
-
- org.goplanit.utils.wrapper.LongMapWrapperImpl<E>
-
- org.goplanit.utils.id.ManagedIdEntitiesImpl<E>
-
- Type Parameters:
E
- type of managed id entity
- All Implemented Interfaces:
Iterable<E>
,ManagedIdEntities<E>
,LongMapWrapper<E>
,MapWrapper<Long,E>
- Direct Known Subclasses:
ConnectoidsImpl
,MacroscopicLinkSegmentTypesImpl
,ManagedDirectedPathsImpl
,ManagedGraphEntitiesImpl
,ModesImpl
,RoutedModeServicesImpl
,RoutedServicesLayersImpl
,RoutedTripDeparturesImpl
,RoutedTripsImpl
,TimePeriods
,TransferZoneGroupsImpl
,TransportLayersImpl
,TravellerTypes
,UserClasses
,ZonesImpl
public abstract class ManagedIdEntitiesImpl<E extends ManagedId> extends LongMapWrapperImpl<E> implements ManagedIdEntities<E>
Base class for containers of managed id entities- Author:
- markr
-
-
Field Summary
Fields Modifier and Type Field Description protected Class<? extends ManagedId>
managedIdClass
the class signature used for generating the managed id within the group defined by the token
-
Constructor Summary
Constructors Modifier Constructor Description protected
ManagedIdEntitiesImpl(Function<E,Long> valueToKey)
Constructor.protected
ManagedIdEntitiesImpl(Function<E,Long> valueToKey, Class<? extends ManagedId> managedIdClass)
Constructorprotected
ManagedIdEntitiesImpl(ManagedIdEntitiesImpl<E> other, boolean deepCopy, BiConsumer<E,E> mapper)
copy constructor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract ManagedIdEntitiesImpl<E>
deepClone()
Deep clone implementationabstract ManagedIdEntitiesImpl<E>
deepCloneWithMapping(BiConsumer<E,E> mapper)
Deep clone implementation where the mapping for its internal copies is captured by the provided mapperClass<? extends ManagedId>
getManagedIdClass()
Collect the class identifier used for the managed ids within the id group for instances of this class used in this containervoid
recreateIds(boolean resetManagedIdClass)
Recreate the ids for all registered entities with or without resetting, this includes child managed ids, i.e., nested magedidentities containers if so indicatedvoid
reset()
When reset it called, it not only clears the entries, but also resets the managedids, such that when the container is reused the managed ids start from zero again.abstract ManagedIdEntitiesImpl<E>
shallowClone()
Each map wrapper should be cloneable where the contents are references of the original where possible but the underlying map itself is newly createdprotected void
updateIdMapping()
updates the container keys based on currently presiding ids.-
Methods inherited from class org.goplanit.utils.wrapper.LongMapWrapperImpl
containsKey, get, remove
-
Methods inherited from class org.goplanit.utils.wrapper.MapWrapperImpl
clear, containsValue, createEmptyInstance, firstMatch, get, getKeyByValue, getMap, getValueToKey, isEmpty, iterator, register, remove, removeIf, setMap, size, toCollection, valuesAsNewSet
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Methods inherited from interface org.goplanit.utils.wrapper.LongMapWrapper
get, remove
-
Methods inherited from interface org.goplanit.utils.id.ManagedIdEntities
containsKey, getFactory, groupBy, recreateIds, streamSortedBy
-
Methods inherited from interface org.goplanit.utils.wrapper.MapWrapper
addAll, clear, containsValue, firstMatch, forEachIn, get, getFirst, getKeyByValue, isEmpty, register, remove, removeAll, removeIf, size, stream, streamSorted, toCollection, toMap, valuesAsNewSet
-
-
-
-
Constructor Detail
-
ManagedIdEntitiesImpl
protected ManagedIdEntitiesImpl(Function<E,Long> valueToKey, Class<? extends ManagedId> managedIdClass)
Constructor- Parameters:
valueToKey
- the mapping from key to value of the graph entitymanagedIdClass
- should reflect the class signature used for generating the managed id of this class when creating it via the factory of this container
-
ManagedIdEntitiesImpl
protected ManagedIdEntitiesImpl(Function<E,Long> valueToKey)
Constructor. while not recommended it is allowed to create managed ids that do not rely on id generation of the class itself. It can be that they rely on child ids or synced ids of other internal referenced classes. In that case this constructor can be used directly. this however should generally be avoided.- Parameters:
valueToKey
- the mapping from key to value of the graph entity
-
ManagedIdEntitiesImpl
protected ManagedIdEntitiesImpl(ManagedIdEntitiesImpl<E> other, boolean deepCopy, BiConsumer<E,E> mapper)
copy constructor- Parameters:
other
- to copydeepCopy
- when true, create a deep copy, shallow copy otherwisemapper
- to apply in case of deep copy to each original to copy combination (when provided, may be null)
-
-
Method Detail
-
updateIdMapping
protected void updateIdMapping()
updates the container keys based on currently presiding ids. Only to be used when an external force has changed already registered entity their ids
-
getManagedIdClass
public Class<? extends ManagedId> getManagedIdClass()
Collect the class identifier used for the managed ids within the id group for instances of this class used in this container- Specified by:
getManagedIdClass
in interfaceManagedIdEntities<E extends ManagedId>
- Returns:
- managedIdClass for instances this factory creates
-
recreateIds
public void recreateIds(boolean resetManagedIdClass)
Recreate the ids for all registered entities with or without resetting, this includes child managed ids, i.e., nested magedidentities containers if so indicated- Specified by:
recreateIds
in interfaceManagedIdEntities<E extends ManagedId>
- Parameters:
resetManagedIdClass
- when true we reset the managedId's counter to zero (via its id class) before recreating the ids, otherwise we simply recreate the managed id by starting with the next available id without resetting
-
reset
public void reset()
When reset it called, it not only clears the entries, but also resets the managedids, such that when the container is reused the managed ids start from zero again. If any entries are managedEntities themselves or contain managed entities themselves, they are reset as well- Specified by:
reset
in interfaceManagedIdEntities<E extends ManagedId>
-
shallowClone
public abstract ManagedIdEntitiesImpl<E> shallowClone()
Each map wrapper should be cloneable where the contents are references of the original where possible but the underlying map itself is newly created- Specified by:
shallowClone
in interfaceManagedIdEntities<E extends ManagedId>
- Specified by:
shallowClone
in interfaceMapWrapper<Long,E extends ManagedId>
- Specified by:
shallowClone
in classLongMapWrapperImpl<E extends ManagedId>
- Returns:
- copy
-
deepClone
public abstract ManagedIdEntitiesImpl<E> deepClone()
Deep clone implementation- Specified by:
deepClone
in interfaceManagedIdEntities<E extends ManagedId>
- Returns:
- deep copy of entities
-
deepCloneWithMapping
public abstract ManagedIdEntitiesImpl<E> deepCloneWithMapping(BiConsumer<E,E> mapper)
Deep clone implementation where the mapping for its internal copies is captured by the provided mapper- Specified by:
deepCloneWithMapping
in interfaceManagedIdEntities<E extends ManagedId>
- Parameters:
mapper
- to apply to each mapping between original and copy- Returns:
- copy
-
-