MCPcopy Create free account
hub / github.com/MenoData/Time4J / multipliedBy

Method multipliedBy

base/src/main/java/net/time4j/Duration.java:1688–1719  ·  view source on GitHub ↗
(int factor)

Source from the content-addressed store, hash-verified

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

Callers 1

inverseMethod · 0.95

Calls 12

isEmptyMethod · 0.95
ofZeroMethod · 0.95
countMethod · 0.95
getTotalLengthMethod · 0.95
ofMethod · 0.95
safeMultiplyMethod · 0.95
isNegativeMethod · 0.95
getMethod · 0.65
absMethod · 0.45
addMethod · 0.45
getAmountMethod · 0.45
getUnitMethod · 0.45

Tested by

no test coverage detected