public Duration<U> with(
        long amount,
        U unit
    ) {

        long absAmount =
            ((amount < 0) ? MathUtils.safeNegate(amount) : amount);
        Item<U> item = replaceFraction(absAmount, unit);

        if (item != null) {
            absAmount = item.getAmount();
            unit = item.getUnit();
        }

        long oldAmount = this.getPartialAmount(unit);

        return this.plus(
            MathUtils.safeSubtract(
                MathUtils.safeMultiply(
                    absAmount,
                    (amount < 0) ? -1 : 1
                ),
                MathUtils.safeMultiply(
                    oldAmount,
                    this.isNegative() ? -1 : 1
                )
            ),
            unit
        );

    }
public Duration < U > with ( long amount , U unit ) { long absAmount = ( ( amount < 0 ) ? MathUtils . safeNegate ( amount ) : amount ) ; Item < U > item = replaceFraction ( absAmount , unit ) ; if ( item != null ) { absAmount = item . getAmount ( ) ; unit = item . getUnit ( ) ; } long oldAmount = this . getPartialAmount ( unit ) ; return this . plus ( MathUtils . safeSubtract ( MathUtils . safeMultiply ( absAmount , ( amount < 0 ) ? - 1 : 1 ) , MathUtils . safeMultiply ( oldAmount , this . isNegative ( ) ? - 1 : 1 ) ) , unit ) ; }
/*[deutsch]
<p>Liefert eine Kopie dieser Instanz mit dem angegebenen ge&auml;nderten
Wert. </p>

<p>Entspricht {@code plus(amount - getAmount(unit), unit)}. </p>

@param   amount      temporal amount to be set (maybe negative)
@param   unit        associated time unit
@return  new changed duration while this duration remains unaffected
@throws  IllegalStateException if the result gets mixed signs by
setting the partial amounts
@throws  IllegalArgumentException if different units of same length exist
@throws  ArithmeticException in case of long overflow
@see     #plus(long, IsoUnit) plus(long, U)