Uploaded image for project: 'Commons Text'
  1. Commons Text
  2. TEXT-96

Convenience methods needed for RandomStringGenerator

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.1
    • None
    • None

    Description

      RandomStringGenerator is extremely verbose compared to the deprecated commons.lang3 RandomStringUtils.

      Previously we could write:

      RandomStringUtils.randomNumeric(10)
      

      to generate a numeric string whereas this now has become:

      new RandomStringGenerator.Builder().withinRange('0', '9').build().generate(10)
      

      although in practice we would then also use static imports too.
      The randomAlphabetic conversion is even more verbose:

      new RandomStringGenerator.Builder().withinRange('A', 'z').filteredBy(new CharacterPredicate() {
                          @Override
                          public boolean test(int codePoint) {
                              return codePoint >= 'a' || codePoint <= 'Z';
                          }
                      }).build().generate(10))
      

      and at that point I lost enthusiam with trying to replicate randomAlphanumeric.

      I don't think the average java developer would understand what a code point is in the first place so then trying to get our automation testers to use the new API to implement random alphanumeric character generation would be difficult.

      I therefore suggest that commons-text should have a copy of RandomStringUtils which can even delegate to RandomStringGenerator or alternatively convenience static methods for the common use cases.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              greenth Peter Phillips
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: