commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Javen O'Neal" <one...@apache.org>
Subject Re: AW: [commons-lang3] NumberUtils feature
Date Mon, 01 Jan 2018 09:27:47 GMT
I'm -1 for a static function as suggested by Lucas. It doesn't improve code
readability, and I'd argue that it decreases readability because of needing
to memorize operator order, ambiguous inclusivity of endpoints (unless you
add isStrictlyBetween), and doesn't gracefully handle mixed data types,
especially non-primitives like fixed precision decimals or fractions.

Even with better named endpoints x and y as min/max, lowerBound/upperBound.
What significant benefit does defining this function provide?

Java syntax might not be as concise as other languages like Python that
allow writing "lowerBound <= value <= upperBound", but a function call
doesn't seem right here.

BiInclusiveRange(lowerBound, upperBound).contains(value) seems like a
better approach.

On Dec 31, 2017 02:31, "Gilles" <gilles@harfang.homelinux.org> wrote:

On Sat, 30 Dec 2017 14:25:32 +0100, Jan Matèrne wrote:

> Maybe open the comparators and use a fluent API?
> is(42).between(10).and(50) == true
> is(10).between(10).and(20) == false
> is(10).between(10).and(20).includingLeft() == true
> is(50).between(10).and(50) == false
> is(50).between(10).and(50).includingRight() == true
>

There is "Range":
  http://commons.apache.org/proper/commons-lang/javadocs/api-
release/org/apache/commons/lang3/Range.html

Is the original suggestion meant to create an implementation
for primitive types?

Gilles



>
> Just quick thoughts ...
>
> Jan
>
>
> -----Urspr√ľngliche Nachricht-----
>> Von: Gilles [mailto:gilles@harfang.homelinux.org]
>> Gesendet: Freitag, 29. Dezember 2017 22:46
>> An: dev@commons.apache.org
>> Betreff: Re: [commons-lang3] NumberUtils feature
>>
>> On Fri, 29 Dec 2017 16:19:05 -0200, Lucas Carvalho wrote:
>> > Gilles, thanks for you reply.
>> >
>> > I will consider your sugestions.
>> >
>> > So, can i open a issue in jira (apache commons) and implement this
>> > feature?
>>
>> Better wait for other opinions on the various suggestions, as it
>> impacts on which JIRA project you'd open the issue.
>>
>> Regards,
>> Gilles
>>
>> >
>> > Thanks.
>> >
>> > Lucas Carvalho
>> >
>> >
>> >
>> > On Fri, Dec 29, 2017 at 12:25 PM, Gilles
>> > <gilles@harfang.homelinux.org>
>> > wrote:
>> >
>> >> Hi.
>> >>
>> >> On Fri, 29 Dec 2017 11:53:29 -0200, Lucas Carvalho wrote:
>> >>
>> >>> I`m sorry,
>> >>>
>> >>> Now code in "text":
>> >>>
>> >>> public static boolean between(final int value, final int x, final
>> >>> int y) {
>> >>>
>> >>>    return value >= x && value <= y;
>> >>>
>> >>> }
>> >>>
>> >>>
>> >>> public static boolean between(final short value, final short x,
>> >>> final short
>> >>> y) {
>> >>>
>> >>>    return value >= x && value <= y;
>> >>>
>> >>> }
>> >>>
>> >>
>> >> To comply with the Java convention, it should probably be
>> >> "isBetween".
>> >>
>> >> Incidently, this also shows a weakness of "Utils" classes: the
>> >> "target"
>> >> (which would normally be "this") is on the same footing as the other
>> >> arguments (the bounds of the interval here).
>> >>
>> >> Also the naming does not reflect whether bounds are included or not:
>> >> usually, one would assume that the left bound is included (>=) but
>> >> not the right one (<).
>> >>
>> >> Then, what about "between(15, 20, 10)"?
>> >>
>> >> Finally, we should consider whether to continue bloating
>> >> "NumberUtils"
>> >> in "Lang" or move some of it to the new "Numbers" component.[1]
>> >>
>> >> Regards,
>> >> Gilles
>> >>
>> >> [1]
>> >> https://git1-us-west.apache.org/repos/asf?p=commons-
>> numbers.git;a=tre
>> >> e
>> >>
>> >>
>> >>>
>> >>>
>> >>> Obrigado.
>> >>>
>> >>> Atenciosamente
>> >>>
>> >>> Lucas Carvalho
>> >>>
>> >>> *Fone *- 34 9 9903 4621
>> >>>
>> >>> On Fri, Dec 29, 2017 at 11:47 AM, Gilles
>> >>> <gilles@harfang.homelinux.org>
>> >>> wrote:
>> >>>
>> >>> Hi.
>> >>>>
>> >>>> On Fri, 29 Dec 2017 09:51:59 -0200, Lucas Carvalho wrote:
>> >>>>
>> >>>> Hello everybody,
>> >>>>>
>> >>>>> I want know if the feature "between" in NumberUtils lib has
be
>> >>>>> discussed?
>> >>>>> I
>> >>>>> use this methods a lot and i would like to share this code in
>> >>>>> apache commons.
>> >>>>>
>> >>>>> Below i share a example:
>> >>>>>
>> >>>>> [image: Inline image 1]
>> >>>>>
>> >>>>>
>> >>>> All I can see is the above.
>> >>>> [Perhaps the image was stripped.]
>> >>>>
>> >>>> I assume it is code; so, please write it here as "text".
>> >>>>
>> >>>> Thanks,
>> >>>> Gilles
>> >>>>
>> >>>>
>> >>>> Thanks.
>> >>>>>
>> >>>>> Lucas Carvalho
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message