osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


On Mon, Aug 20, 2018 at 12:55 PM, sebb <sebbaz@xxxxxxxxx> wrote:
> On 20 August 2018 at 16:26, Lodewyk <jacobuslodewicus@xxxxxxxxx> 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: dev-unsubscribe@xxxxxxxxxxxxxxxxxx
> For additional commands, e-mail: dev-help@xxxxxxxxxxxxxxxxxx
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: dev-help@xxxxxxxxxxxxxxxxxx