Time for my first blog of the year. Yea! Mind you its a bit small, but then perhaps that is a good thing.
Look at these two setters. Setter methods like the first example are very common. Take a look at the second its so much better. With the second the responsibility to convert is neatly delegated to another class instead of forcing the user of the api to work it out. In addition the programmer can supply hours, minutes or any other that TimeUnit supports.
public void setDuration(long durationInMs) {
this.duration = durationInMs;
}
public void setDuration(long duration, TimeUnit timeUnit) {
this.duration = timeUnit.toMillis(duration);
}
TimeUnit was brought to you by: java.util.concurrent.TimeUnit! Its handy, so use it!