What the Duration of negative Infinity mean?
richard.bair at oracle.com
Thu Jan 31 08:23:56 PST 2013
>> How does the animation code handle negative duration values?
> It doesn't handle negative values at all. All code in animations expects the duration to be positive.
It seems like we have to allow for negative durations for the sake of:
Duration d1 = Duration.seconds(3);
Duration d2 = Duration.seconds(-1);
Duration d3 = d1.add(d2);
This is obviously contrived (why don't I just use d1.subtract in the first place?), but if instead of hard coding the vales for 3 & -1, if they were computed by some other match routine (maybe the distance of the mouse from the object you are animating and that distance should form a duration or some such) then you could easily end up in a situation where a negative value is passed in and asking the developer to guard against that will be cumbersome.
If that's true, then we have to decide what to do about negative values in ScheduledService & animation code (and anywhere else in our API that we use a Duration). Throwing an exception from a constructor is a possibility, but from a setter not so much. I could also add an "abs" to Duration so that developers who find themselves passing negative values to an animation could use "abs" to make sure the sign comes out right in the end?
I'm also a little worried about compatibility if we start throwing exceptions for negative durations. Of course, if we did make it illegal for negative durations then the rest of the API / implementation would be much simpler. I'm worried about those Duration math methods though.
More information about the openjfx-dev