Package org.planit.utils.id
Class IdGenerator
- java.lang.Object
-
- org.planit.utils.id.IdGenerator
-
public final class IdGenerator extends Object
Convenience class to track unique ids across different classes that decide to use a generator for their id members. Ids are generated starting at zero and in an incremental consecutive fashion. They are unique to their parent though, so if the same class is registered twice with different parents, then their ids will be unique per parent but not across parents.- Author:
- markr
-
-
Constructor Summary
Constructors Constructor Description IdGenerator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static org.planit.utils.id.LocalIdGenerator
createIdGeneratorForParent(IdGroupingToken group)
Create new idGenerators for this group such that we track unique id's within this groupstatic IdGroupingToken
createIdGroupingToken(Object groupOwner, long groupOwnerId)
Factory method to create a new id grouping token based on the class instance simple name and the instance id This allows for a human readable token as well as a unique tokenstatic IdGroupingToken
createIdGroupingToken(String groupDescription)
Factory method to create a new id grouping tokenstatic int
generateId(IdGroupingToken group, Class<? extends Object> theClass)
Generate a unique id for the chosen classstatic void
reset()
Reset the id generation at the start of a run
-
-
-
Method Detail
-
createIdGeneratorForParent
protected static org.planit.utils.id.LocalIdGenerator createIdGeneratorForParent(IdGroupingToken group)
Create new idGenerators for this group such that we track unique id's within this group- Parameters:
group
- the group for which ids will be generated- Returns:
- created IdGenerator
-
generateId
public static int generateId(IdGroupingToken group, Class<? extends Object> theClass)
Generate a unique id for the chosen class- Parameters:
group
- the group for which the id is createdtheClass
- the class for which the id is being generated- Returns:
- the generated id
-
reset
public static void reset()
Reset the id generation at the start of a run
-
createIdGroupingToken
public static IdGroupingToken createIdGroupingToken(String groupDescription)
Factory method to create a new id grouping token- Parameters:
groupDescription
- description for the group- Returns:
- idGroupingToken that has been created
-
createIdGroupingToken
public static IdGroupingToken createIdGroupingToken(Object groupOwner, long groupOwnerId)
Factory method to create a new id grouping token based on the class instance simple name and the instance id This allows for a human readable token as well as a unique token- Parameters:
groupOwner
- group ownergroupOwnerId
- id of the group owner- Returns:
- idGroupingToken that has been created
-
-