Class Mod10Generator
java.lang.Object
org.instancio.internal.generator.AbstractGenerator<String>
org.instancio.internal.generator.checksum.BaseModCheckGenerator
org.instancio.internal.generator.checksum.Mod10Generator
- All Implemented Interfaces:
Generator<String>
,GeneratorSpec<String>
,AsGeneratorSpec<String>
,Mod10AsGeneratorSpec
,Mod10GeneratorSpec
,Mod10Spec
,NullableGeneratorSpec<String>
,ValueSpec<String>
,InternalLengthGeneratorSpec<String>
public class Mod10Generator
extends BaseModCheckGenerator
implements Mod10AsGeneratorSpec, Mod10Spec
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the public API method name of the generator spec.checkDigitIndex
(int idx) The index of the check digit in the input.protected int
endIndex
(int idx) The end index for calculating the checksum.protected int
even
(int position) length
(int length) Length of the number to generate (default value is16
).org.instancio.internal.generator.checksum.VariableLengthModCheckGenerator
length
(int min, int max) multiplier
(int multiplier) Multiplier to be used for odd digits when calculating the Mod10 checksum (default value is3
).nullable()
Indicates thatnull
value can be generated.nullable
(boolean isNullable) protected int
odd
(int position) protected int
protected int
startIndex
(int idx) The start index for calculating the checksum (default value is0
).protected int
protected boolean
protected String
tryGenerateNonNull
(Random random) Makes the best effort to return a non-null value.weight
(int weight) The weight to be used for even digits when calculating the Mod10 checksum (default value is1
).Methods inherited from class org.instancio.internal.generator.checksum.BaseModCheckGenerator
base, direction, payload, treat10As, treat11As
Methods inherited from class org.instancio.internal.generator.AbstractGenerator
generate, getContext, hints, isNullable
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.instancio.generator.specs.AsGeneratorSpec
as, asString
-
Constructor Details
-
Mod10Generator
public Mod10Generator() -
Mod10Generator
-
-
Method Details
-
apiMethod
Description copied from class:AbstractGenerator
Returns the public API method name of the generator spec. The returned name is used for reporting validation errors.- Specified by:
apiMethod
in classAbstractGenerator<String>
- Returns:
- spec name if defined, or
null
otherwise
-
length
Description copied from interface:Mod10GeneratorSpec
Length of the number to generate (default value is16
).- Specified by:
length
in interfaceMod10AsGeneratorSpec
- Specified by:
length
in interfaceMod10GeneratorSpec
- Specified by:
length
in interfaceMod10Spec
- Parameters:
length
- of the number to generate- Returns:
- spec builder
-
multiplier
Description copied from interface:Mod10GeneratorSpec
Multiplier to be used for odd digits when calculating the Mod10 checksum (default value is3
).- Specified by:
multiplier
in interfaceMod10AsGeneratorSpec
- Specified by:
multiplier
in interfaceMod10GeneratorSpec
- Specified by:
multiplier
in interfaceMod10Spec
- Parameters:
multiplier
- for odd digits- Returns:
- spec builder
-
weight
Description copied from interface:Mod10GeneratorSpec
The weight to be used for even digits when calculating the Mod10 checksum (default value is1
).- Specified by:
weight
in interfaceMod10AsGeneratorSpec
- Specified by:
weight
in interfaceMod10GeneratorSpec
- Specified by:
weight
in interfaceMod10Spec
- Parameters:
weight
- for even digits- Returns:
- spec builder
-
startIndex
Description copied from interface:Mod10GeneratorSpec
The start index for calculating the checksum (default value is0
).- Specified by:
startIndex
in interfaceMod10AsGeneratorSpec
- Specified by:
startIndex
in interfaceMod10GeneratorSpec
- Specified by:
startIndex
in interfaceMod10Spec
- Parameters:
idx
- for calculating the checksum (inclusive)- Returns:
- spec builder
-
endIndex
Description copied from interface:Mod10GeneratorSpec
The end index for calculating the checksum.- Specified by:
endIndex
in interfaceMod10AsGeneratorSpec
- Specified by:
endIndex
in interfaceMod10GeneratorSpec
- Specified by:
endIndex
in interfaceMod10Spec
- Parameters:
idx
- for calculating the checksum (inclusive)- Returns:
- spec builder
-
checkDigitIndex
Description copied from interface:Mod10GeneratorSpec
The index of the check digit in the input. If not specified, the last digit will be used as the check digit.If set, the digit at the specified index is used. If set the following must hold true:
checkDigitIndex >= 0 && (checkDigitIndex < startIndex || checkDigitIndex >= endIndex)
.- Specified by:
checkDigitIndex
in interfaceMod10AsGeneratorSpec
- Specified by:
checkDigitIndex
in interfaceMod10GeneratorSpec
- Specified by:
checkDigitIndex
in interfaceMod10Spec
- Parameters:
idx
- index of the check digit- Returns:
- spec builder
-
nullable
Description copied from interface:NullableGeneratorSpec
Indicates thatnull
value can be generated.- Specified by:
nullable
in interfaceMod10AsGeneratorSpec
- Specified by:
nullable
in interfaceMod10GeneratorSpec
- Specified by:
nullable
in interfaceMod10Spec
- Specified by:
nullable
in interfaceNullableGeneratorSpec<String>
- Specified by:
nullable
in interfaceValueSpec<String>
- Overrides:
nullable
in classAbstractGenerator<String>
- Returns:
- spec builder
-
nullable
- Overrides:
nullable
in classAbstractGenerator<String>
-
even
protected int even(int position) - Overrides:
even
in classBaseModCheckGenerator
-
odd
protected int odd(int position) - Overrides:
odd
in classBaseModCheckGenerator
-
sumDigits
protected boolean sumDigits()- Overrides:
sumDigits
in classBaseModCheckGenerator
-
length
public org.instancio.internal.generator.checksum.VariableLengthModCheckGenerator length(int min, int max) - Specified by:
length
in interfaceInternalLengthGeneratorSpec<String>
-
tryGenerateNonNull
Description copied from class:AbstractGenerator
Makes the best effort to return a non-null value. However, in certain cases this method will produce anull
.- Overrides:
tryGenerateNonNull
in classBaseModCheckGenerator
- Parameters:
random
- for generating the value- Returns:
- generated value, either a null or non-null
-
prefixLength
protected int prefixLength()- Overrides:
prefixLength
in classBaseModCheckGenerator
-
payloadLength
protected int payloadLength()- Specified by:
payloadLength
in classBaseModCheckGenerator
-
checkPosition
protected int checkPosition()- Overrides:
checkPosition
in classBaseModCheckGenerator
-
suffixLength
protected int suffixLength()- Overrides:
suffixLength
in classBaseModCheckGenerator
-