Class RgxGen


  • public class RgxGen
    extends Object
    String values generator based on regular expression pattern
    • 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. Set null to 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 either setDefaultProperties or default hardcoded.
        Parameters:
        properties - configuration properties. Set null to reset.
        See Also:
        RgxGenOption
      • numUnique

        @Deprecated
        public BigInteger numUnique()
        Deprecated.
        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
      • 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.
      • generateNotMatching

        public String generateNotMatching​(Random random)
        Generate random string that does not match a pattern. Random initialized with same seed will produce same results.
        Parameters:
        random - random to use for the generation.
        Returns:
        generated string.