Class ZoneOffsetGenerator

java.lang.Object
de.cuioss.test.generator.impl.ZoneOffsetGenerator
All Implemented Interfaces:
TypedGenerator<ZoneOffset>

public class ZoneOffsetGenerator extends Object implements TypedGenerator<ZoneOffset>
Generates ZoneOffset instances based on the available system time zones. This generator creates offsets by sampling from all available zone IDs and extracting their current offsets.

Features:

  • Uses all system-available zone IDs (ZoneId.getAvailableZoneIds())
  • Generates valid offsets based on current time
  • Covers both positive and negative offsets
  • Thread-safe implementation

Example usage:

 
 // Create a generator
 var generator = new ZoneOffsetGenerator();
 
 // Generate single values
 ZoneOffset offset = generator.next();
 
 // Generate collections
 var collectionGen = new CollectionGenerator&lt;&gt;(generator);
 List&lt;ZoneOffset&gt; offsets = collectionGen.list(5); // List of 5 offsets
 
 

This generator is particularly useful for testing:

  • Time zone offset calculations
  • UTC conversions
  • Date-time formatting with offsets
  • International time handling
Author:
Eugen Fischer
See Also:
  • Constructor Details

  • Method Details

    • next

      public ZoneOffset 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<ZoneOffset>
      Returns:
      A newly created instance. May be null if the generator explicitly supports null value generation.
    • 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<ZoneOffset>
      Returns:
      The class information indicating which type this generator is responsible for.