public virtual void test_minusDifferentSize() { MultiCurrencyAmountArray array1 = MultiCurrencyAmountArray.of(ImmutableMap.of(Currency.USD, DoubleArray.of(30, 32), Currency.EUR, DoubleArray.of(40, 43), Currency.CHF, DoubleArray.of(50, 54))); MultiCurrencyAmountArray array2 = MultiCurrencyAmountArray.of(ImmutableMap.of(Currency.GBP, DoubleArray.of(20, 21, 22), Currency.EUR, DoubleArray.of(140, 143, 144), Currency.CHF, DoubleArray.of(250, 254, 256))); assertThrowsIllegalArg(() => array1.minus(array2)); }
/// <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 coverage() { coverImmutableBean(VALUES_ARRAY); MultiCurrencyAmountArray test2 = MultiCurrencyAmountArray.of(MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 21), CurrencyAmount.of(Currency.USD, 31), CurrencyAmount.of(Currency.EUR, 41)), MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 22), CurrencyAmount.of(Currency.USD, 33), CurrencyAmount.of(Currency.EUR, 44))); coverBeanEquals(VALUES_ARRAY, test2); }
//------------------------------------------------------------------------- // Test hand-written equals and hashCode methods which correctly handle maps with array values public virtual void test_equalsHashCode() { MultiCurrencyAmountArray array = MultiCurrencyAmountArray.of(ImmutableList.of(MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 20), CurrencyAmount.of(Currency.USD, 30), CurrencyAmount.of(Currency.EUR, 40)), MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 21), CurrencyAmount.of(Currency.USD, 32), CurrencyAmount.of(Currency.EUR, 43)), MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 22), CurrencyAmount.of(Currency.USD, 33), CurrencyAmount.of(Currency.EUR, 44)))); assertThat(array).isEqualTo(VALUES_ARRAY); assertThat(array.GetHashCode()).isEqualTo(VALUES_ARRAY.GetHashCode()); }
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()); }
public virtual void test_minusAmount() { MultiCurrencyAmountArray array = MultiCurrencyAmountArray.of(ImmutableMap.of(Currency.USD, DoubleArray.of(30, 32, 33), Currency.EUR, DoubleArray.of(40, 43, 44), Currency.CHF, DoubleArray.of(50, 54, 56))); MultiCurrencyAmount amount = MultiCurrencyAmount.of(ImmutableMap.of(Currency.GBP, 21d, Currency.EUR, 143d, Currency.CHF, 254d)); MultiCurrencyAmountArray expected = MultiCurrencyAmountArray.of(ImmutableMap.of(Currency.GBP, DoubleArray.of(-21, -21, -21), Currency.USD, DoubleArray.of(30, 32, 33), Currency.EUR, DoubleArray.of(-103, -100, -99), Currency.CHF, DoubleArray.of(-204, -200, -198))); assertThat(array.minus(amount)).isEqualTo(expected); }
public virtual void test_minusArray() { MultiCurrencyAmountArray array1 = MultiCurrencyAmountArray.of(ImmutableMap.of(Currency.USD, DoubleArray.of(30, 32, 33), Currency.EUR, DoubleArray.of(40, 43, 44), Currency.CHF, DoubleArray.of(50, 54, 56))); MultiCurrencyAmountArray array2 = MultiCurrencyAmountArray.of(ImmutableMap.of(Currency.GBP, DoubleArray.of(20, 21, 22), Currency.EUR, DoubleArray.of(140, 143, 144), Currency.CHF, DoubleArray.of(250, 254, 256))); MultiCurrencyAmountArray expected = MultiCurrencyAmountArray.of(ImmutableMap.of(Currency.GBP, DoubleArray.of(-20, -21, -22), Currency.USD, DoubleArray.of(30, 32, 33), Currency.EUR, DoubleArray.of(-100, -100, -100), Currency.CHF, DoubleArray.of(-200, -200, -200))); assertThat(array1.minus(array2)).isEqualTo(expected); }
public virtual void test_plusAmount() { MultiCurrencyAmountArray array = MultiCurrencyAmountArray.of(ImmutableMap.of(Currency.USD, DoubleArray.of(30, 32, 33), Currency.EUR, DoubleArray.of(40, 43, 44), Currency.CHF, DoubleArray.of(50, 54, 56))); MultiCurrencyAmount amount = MultiCurrencyAmount.of(ImmutableMap.of(Currency.GBP, 21d, Currency.EUR, 143d, Currency.CHF, 254d)); MultiCurrencyAmountArray expected = MultiCurrencyAmountArray.of(ImmutableMap.of(Currency.GBP, DoubleArray.of(21, 21, 21), Currency.USD, DoubleArray.of(30, 32, 33), Currency.EUR, DoubleArray.of(183, 186, 187), Currency.CHF, DoubleArray.of(304, 308, 310))); assertThat(array.plus(amount)).isEqualTo(expected); }
//------------------------------------------------------------------------- /// <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)); }
public virtual void total() { IList <CurrencyAmountArray> arrays = ImmutableList.of(CurrencyAmountArray.of(USD, DoubleArray.of(10, 20, 30)), CurrencyAmountArray.of(USD, DoubleArray.of(5, 6, 7)), CurrencyAmountArray.of(EUR, DoubleArray.of(2, 4, 6)), CurrencyAmountArray.of(GBP, DoubleArray.of(11, 12, 13)), CurrencyAmountArray.of(GBP, DoubleArray.of(1, 2, 3))); IDictionary <Currency, DoubleArray> expectedMap = ImmutableMap.of(USD, DoubleArray.of(15, 26, 37), EUR, DoubleArray.of(2, 4, 6), GBP, DoubleArray.of(12, 14, 16)); MultiCurrencyAmountArray expected = MultiCurrencyAmountArray.of(expectedMap); assertThat(MultiCurrencyAmountArray.total(arrays)).isEqualTo(expected); }
public virtual void collector() { IList <CurrencyAmountArray> arrays = ImmutableList.of(CurrencyAmountArray.of(USD, DoubleArray.of(10, 20, 30)), CurrencyAmountArray.of(USD, DoubleArray.of(5, 6, 7)), CurrencyAmountArray.of(EUR, DoubleArray.of(2, 4, 6)), CurrencyAmountArray.of(GBP, DoubleArray.of(11, 12, 13)), CurrencyAmountArray.of(GBP, DoubleArray.of(1, 2, 3))); IDictionary <Currency, DoubleArray> expectedMap = ImmutableMap.of(USD, DoubleArray.of(15, 26, 37), EUR, DoubleArray.of(2, 4, 6), GBP, DoubleArray.of(12, 14, 16)); MultiCurrencyAmountArray expected = MultiCurrencyAmountArray.of(expectedMap); //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: assertThat(arrays.collect(toMultiCurrencyAmountArray())).isEqualTo(expected); }
// 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); }
//-------------------------------------------------------------------------------------------------- /// <summary> /// Serializes and deserializes an array using default serialization. /// </summary> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static MultiCurrencyAmountArray serializedDeserialize(MultiCurrencyAmountArray array) throws Exception private static MultiCurrencyAmountArray serializedDeserialize(MultiCurrencyAmountArray array) { MemoryStream byteOutputStream = new MemoryStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteOutputStream); objectOutputStream.writeObject(array); objectOutputStream.flush(); MemoryStream byteInputStream = new MemoryStream(byteOutputStream.toByteArray()); ObjectInputStream objectInputStream = new ObjectInputStream(byteInputStream); return((MultiCurrencyAmountArray)objectInputStream.readObject()); }
public virtual void test_of_function() { MultiCurrencyAmount mca1 = MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 10), CurrencyAmount.of(Currency.USD, 20)); MultiCurrencyAmount mca2 = MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 10), CurrencyAmount.of(Currency.EUR, 30)); MultiCurrencyAmount mca3 = MultiCurrencyAmount.of(CurrencyAmount.of(Currency.USD, 40)); IList <MultiCurrencyAmount> amounts = ImmutableList.of(mca1, mca2, mca3); MultiCurrencyAmountArray test = MultiCurrencyAmountArray.of(3, i => amounts[i]); assertThat(test.get(0)).isEqualTo(mca1.plus(Currency.EUR, 0)); assertThat(test.get(1)).isEqualTo(mca2.plus(Currency.USD, 0)); assertThat(test.get(2)).isEqualTo(mca3.plus(Currency.GBP, 0).plus(Currency.EUR, 0)); }
//----------------------------------------------------------------------- public override bool Equals(object obj) { if (obj == this) { return(true); } if (obj != null && obj.GetType() == this.GetType()) { MultiCurrencyAmountArray other = (MultiCurrencyAmountArray)obj; return((size_Renamed == other.size_Renamed) && JodaBeanUtils.equal(values, other.values)); } return(false); }
/// <summary> /// Returns a collector which creates a multi currency amount array by combining a stream of /// currency amount arrays. /// <para> /// The arrays in the stream must all have the same length. /// /// </para> /// </summary> /// <returns> the collector </returns> //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: public static java.util.stream.Collector<CurrencyAmountArray, ?, MultiCurrencyAmountArray> toMultiCurrencyAmountArray() public static Collector <CurrencyAmountArray, ?, MultiCurrencyAmountArray> toMultiCurrencyAmountArray() { //JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter: //JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter: return(Collector.of <CurrencyAmountArray, IDictionary <Currency, CurrencyAmountArray>, MultiCurrencyAmountArray>(Hashtable::new, (map, ca) => map.merge(ca.Currency, ca, CurrencyAmountArray::plus), (map1, map2) => { map2.values().forEach((ca2) => map1.merge(ca2.Currency, ca2, CurrencyAmountArray::plus)); return map1; }, map => { IDictionary <Currency, DoubleArray> currencyArrayMap = MapStream.of(map).mapValues(caa => caa.Values).toMap(); return MultiCurrencyAmountArray.of(currencyArrayMap); }, UNORDERED)); }
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() { 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)); }
/// <summary> /// Returns a new array containing the values from this array with the values from the amount subtracted. /// <para> /// The amount is subtracted from each element in this array. /// /// </para> /// </summary> /// <param name="amount"> the amount to subtract </param> /// <returns> a new array containing the values from this array with the values from the amount subtracted </returns> public MultiCurrencyAmountArray minus(MultiCurrencyAmount amount) { ImmutableMap.Builder <Currency, DoubleArray> builder = ImmutableMap.builder(); foreach (Currency currency in Sets.union(values.Keys, amount.Currencies)) { DoubleArray array = values.get(currency); if (array == null) { builder.put(currency, DoubleArray.filled(size_Renamed, -amount.getAmount(currency).Amount)); } else if (!amount.contains(currency)) { builder.put(currency, array); } else { builder.put(currency, array.minus(amount.getAmount(currency).Amount)); } } return(MultiCurrencyAmountArray.of(builder.build())); }
public virtual void test_of_function_empty_amounts() { MultiCurrencyAmountArray test = MultiCurrencyAmountArray.of(3, i => MultiCurrencyAmount.empty()); assertThat(test.size()).isEqualTo(3); }