Class NumberGenerator

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

public class NumberGenerator extends Object implements TypedGenerator<Number>
Generates Number instances using integer values. This generator provides a basic implementation that creates integer numbers within the full range of possible values.

Features:

  • Uses Generators.integers() internally
  • Generates values across the full integer range
  • Thread-safe implementation
  • Suitable for general numeric testing

Example usage:

 
 // Create a generator
 var generator = new NumberGenerator();
 
 // Generate single values
 Number value = generator.next();
 
 // Generate collections
 var collectionGen = new CollectionGenerator&lt;>(generator);
 List&lt;Number&gt; numbers = collectionGen.list(5); // List of 5 numbers
 
 

This generator is particularly useful for testing:

  • Generic number handling
  • Numeric type conversions
  • Mathematical operations
Author:
Oliver Wolff
See Also:
  • Constructor Details

  • Method Details

    • next

      public Number 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<Number>
      Returns:
      A newly created instance. May be null if the generator explicitly supports null value generation.
    • getType

      public Class<Number> 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<Number>
      Returns:
      The class information indicating which type this generator is responsible for.