mardi 4 septembre 2018

Passing TimeUnits and converting to milliseconds

How can I make an API for a class that the user passes a TimeUnit e.g. minutes, seconds, hours and a number and keep the millisec value internally in the class.
The following seems the only way?

void someMethodDays(int numOfDays) {  
   this.longValue = TimeUnit.DAYS.toMillis(numOfDays);  
}  

void someMethodHour(int numOfHours) {  
   this.longValue = TimeUnit.HOURS.toMillis(numOfDays);  
} etc  

Is this the only way? A method per value with a descriptive name for argument?

Aucun commentaire:

Enregistrer un commentaire