Class IdGenerator

java.lang.Object
com.ntu.fdae.group1.bto.utils.IdGenerator

public final class IdGenerator extends Object
Utility class for generating sequential IDs with a fixed prefix and zero-padding.

This class provides thread-safe generation of unique, sequential identifiers for various entities in the BTO Management System. Each ID consists of a entity-specific prefix followed by a zero-padded sequential number.

The class maintains separate counters for each entity type and ensures that IDs remain unique across application restarts by examining existing IDs in the repositories during initialization.

IMPORTANT: The initialize() method MUST be called once at application startup AFTER data repositories have been loaded to ensure ID uniqueness across restarts.

  • Method Details

    • initialise

      public static void initialise(IProjectRepository projectRepo, IApplicationRepository applicationRepo, IBookingRepository bookingRepo, IEnquiryRepository enquiryRepo, IOfficerRegistrationRepository registrationRepo)
      Initialises the ID counters by scanning existing IDs from loaded repositories.

      This method examines all existing IDs in the provided repositories and sets each ID counter to one more than the highest existing ID of that type. This ensures that new IDs will not collide with existing ones, even after application restarts.

      This MUST be called once at startup after repositories are loaded to ensure uniqueness across application executions.

      Parameters:
      projectRepo - Loaded IProjectRepository containing existing project IDs
      applicationRepo - Loaded IApplicationRepository containing existing application IDs
      bookingRepo - Loaded IBookingRepository containing existing booking IDs
      enquiryRepo - Loaded IEnquiryRepository containing existing enquiry IDs
      registrationRepo - Loaded IOfficerRegistrationRepository containing existing registration IDs
    • generateApplicationId

      public static String generateApplicationId()
      Generates a new unique application ID.

      The ID consists of the prefix "APP" followed by a zero-padded sequential number. This method is thread-safe and atomically increments the counter.

      Returns:
      A new unique application ID string (e.g., "APP001", "APP002")
    • generateBookingId

      public static String generateBookingId()
      Generates a new unique booking ID.

      The ID consists of the prefix "BOOK" followed by a zero-padded sequential number. This method is thread-safe and atomically increments the counter.

      Returns:
      A new unique booking ID string (e.g., "BOOK001", "BOOK002")
    • generateEnquiryId

      public static String generateEnquiryId()
      Generates a new unique enquiry ID.

      The ID consists of the prefix "ENQ" followed by a zero-padded sequential number. This method is thread-safe and atomically increments the counter.

      Returns:
      A new unique enquiry ID string (e.g., "ENQ001", "ENQ002")
    • generateOfficerRegId

      public static String generateOfficerRegId()
      Generates a new unique officer registration ID.

      The ID consists of the prefix "REG" followed by a zero-padded sequential number. This method is thread-safe and atomically increments the counter.

      Returns:
      A new unique registration ID string (e.g., "REG001", "REG002")
    • generateProjectId

      public static String generateProjectId()
      Generates a new unique project ID.

      The ID consists of the prefix "PROJ" followed by a zero-padded sequential number. This method is thread-safe and atomically increments the counter.

      Returns:
      A new unique project ID string (e.g., "PROJ001", "PROJ002")
    • generateFlatInfoId

      public static String generateFlatInfoId()
      Generates a new unique flat information ID.

      The ID consists of the prefix "FLAT" followed by a zero-padded sequential number. This method is thread-safe and atomically increments the counter.

      Returns:
      A new unique flat information ID string (e.g., "FLAT001", "FLAT002")