Adrian Crum wrote: > Adam Heath wrote: >> The javadoc for org.ofbiz.base.util.TimeDuration says it is immutable; >> however, it's fields are not final, and lots of methods modify it's >> fields. > > The methods that modify fields are directly or indirectly called by the > constructor and are protected. Let me know if any public method modifies > a field.
fromLong modifies the fields directly, not from the constructor. makeNegative modifies the fields. set() is protected, TimeDuration is not final, so sub-classes could change the fields. If this were a proper immutable class, it could be used as a key in a map. Ideally, this class should extend Number, or some other number class. It should also normalize it's values. If I set a duration of 86400 seconds, it should normalize to 1 day. Also, the 7 arg constructor incorrectly sets itself negative. If I set a duration of 5 days, and -30 seconds, it'll think it's negative. >> Was there any research into other duration implementations? I see one >> at javax.xml.datatype.Duration, that seems mostly compatible, except >> that it doesn't have millisecond resolution. > > I spent some time Googling publicly available JavaDocs and got the basic > idea from what I found. >
