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] [Commented] (LANG-1412) Add toArray method to CharSet
Date Wed, 15 Aug 2018 09:57:00 GMT

    [ https://issues.apache.org/jira/browse/LANG-1412?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16580900#comment-16580900
] 

Alexander Tsvetkov commented on LANG-1412:
------------------------------------------

I can contribute this feature to https://github.com/apache/commons-lang/ if you see any value
in it and are willing to review it. :)

> 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
>            Priority: Major
>
> 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