You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gilles (JIRA)" <ji...@apache.org> on 2017/07/01 17:27:03 UTC

[jira] [Comment Edited] (TEXT-97) RandomStringGenerator should be able to pass multiple ranges to .withinRange()

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

Gilles edited comment on TEXT-97 at 7/1/17 5:26 PM:
----------------------------------------------------

I'm contradicting myself but I'm not so happy with
{code}
withinRange(char[] ... pairs)
{code}

# This API does not prevent passing an argument that is not an array of pairs. It may throw {{ArrayIndexOutOfBoundsException}} or silently discard part of the input.
# Usage requires the knowledge of the ordering of the characters (whereas, it is ultimately irrelevant to the output).

What about
{code}
withinRange(char ... args)
{code}
where the code will check that {{args.length}} is a multiple of 2?

HoweverI still wonder why it would not be better to have helper methods that generate a {{char[]}} to be used with
{code}
selectFrom(char ... args)
{code}
I.e. somewhere in TEXT, there could exist
{code}
public char[] decimalDigits() {
    return new char[] {'0', '1', '2', /* etc. */ };
}
public char[] lowerCaseAscii() {
    return new char[] {'a', 'b', 'c', /* etc. */ };
}
// etc.
{code}



was (Author: erans):
I'm contradicting myself but I'm not so happy with
{code}
withinRange(char[] ... pairs)
{code}

# This API does not prevent passing an argument that is not an array of pairs. It may throw {{ArrayIndexOutOfBoundsException}} or silently discard part of the input.
# Usage requires the knowledge of the ordering of the characters (whereas, it is ultimately irrelevant to the output).

What about
{code}
withinRange(char ... args)
{code}
where the code will check that {{args.length}} is a multiple of 2?

HoweverI still wonder why it would not be better to have helper methods that generate a {{char[]}} to be used with
{code}
selectFrom(char ... args)
{code}
I.e. somewhere in TEXT, there could exist
{code}
public char[] numericCharacters() {
    return new char[] {'0', '1', '2', /* etc. */ };
}
{code}


> RandomStringGenerator should be able to pass multiple ranges to .withinRange()
> ------------------------------------------------------------------------------
>
>                 Key: TEXT-97
>                 URL: https://issues.apache.org/jira/browse/TEXT-97
>             Project: Commons Text
>          Issue Type: Improvement
>            Reporter: Amey Jadiye
>             Fix For: 1.2
>
>
> Users should have ability to pass multiple ranges to generate desired output.
> Ex. For
> *.randomNumeric()*
> {code}
> char [][]  ranges = {{'0','9'}};
> RandomStringGenerator generator = new RandomStringGenerator.Builder().withinRange(ranges).build();
> {code}
> *.randomAlphabetic()*
> {code}
> char [][]  ranges = {{'A','Z'}}; // or {{'A','Z'},{'a','z'}}
> RandomStringGenerator generator = new RandomStringGenerator.Builder().withinRange(ranges).build();
> {code}
> *.randomAlphanumeric()*
> {code}
> char [][]  ranges = {{'0','9'},{'A','Z'},{'a','b'}};
> RandomStringGenerator generator = new RandomStringGenerator.Builder().withinRange(ranges).build();
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)