Request to extend StringUtils: Check String length falls within interval

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Request to extend StringUtils: Check String length falls within interval

Lodewyk
Hi,

I would like to extend StringUtils. I looked through the GitHub repository
and it was suggested that I check if the intended feature falls within the
scope of Apache Commons Lang first.

I intend on adding a function that will return either true or false if the
length of a String is between a specified interval.

Example Function Descriptor:

> public boolean isLengthBetween(int begin, int end, String str)


This will cut out the need for having to test the length of a String as
follows:

> if (name.length() < 3 || name.length() > 32) {
>     throw new IllegalArgumentException();
> }
>

With the intended addition:

> if (!isLengthBetween(3, 32)) {
>      throw new IllegalArgumentException();
> }


Thank you.

Kind Regards,
Jacobus Lodewicus
Reply | Threaded
Open this post in threaded view
|

Re: Request to extend StringUtils: Check String length falls within interval

sebb-2-2
On 20 August 2018 at 16:26, Lodewyk <[hidden email]> wrote:
> Hi,
>
> I would like to extend StringUtils. I looked through the GitHub repository
> and it was suggested that I check if the intended feature falls within the
> scope of Apache Commons Lang first.
>
> I intend on adding a function that will return either true or false if the
> length of a String is between a specified interval.

What if the string is null?

> Example Function Descriptor:
>
>> public boolean isLengthBetween(int begin, int end, String str)
>
>
> This will cut out the need for having to test the length of a String as
> follows:
>
>> if (name.length() < 3 || name.length() > 32) {
>>     throw new IllegalArgumentException();
>> }
>>
>
> With the intended addition:
>
>> if (!isLengthBetween(3, 32)) {

Missing string parameter?

>>      throw new IllegalArgumentException();
>> }
>
>
> Thank you.

Seems to me it would be better to have a generic range checker that
operates on the string length, rather than a special-purpose method
just for strings.

> Kind Regards,
> Jacobus Lodewicus

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Request to extend StringUtils: Check String length falls within interval

Woonsan Ko-3
On Mon, Aug 20, 2018 at 12:55 PM, sebb <[hidden email]> wrote:

> On 20 August 2018 at 16:26, Lodewyk <[hidden email]> wrote:
>> Hi,
>>
>> I would like to extend StringUtils. I looked through the GitHub repository
>> and it was suggested that I check if the intended feature falls within the
>> scope of Apache Commons Lang first.
>>
>> I intend on adding a function that will return either true or false if the
>> length of a String is between a specified interval.
>
> What if the string is null?
>
>> Example Function Descriptor:
>>
>>> public boolean isLengthBetween(int begin, int end, String str)
>>
>>
>> This will cut out the need for having to test the length of a String as
>> follows:
>>
>>> if (name.length() < 3 || name.length() > 32) {
>>>     throw new IllegalArgumentException();
>>> }
>>>
>>
>> With the intended addition:
>>
>>> if (!isLengthBetween(3, 32)) {
>
> Missing string parameter?
>
>>>      throw new IllegalArgumentException();
>>> }
>>
>>
>> Thank you.
>
> Seems to me it would be better to have a generic range checker that
> operates on the string length, rather than a special-purpose method
> just for strings.
Seems like we already have one:
- org.apache.commons.lang3.Range<T>
- org.apache.commons.lang.math.IntRange

>
>> Kind Regards,
>> Jacobus Lodewicus
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]