I've actually come up with a better solution but I'll have time on weekend On Mon, Mar 18, 2019, 17:51 Eric Barnhill <ericbarnh...@gmail.com> wrote:
> I don't have time to unravel this for you, and I am not saying my proposed > idea was the best, but generally it is an antipattern to have a bunch of > similarly named methods performing approximately the same task. > > It is a nice idea for a common utility but surely there is a way to > implement it where someone sets the rounding method and precision somehow, > and then calls round(), rather than having lots of method names like > "roundUpDays()". > > On Sun, Mar 17, 2019 at 2:49 PM Aleksander Ściborek < > aleksanderscibo...@gmail.com> wrote: > > > I was thinking about this, the implementation of Duration class makes it > > quite hard. If method "public long get(TemporalUnit unit)" from Duration > > class supported all ChronoUnit it would be pretty easy to do, but with > the > > current implementation I would have to make a lot of switch or if > > statements so therefore I don't see to much benefits from make this in > more > > objectish way > > > > > > On Wed, 13 Mar 2019 at 00:20, Eric Barnhill <ericbarnh...@gmail.com> > > wrote: > > > > > 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 < > > > aleksanderscibo...@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 > > > > > > > > > >