Generex icon indicating copy to clipboard operation
Generex copied to clipboard

add 2 methods to Generex: generateMaxLength + generateMinLength

Open astik opened this issue 8 years ago • 3 comments

Automaton is not exposed though Generex. This is a not cool because it exposes some useful methods for information.

Those changes expose 2 methods to get sizes for the shortest and longest string that can be generated (which can be useful if you need to define regexp that produce string with a constraint length)

astik avatar Feb 09 '17 06:02 astik

In the meantime, here is a workaround :

  private Automaton getAutomaton() {
    // this method is necessary as Generex does not expose automaton.
    // as soon as it will (if it will), this method should be remove
    // see https://github.com/mifmif/Generex/pull/37
    try {
      return (Automaton) FieldUtils.readField(generex, "automaton", true);
    } catch (IllegalAccessException e) {
      throw new TechnicalException("Failure to access private attribute automaton from generex instance", e);
    }
  }

This allow me to access the automaton instance from the generex one. As it uses reflection, be careful =)

astik avatar Feb 09 '17 07:02 astik

Could you please provide a description with some examples that shows when to use the exposed Automaton and the two additional methods (min/max). Test cases are also required to validate the implementation of those methods.

Thanks.

mifmif avatar Feb 15 '17 17:02 mifmif

I added the unit test for min and max length expectations.

Here is a use case we have currently with Generex :

  • we create random identifier for multiple entity's types
  • an entity's type have a grammar that defines the identifier regex
  • a grammar / regex is defined and should be bound between a minimum possible length (for example 3) and a maximum possible length (for example 20), so that we are sure that identifier's length is between 3 and 20.
  • when creating a grammar we need a way to validate the theoretical min and max length for a regex in order to display proper message to the user

For this particular validation need, we need to access those 2 status from automaton.

astik avatar Feb 16 '17 02:02 astik