Package com.github.curiousoddman.rgxgen
Class RgxGen
- java.lang.Object
-
- com.github.curiousoddman.rgxgen.RgxGen
-
public class RgxGen extends Object
String values generator based on regular expression pattern
-
-
Constructor Summary
Constructors Constructor Description RgxGen(NodeTreeBuilder builder)Parse regex pattern using provided builder and prepare to generate valuesRgxGen(CharSequence pattern)Parse pattern using DefaultTreeBuilder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Stringgenerate()Generate random string from the pattern.Stringgenerate(Random random)Generate random string from the pattern.StringgenerateNotMatching()Generate random string that does not match a pattern.StringgenerateNotMatching(Random random)Generate random string that does not match a pattern.Optional<BigInteger>getUniqueEstimation()Returns estimation of unique values that can be generated with the pattern.StringIteratoriterateUnique()Creates iterator over unique values.BigIntegernumUnique()Deprecated.usegetUniqueEstimation()insteadstatic voidsetDefaultProperties(RgxGenProperties properties)Set default properties for RgxGen.voidsetProperties(RgxGenProperties properties)Set properties for the instance of RgxGen.Stream<String>stream()Creates infinite stream of randomly generated values.
-
-
-
Constructor Detail
-
RgxGen
public RgxGen(CharSequence pattern)
Parse pattern using DefaultTreeBuilder.- Parameters:
pattern- regex pattern for values generation
-
RgxGen
public RgxGen(NodeTreeBuilder builder)
Parse regex pattern using provided builder and prepare to generate values- Parameters:
builder- node tree builder implementation
-
-
Method Detail
-
setDefaultProperties
public static void setDefaultProperties(RgxGenProperties properties)
Set default properties for RgxGen. Each new instance of RgxGen will use these properties as a backup, if property is not set per instance.- Parameters:
properties- configuration properties. Setnullto reset.- See Also:
RgxGenOption- API Note:
- Existing instances will not be affected. Only those, that will be created after this call.
-
setProperties
public void setProperties(RgxGenProperties properties)
Set properties for the instance of RgxGen. These options will override default values set by eithersetDefaultPropertiesor default hardcoded.- Parameters:
properties- configuration properties. Setnullto reset.- See Also:
RgxGenOption
-
numUnique
@Deprecated public BigInteger numUnique()
Deprecated.usegetUniqueEstimation()insteadReturns estimation of unique values that can be generated with the pattern.- Returns:
- number of unique values or null, if infinite
- API Note:
- This might not be accurate! For example the pattern "(a{0,2}|b{0,2})" will estimate to 6, though actual count is only 5, because right and left part of group can yield same value
-
getUniqueEstimation
public Optional<BigInteger> getUniqueEstimation()
Returns estimation of unique values that can be generated with the pattern.- Returns:
- number of unique values or null, if infinite
- API Note:
- This might not be accurate! For example the pattern "(a{0,2}|b{0,2})" will estimate to 6, though actual count is only 5, because right and left part of group can yield same value
-
stream
public Stream<String> stream()
Creates infinite stream of randomly generated values.- Returns:
- stream of randomly generated strings
- See Also:
generate()
-
iterateUnique
public StringIterator iterateUnique()
Creates iterator over unique values.- Returns:
- Iterator over unique values
-
generate
public String generate()
Generate random string from the pattern.- Returns:
- matching random string
-
generate
public String generate(Random random)
Generate random string from the pattern. Random initialized with same seed will produce same results.- Parameters:
random- random to use for the generation.- Returns:
- generated string.
-
generateNotMatching
public String generateNotMatching()
Generate random string that does not match a pattern.- Returns:
- not matching random string.
-
-