commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexander Tsvetkov (JIRA)" <j...@apache.org>
Subject [jira] [Created] (LANG-1412) Add toArray method to CharSet
Date Wed, 15 Aug 2018 09:05:00 GMT
Alexander Tsvetkov created LANG-1412:
----------------------------------------

             Summary: Add toArray method to CharSet
                 Key: LANG-1412
                 URL: https://issues.apache.org/jira/browse/LANG-1412
             Project: Commons Lang
          Issue Type: New Feature
            Reporter: Alexander Tsvetkov


We have a project where we generate a random string from a set of legal characters like this:
{code:java}
StringBuilder stringBuilder = new StringBuilder(length);
for (int i = 0; i < length; i++) {
    int randomIndex = randomGenerator.nextInt(LEGAL_CHARACTERS.length);
    stringBuilder.append(LEGAL_CHARACTERS[randomIndex]);
}
return stringBuilder.toString();
{code}
Where LEGAL_CHARACTERS is a char array. The problem is that initializing the LEGAL_CHARACTERS
array is not very pretty and we would like to do it this way:
{code:java}
private static final char[] LEGAL_CHARACTERS = CharSet.getInstance("A-Z", "a-z", "0-9", "-",
"_@()&#*[]").toArray();
{code}
Do you think this would be a good addition to Commons Lang in general? If yes, then is CharSet
the right place for that?



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message