commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Barnhill <ericbarnh...@gmail.com>
Subject Re: [LANG]DurationUtils pull request reminder
Date Tue, 12 Mar 2019 23:20:13 GMT
I think this class is on its way howver I agree with Sebb's comments there
has to be more flexibility about the rounding approach.

I am not sure a Utils class is the way to handle this flexibility. What
about a DurationRounder class or similar. Then an Enum for rounding method:
RoundingMethod.ROUND_UP,  RoundingMethod  .ROUND_DOWN etc. You will want to
include what is known in Matlab as the fix() or "round toward zero" method,
which is a common method when there are positive and negative numbers.

The user can then set the rounding method of the object during construction
(or a setter I guess). Then when the object is passed a Duration the state
of the object will dictate how it rounds. In Python or Matlab the enum
would reference a function handle, I am not sure what would be the most
elegant Java solution for such a situation -- perhaps using MethodHandle,
or using a lambda expression?

And then I would say ditto for the unit of rounding. So rather than
repetitive methods like roundUpDays(), you construct a
DurationRounder(RoundingMethod.FIX, RoundingUnit.SECONDS) and then just
call round() .

Please jump in if anyone finds this approach objectionable.

Eric

On Tue, Mar 12, 2019 at 4:05 PM Aleksander Ściborek <
aleksandersciborek@gmail.com> wrote:

> Hi,
> I would like to remind abut my pull request :
> https://github.com/apache/commons-lang/pull/406
> I know that you have a lot of work, but please take look at it - this PR
> was created almost month ago.
> Aleksander
>

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