/// <summary> /// Returns a new array containing the values from this array with the values from the other array subtracted. /// <para> /// The amounts are subtracted from the matching element in this array. /// The arrays must have the same size. /// /// </para> /// </summary> /// <param name="other"> another array of multiple currency values. </param> /// <returns> a new array containing the values from this array added with the values from the other array subtracted </returns> /// <exception cref="IllegalArgumentException"> if the arrays have different sizes </exception> public MultiCurrencyAmountArray minus(MultiCurrencyAmountArray other) { if (other.size() != size_Renamed) { throw new System.ArgumentException(Messages.format("Sizes must be equal, this size is {}, other size is {}", size_Renamed, other.size())); } ImmutableMap.Builder <Currency, DoubleArray> builder = ImmutableMap.builder(); foreach (Currency currency in Sets.union(values.Keys, other.values.Keys)) { DoubleArray array = values.get(currency); DoubleArray otherArray = other.values.get(currency); if (otherArray == null) { builder.put(currency, array); } else if (array == null) { builder.put(currency, otherArray.multipliedBy(-1)); } else { builder.put(currency, array.minus(otherArray)); } } return(of(builder.build())); }
public virtual void test_empty_amounts() { MultiCurrencyAmountArray array = MultiCurrencyAmountArray.of(MultiCurrencyAmount.empty(), MultiCurrencyAmount.empty()); assertThat(array.size()).isEqualTo(2); assertThat(array.get(0)).isEqualTo(MultiCurrencyAmount.empty()); assertThat(array.get(1)).isEqualTo(MultiCurrencyAmount.empty()); }
//------------------------------------------------------------------------- /// <summary> /// Returns a new array containing the values from this array added to the values in the other array. /// <para> /// The amounts are added to the matching element in this array. /// The arrays must have the same size. /// /// </para> /// </summary> /// <param name="other"> another array of multiple currency values. </param> /// <returns> a new array containing the values from this array added to the values in the other array </returns> /// <exception cref="IllegalArgumentException"> if the arrays have different sizes </exception> public MultiCurrencyAmountArray plus(MultiCurrencyAmountArray other) { if (other.size() != size_Renamed) { throw new System.ArgumentException(Messages.format("Sizes must be equal, this size is {}, other size is {}", size_Renamed, other.size())); } IDictionary <Currency, DoubleArray> addedValues = Stream.concat(values.entrySet().stream(), other.values.entrySet().stream()).collect(toMap(e => e.Key, e => e.Value, (arr1, arr2) => arr1.plus(arr2))); return(MultiCurrencyAmountArray.of(addedValues)); }
// Test that the size is correctly restored after deserialization. //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void serializeSize() throws Exception public virtual void serializeSize() { MultiCurrencyAmountArray deserialized = serializedDeserialize(VALUES_ARRAY); assertThat(deserialized.size()).isEqualTo(3); MultiCurrencyAmountArray empty = MultiCurrencyAmountArray.of(MultiCurrencyAmount.empty(), MultiCurrencyAmount.empty()); MultiCurrencyAmountArray deserializedEmpty = serializedDeserialize(empty); assertThat(deserializedEmpty.size()).isEqualTo(2); }
//------------------------------------------------------------------------- public virtual void test_of() { assertThat(VALUES_ARRAY.getValues(Currency.GBP)).isEqualTo(DoubleArray.of(20, 21, 22)); assertThat(VALUES_ARRAY.getValues(Currency.USD)).isEqualTo(DoubleArray.of(30, 32, 33)); assertThat(VALUES_ARRAY.getValues(Currency.EUR)).isEqualTo(DoubleArray.of(40, 43, 44)); MultiCurrencyAmountArray raggedArray = MultiCurrencyAmountArray.of(ImmutableList.of(MultiCurrencyAmount.of(CurrencyAmount.of(Currency.EUR, 4)), MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 21), CurrencyAmount.of(Currency.USD, 32), CurrencyAmount.of(Currency.EUR, 43)), MultiCurrencyAmount.of(CurrencyAmount.of(Currency.EUR, 44)))); assertThat(raggedArray.size()).isEqualTo(3); assertThat(VALUES_ARRAY.Currencies).containsExactlyInAnyOrder(Currency.GBP, Currency.USD, Currency.EUR); assertThat(raggedArray.getValues(Currency.GBP)).isEqualTo(DoubleArray.of(0, 21, 0)); assertThat(raggedArray.getValues(Currency.USD)).isEqualTo(DoubleArray.of(0, 32, 0)); assertThat(raggedArray.getValues(Currency.EUR)).isEqualTo(DoubleArray.of(4, 43, 44)); assertThrowsIllegalArg(() => raggedArray.getValues(Currency.AUD)); }
public virtual void test_of_map() { MultiCurrencyAmountArray array = MultiCurrencyAmountArray.of(ImmutableMap.of(Currency.GBP, DoubleArray.of(20, 21, 22), Currency.EUR, DoubleArray.of(40, 43, 44))); MultiCurrencyAmountArray expected = MultiCurrencyAmountArray.of(ImmutableList.of(MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 20), CurrencyAmount.of(Currency.EUR, 40)), MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 21), CurrencyAmount.of(Currency.EUR, 43)), MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 22), CurrencyAmount.of(Currency.EUR, 44)))); assertThat(array.size()).isEqualTo(3); assertThat(array).isEqualTo(expected); assertThrowsIllegalArg(() => MultiCurrencyAmountArray.of(ImmutableMap.of(Currency.GBP, DoubleArray.of(20, 21), Currency.EUR, DoubleArray.of(40, 43, 44))), "Arrays must have the same size.*"); MultiCurrencyAmountArray empty = MultiCurrencyAmountArray.of(ImmutableMap.of()); assertThat(empty.size()).isEqualTo(0); }
public virtual void test_of_function_empty_amounts() { MultiCurrencyAmountArray test = MultiCurrencyAmountArray.of(3, i => MultiCurrencyAmount.empty()); assertThat(test.size()).isEqualTo(3); }