Ejemplo n.º 1
0
        /// <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));
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
 /// <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()));
 }
Ejemplo n.º 5
0
        public virtual void test_of_function_empty_amounts()
        {
            MultiCurrencyAmountArray test = MultiCurrencyAmountArray.of(3, i => MultiCurrencyAmount.empty());

            assertThat(test.size()).isEqualTo(3);
        }