I am used to developing in Python, but for work reasons have to do it in Java. I am facing a task that would be trivial in Python, and I'd like some advice on how to handle this in Java the proper way.
I need to parse a duration string. It can be in milliseconds (235ms) or seconds (32s). And it can also be "< 1ms" as a special case.
The parsing happens at least three times in the code so I'd like to separate it into a method. But my code does need to know, not just the resulting value in ms, but also whether it was in ms or s and whether it was <1ms (0 is a different value).
In Python I would just return a tuple:
return (value_in_milliseconds,is_in_seconds,is_under_1ms)
In C I would define a struct of these three values and return it. In Pascal I'd define a record.
In Java I can't return a tuple and I can't define a record so what do I do?
The only thing I can think of is creating a class representing a duration value. The constructor would take the string and parse it. The class would have fields: int milliseconds, boolean inSeconds, boolean under 1ms .
But this sounds terribly heavyweight - is there a better solution?