(int factor)
| 1686 | * @throws ArithmeticException in case of long overflow |
| 1687 | */ |
| 1688 | public Duration<U> multipliedBy(int factor) { |
| 1689 | |
| 1690 | if ( |
| 1691 | this.isEmpty() |
| 1692 | || (factor == 1) |
| 1693 | ) { |
| 1694 | return this; |
| 1695 | } else if (factor == 0) { |
| 1696 | return ofZero(); |
| 1697 | } else if (factor == -1) { |
| 1698 | return new Duration<>(this, true); |
| 1699 | } |
| 1700 | |
| 1701 | List<Item<U>> newItems = new ArrayList<>(this.count()); |
| 1702 | int scalar = Math.abs(factor); |
| 1703 | |
| 1704 | for (int i = 0, n = this.count(); i < n; i++) { |
| 1705 | Item<U> item = this.getTotalLength().get(i); |
| 1706 | newItems.add( |
| 1707 | Item.of( |
| 1708 | MathUtils.safeMultiply(item.getAmount(), scalar), |
| 1709 | item.getUnit() |
| 1710 | ) |
| 1711 | ); |
| 1712 | } |
| 1713 | |
| 1714 | return new Duration<>( |
| 1715 | newItems, |
| 1716 | ((factor < 0) != this.isNegative()) |
| 1717 | ); |
| 1718 | |
| 1719 | } |
| 1720 | |
| 1721 | /** |
| 1722 | * <p>Creates a duration as union of this instance and given timespan |
no test coverage detected