(
long sourceDuration,
ClockUnit sourceUnit
)
| 214 | * @throws ArithmeticException in case of long overflow |
| 215 | */ |
| 216 | public long convert( |
| 217 | long sourceDuration, |
| 218 | ClockUnit sourceUnit |
| 219 | ) { |
| 220 | |
| 221 | if (sourceDuration == 0) { |
| 222 | return 0L; |
| 223 | } |
| 224 | |
| 225 | int o1 = this.ordinal(); |
| 226 | int o2 = sourceUnit.ordinal(); |
| 227 | |
| 228 | if (o1 == o2) { |
| 229 | return sourceDuration; |
| 230 | } else if (o1 > o2) { |
| 231 | return MathUtils.safeMultiply( |
| 232 | sourceDuration, |
| 233 | FACTORS[o1] / FACTORS[o2] |
| 234 | ); |
| 235 | } else { |
| 236 | long factor = FACTORS[o2] / FACTORS[o1]; |
| 237 | return (sourceDuration / factor); // possible truncation |
| 238 | } |
| 239 | |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * <p>Converts the given duration to an amount in this unit and performs |
no test coverage detected