/** * Obtains an instance specifying a multiplication factor, adding it to the base value. * <p> * The result will be {@code (baseValue + baseValue * modifyingValue)}. * * @param deltaMultiplier the multiplication factor to apply to the base amount * with the result added to the base amount * @return the adjustment, capturing the delta multiplier */ public static ValueAdjustment ofDeltaMultiplier(double deltaMultiplier) { return new ValueAdjustment(deltaMultiplier, ValueAdjustmentType.DELTA_MULTIPLIER); }
@Override public ValueStepSequence build() { return new ValueStepSequence( firstStepDate, lastStepDate, frequency, adjustment); }
/** * Obtains an instance from a value and array of derivatives. * * @param value the value * @param derivatives the derivatives of the value * @return the object */ public static ValueDerivatives of(double value, DoubleArray derivatives) { return new ValueDerivatives(value, derivatives); }
public void test_resolveValues_sequenceAndStepClash() { ValueStepSequence seq = ValueStepSequence.of( date(2014, 2, 1), date(2014, 3, 1), Frequency.P1M, ValueAdjustment.ofDeltaAmount(100)); ValueStep step1 = ValueStep.of(date(2014, 2, 1), ValueAdjustment.ofReplace(350d)); ValueSchedule test = ValueSchedule.builder().initialValue(200d).steps(step1).stepSequence(seq).build(); assertThrowsIllegalArg(() -> test.resolveValues(SCHEDULE)); }
public void test_ofFractionalDecimalPlaces() { HalfUpRounding test = HalfUpRounding.ofFractionalDecimalPlaces(4, 32); assertEquals(test.getDecimalPlaces(), 4); assertEquals(test.getFraction(), 32); assertEquals(test.toString(), "Round to 1/32 of 4dp"); assertEquals(Rounding.ofFractionalDecimalPlaces(4, 32), test); }
public void test_builder_invalid() { assertThrowsIllegalArg(() -> ValueStep.builder().value(DELTA_MINUS_2000).build()); assertThrowsIllegalArg(() -> ValueStep.builder().date(date(2014, 6, 30)).periodIndex(1).value(DELTA_MINUS_2000).build()); assertThrowsIllegalArg(() -> ValueStep.builder().periodIndex(0).value(DELTA_MINUS_2000).build()); assertThrowsIllegalArg(() -> ValueStep.builder().periodIndex(-1).value(DELTA_MINUS_2000).build()); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(ValueStep beanToCopy) { this.periodIndex = beanToCopy.periodIndex; this.date = beanToCopy.date; this.value = beanToCopy.getValue(); }
/** * Adjusts the base value based on the criteria of this adjustment. * <p> * For example, if this adjustment represents a 10% decrease, then the * result will be the base value minus 10%. * * @param baseValue the base, or previous, value to be adjusted * @return the calculated result */ public double adjust(double baseValue) { return type.adjust(baseValue, modifyingValue); }
/** * Returns a builder that allows this bean to be mutated. * @return the mutable builder, not null */ public Builder toBuilder() { return new Builder(this); }
/** * Returns a builder used to create an instance of the bean. * @return the builder, not null */ public static ValueSchedule.Builder builder() { return new ValueSchedule.Builder(); }
@Override public ValueSchedule build() { return new ValueSchedule( initialValue, steps, stepSequence); }
@Override public HalfUpRounding build() { return new HalfUpRounding( decimalPlaces, fraction); }
@Override public ValueStep build() { return new ValueStep( periodIndex, date, value); }
public void test_resolveValues_sequenceAndSteps() { ValueStepSequence seq = ValueStepSequence.of( date(2014, 2, 1), date(2014, 3, 1), Frequency.P1M, ValueAdjustment.ofDeltaAmount(100)); ValueStep step1 = ValueStep.of(date(2014, 1, 1), ValueAdjustment.ofReplace(350d)); ValueSchedule test = ValueSchedule.builder().initialValue(200d).steps(step1).stepSequence(seq).build(); assertEquals(test.resolveValues(SCHEDULE), DoubleArray.of(350d, 450d, 550d)); }
/** * Obtains an instance specifying a multiplication factor to apply to the base value. * <p> * The result will be {@code (baseValue * modifyingValue)}. * * @param multiplier the multiplication factor to apply to the base amount * @return the adjustment */ public static ValueAdjustment ofMultiplier(double multiplier) { return new ValueAdjustment(multiplier, ValueAdjustmentType.MULTIPLIER); }
/** * Returns a builder used to create an instance of the bean. * @return the builder, not null */ public static ValueStep.Builder builder() { return new ValueStep.Builder(); }
/** * Returns a builder that allows this bean to be mutated. * @return the mutable builder, not null */ public Builder toBuilder() { return new Builder(this); }
@Override public ValueAdjustment build() { return new ValueAdjustment( modifyingValue, type); }
/** * Obtains an instance that replaces the base value. * <p> * The base value is ignored when calculating the result. * * @param replacementValue the replacement value to use as the result of the adjustment * @return the adjustment, capturing the replacement value */ public static ValueAdjustment ofReplace(double replacementValue) { return new ValueAdjustment(replacementValue, ValueAdjustmentType.REPLACE); }
/** * Obtains an instance specifying an amount to add to the base value. * <p> * The result will be {@code (baseValue + deltaAmount)}. * * @param deltaAmount the amount to be added to the base value * @return the adjustment, capturing the delta amount */ public static ValueAdjustment ofDeltaAmount(double deltaAmount) { return new ValueAdjustment(deltaAmount, ValueAdjustmentType.DELTA_AMOUNT); }