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

Method with

base/src/main/java/net/time4j/Duration.java:1537–1567  ·  view source on GitHub ↗
(
        long amount,
        U unit
    )

Source from the content-addressed store, hash-verified

1535 * @see #plus(long, IsoUnit) plus(long, U)
1536 */
1537 public Duration<U> with(
1538 long amount,
1539 U unit
1540 ) {
1541
1542 long absAmount =
1543 ((amount < 0) ? MathUtils.safeNegate(amount) : amount);
1544 Item<U> item = replaceFraction(absAmount, unit);
1545
1546 if (item != null) {
1547 absAmount = item.getAmount();
1548 unit = item.getUnit();
1549 }
1550
1551 long oldAmount = this.getPartialAmount(unit);
1552
1553 return this.plus(
1554 MathUtils.safeSubtract(
1555 MathUtils.safeMultiply(
1556 absAmount,
1557 (amount < 0) ? -1 : 1
1558 ),
1559 MathUtils.safeMultiply(
1560 oldAmount,
1561 this.isNegative() ? -1 : 1
1562 )
1563 ),
1564 unit
1565 );
1566
1567 }
1568
1569 /**
1570 * <p>Gets the absolute always non-negative copy of this duration. </p>

Callers

nothing calls this directly

Calls 11

safeNegateMethod · 0.95
replaceFractionMethod · 0.95
getPartialAmountMethod · 0.95
plusMethod · 0.95
safeSubtractMethod · 0.95
safeMultiplyMethod · 0.95
isNegativeMethod · 0.95
convertMethod · 0.95
normalizeMethod · 0.65
getAmountMethod · 0.45
getUnitMethod · 0.45

Tested by

no test coverage detected