Class ZipCodeGenerator

java.lang.Object
de.cuioss.test.generator.domain.ZipCodeGenerator
All Implemented Interfaces:
TypedGenerator<Integer>

public class ZipCodeGenerator extends Object implements TypedGenerator<Integer>
Generates German postal codes (Postleitzahlen) for test data generation.

Characteristics:

  • Generates 5-digit postal codes
  • Range: 10000 - 99999
  • Format matches official German postal code format

Example usage:

 var generator = new ZipCodeGenerator();
 Integer zipCode = generator.next(); // e.g. 12345
 String formattedZip = String.format("%05d", zipCode); // Ensures 5 digits with leading zeros
 

Note: This generator returns Integer values. For display purposes, you may want to format the number to ensure it always shows 5 digits.

Author:
Oliver Wolff
  • Constructor Details

  • Method Details

    • next

      public Integer next()
      Description copied from interface: TypedGenerator
      Generates the next instance based on the generator's configuration. Implementations must ensure thread-safety.
      Specified by:
      next in interface TypedGenerator<Integer>
      Returns:
      A newly created instance. May be null if the generator explicitly supports null value generation.
    • getType

      public Class<Integer> getType()
      Description copied from interface: TypedGenerator
      Provides type information about what kind of objects this generator creates. The default implementation uses the first non-null result from TypedGenerator.next() to determine the type.

      Note: If your generator may return null values or the generated type differs from the actual instance type, you should override this method.

      Specified by:
      getType in interface TypedGenerator<Integer>
      Returns:
      The class information indicating which type this generator is responsible for.