Interface BigDecimalGeneratorSpec
- All Superinterfaces:
AsGeneratorSpec<BigDecimal>,GeneratorSpec<BigDecimal>,NullableGeneratorSpec<BigDecimal>,NumberGeneratorSpec<BigDecimal>
- All Known Subinterfaces:
BigDecimalSpec
BigDecimal.- Since:
- 1.5.4
-
Method Summary
Modifier and TypeMethodDescriptionmax(BigDecimal max) Specifies the upper bound.min(BigDecimal min) Specifies the lower bound.nullable()Specifies that anullcan 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
precision(int). For details, seeprecision(int)javadoc.- Specified by:
minin interfaceNumberGeneratorSpec<BigDecimal>- Parameters:
min- lower bound (inclusive)- Returns:
- spec builder
-
max
Specifies the upper bound.Note that this method is incompatible with
precision(int). For details, seeprecision(int)javadoc.- Specified by:
maxin 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, includingBigIntegerandBigDecimal.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
precision(int). For details, seeprecision(int)javadoc.- Specified by:
rangein interfaceNumberGeneratorSpec<BigDecimal>- Parameters:
min- lower bound (inclusive)max- upper bound (inclusive)- Returns:
- spec builder
-
nullable
BigDecimalGeneratorSpec nullable()Description copied from interface:NumberGeneratorSpecSpecifies that anullcan be generated.- Specified by:
nullablein interfaceNullableGeneratorSpec<BigDecimal>- Specified by:
nullablein interfaceNumberGeneratorSpec<BigDecimal>- Returns:
- spec builder
-
scale
Scale of the generatedBigDecimal. Generated values will have givenscaleas returned byBigDecimal.scale().If not specified, the default scale is
2.- Parameters:
scale- the scale of generatedBigDecimalvalues- Returns:
- spec builder
- Since:
- 1.5.4
-
precision
Precision of the generatedBigDecimal. Generated values will have givenprecisionas returned byBigDecimal.precision().This method is incompatible with the following methods:
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 = Instancio.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 = Instancio.gen().math().bigDecimal() .range(BigDecimal.ZERO, BigDecimal.ONE) .precision(5) .get(); // Sample output: 394.19- Parameters:
precision- the precision of generatedBigDecimalvalues- Returns:
- spec builder
- Since:
- 3.3.0
-