Interface BigDecimalAsGeneratorSpec
- All Superinterfaces:
AsGeneratorSpec<BigDecimal>
,BigDecimalGeneratorSpec
,GeneratorSpec<BigDecimal>
,NullableGeneratorSpec<BigDecimal>
,NumberGeneratorSpec<BigDecimal>
BigDecimal
values
that supports AsGeneratorSpec
.- Since:
- 2.6.0
-
Method Summary
Modifier and TypeMethodDescriptionmax
(BigDecimal max) Specifies the upper bound.min
(BigDecimal min) Specifies the lower bound.nullable()
Specifies that anull
can be generated.precision
(int precision) Precision of the generatedBigDecimal
.range
(BigDecimal min, BigDecimal max) Specifies the range for generated numbers.scale
(int scale) Scale of the generatedBigDecimal
.Methods inherited from interface org.instancio.generator.specs.AsGeneratorSpec
as, asString
-
Method Details
-
min
Specifies the lower bound.Note that this method is incompatible with
BigDecimalGeneratorSpec.precision(int)
. For details, seeBigDecimalGeneratorSpec.precision(int)
javadoc.Note that this method is incompatible with
precision(int)
. For details, seeprecision(int)
javadoc.- Specified by:
min
in interfaceBigDecimalGeneratorSpec
- Specified by:
min
in interfaceNumberGeneratorSpec<BigDecimal>
- Parameters:
min
- lower bound (inclusive)- Returns:
- spec builder
-
max
Specifies the upper bound.Note that this method is incompatible with
BigDecimalGeneratorSpec.precision(int)
. For details, seeBigDecimalGeneratorSpec.precision(int)
javadoc.Note that this method is incompatible with
precision(int)
. For details, seeprecision(int)
javadoc.- Specified by:
max
in interfaceBigDecimalGeneratorSpec
- Specified by:
max
in interfaceNumberGeneratorSpec<BigDecimal>
- Parameters:
max
- upper bound (inclusive)- Returns:
- spec builder
-
range
Specifies the range for generated numbers.The following examples use
int
, however the same principle applies to all numeric types, includingBigInteger
andBigDecimal
.This method can be invoked multiple times to specify several ranges, for example, the following will generate a random value within
[10-15]
or[20-25]
:
Note: this method has higher precedence thanints().range(10, 15).range(20, 25)
NumberGeneratorSpec.min(Number)
andNumberGeneratorSpec.max(Number)
. For example, the following will generate a number within[1, 5]
:ints().range(1, 5).min(95).max(99)
Note that this method is incompatible with
BigDecimalGeneratorSpec.precision(int)
. For details, seeBigDecimalGeneratorSpec.precision(int)
javadoc.Note that this method is incompatible with
precision(int)
. For details, seeprecision(int)
javadoc.- Specified by:
range
in interfaceBigDecimalGeneratorSpec
- Specified by:
range
in interfaceNumberGeneratorSpec<BigDecimal>
- Parameters:
min
- lower bound (inclusive)max
- upper bound (inclusive)- Returns:
- spec builder
-
nullable
BigDecimalAsGeneratorSpec nullable()Description copied from interface:NumberGeneratorSpec
Specifies that anull
can be generated.- Specified by:
nullable
in interfaceBigDecimalGeneratorSpec
- Specified by:
nullable
in interfaceNullableGeneratorSpec<BigDecimal>
- Specified by:
nullable
in interfaceNumberGeneratorSpec<BigDecimal>
- Returns:
- spec builder
-
scale
Description copied from interface:BigDecimalGeneratorSpec
Scale of the generatedBigDecimal
. Generated values will have givenscale
as returned byBigDecimal.scale()
.If not specified, the default scale is
2
.- Specified by:
scale
in interfaceBigDecimalGeneratorSpec
- Parameters:
scale
- the scale of generatedBigDecimal
values- Returns:
- spec builder
-
precision
Precision of the generatedBigDecimal
. Generated values will have givenprecision
as returned byBigDecimal.precision()
.This method is incompatible with the following methods:
BigDecimalGeneratorSpec.min(BigDecimal)
BigDecimalGeneratorSpec.min(BigDecimal)
BigDecimalGeneratorSpec.range(BigDecimal, BigDecimal)
If this method is combined with any of the above, the last method takes precedence.
// Example 1: range() takes precedence as it is specified last BigDecimal result = Gen.math().bigDecimal() .precision(5) .range(BigDecimal.ZERO, BigDecimal.ONE) .get(); // Sample output: 0.81 // Example 2: precision() takes precedence as it is specified last BigDecimal result = Gen.math().bigDecimal() .range(BigDecimal.ZERO, BigDecimal.ONE) .precision(5) .get(); // Sample output: 394.19
- Specified by:
precision
in interfaceBigDecimalGeneratorSpec
- Parameters:
precision
- the precision of generatedBigDecimal
values- Returns:
- spec builder
- Since:
- 3.3.0
-