Class IDController
java.lang.Object
utils.IDController
Utility class responsible for generating unique, sequential identifiers (IDs)
for new
Project and Request entities.
It maintains static counters for each entity type and initializes them based on
the highest existing ID found in the current data lists to ensure continuity.
Note: This implementation assumes IDs follow a pattern like "P0001" or "R0001" where the numeric part starts from index 1.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidinit()Initializes the static ID counters by scanning the existing Project and Request lists.static StringGenerates a new, unique project ID sequentially.static StringGenerates a new, unique request ID sequentially.static voidsetProjectCount(int count) Manually sets the internal counter used for generating the next project ID.static voidsetRequestCount(int count) Manually sets the internal counter used for generating the next request ID.
-
Constructor Details
-
IDController
public IDController()
-
-
Method Details
-
init
public static void init()Initializes the static ID counters by scanning the existing Project and Request lists. It finds the maximum numeric value currently used in existing IDs (assuming format Prefix + Number) and sets the internal counters to that maximum value. This ensures that subsequently generated IDs are unique and sequential. Should typically be called once at application startup after loading initial data. -
setProjectCount
public static void setProjectCount(int count) Manually sets the internal counter used for generating the next project ID. Useful primarily for testing or specific reset scenarios. Use with caution.- Parameters:
count- The value to set the project counter to.
-
setRequestCount
public static void setRequestCount(int count) Manually sets the internal counter used for generating the next request ID. Useful primarily for testing or specific reset scenarios. Use with caution. Note: There is a typo in the method name and the corresponding static variable (`reqeustCount`).- Parameters:
count- The value to set the request counter to.
-
newProjectID
Generates a new, unique project ID sequentially. Increments the internal project counter and formats the ID as "P" followed by a 4-digit number, zero-padded on the left (e.g., "P0001", "P0012", "P0123").- Returns:
- A new unique project ID string.
-
newRequestID
Generates a new, unique request ID sequentially. Increments the internal request counter (`reqeustCount` - typo noted) and formats the ID as "R" followed by a 4-digit number, zero-padded on the left (e.g., "R0001", "R0012", "R0123"). Note: Uses the static variable `reqeustCount` which has a typo.- Returns:
- A new unique request ID string.
-