Example #1
0
        public virtual void compose()
        {
            Fn1 fn1a = new Fn1();
            Fn1 fn1b = new Fn1();
            Fn2 fn2  = new Fn2();

            CalculationFunctions fns1     = CalculationFunctions.of(fn1a);
            CalculationFunctions fns2     = CalculationFunctions.of(fn1b, fn2);
            CalculationFunctions composed = fns1.composedWith(fns2);

            assertEquals(composed.getFunction(new Target1()), fn1a);
            assertEquals(composed.getFunction(new Target2()), fn2);
        }
        public virtual void oneDerivedFunction()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> delegateResults = com.google.common.collect.ImmutableMap.of(CASH_FLOWS, com.opengamma.strata.collect.result.Result.success(3), PAR_RATE, com.opengamma.strata.collect.result.Result.success(5));
            IDictionary <Measure, Result <object> > delegateResults = ImmutableMap.of(CASH_FLOWS, Result.success(3), PAR_RATE, Result.success(5));
            DelegateFn           delegateFn           = new DelegateFn(delegateResults);
            DerivedFn            derivedFn            = new DerivedFn();
            CalculationFunctions calculationFunctions = CalculationFunctions.of(delegateFn);
            CalculationFunctions derivedFunctions     = calculationFunctions.composedWith(derivedFn);
            TestTarget           target = new TestTarget(42);
//JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the Java 'super' constraint:
//ORIGINAL LINE: CalculationFunction<? super TestTarget> function = derivedFunctions.getFunction(target);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
            CalculationFunction <object> function = derivedFunctions.getFunction(target);

            ImmutableSet <Measure> expectedMeasures = ImmutableSet.of(BUCKETED_PV01, CASH_FLOWS, PAR_RATE);

            assertThat(function.supportedMeasures()).isEqualTo(expectedMeasures);
        }
        /// <summary>
        /// Test that multiple derived functions for the same target type are correctly combined when one derived function
        /// depends on another.
        /// </summary>
        public virtual void multipleDerivedFunctionsForSameTargetTypeWithDependencyBetweenDerivedFunctions()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> delegateResults = com.google.common.collect.ImmutableMap.of(CASH_FLOWS, com.opengamma.strata.collect.result.Result.success(3), PAR_RATE, com.opengamma.strata.collect.result.Result.success(5));
            IDictionary <Measure, Result <object> > delegateResults = ImmutableMap.of(CASH_FLOWS, Result.success(3), PAR_RATE, Result.success(5));
            DelegateFn delegateFn = new DelegateFn(delegateResults);
            DerivedFn  derivedFn1 = new DerivedFn();
            // This depends on the measure calculated by derivedFn1
            DerivedFn derivedFn2 = new DerivedFn(PRESENT_VALUE_MULTI_CCY, ImmutableSet.of(BUCKETED_PV01));

            CalculationFunctions calculationFunctions = CalculationFunctions.of(delegateFn);
            // The derived functions must be specified in the correct order.
            // The function higher up the dependency chain must come second
            CalculationFunctions derivedFunctions = calculationFunctions.composedWith(derivedFn1, derivedFn2);
            TestTarget           target           = new TestTarget(42);
//JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the Java 'super' constraint:
//ORIGINAL LINE: CalculationFunction<? super TestTarget> function = derivedFunctions.getFunction(target);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
            CalculationFunction <object> function = derivedFunctions.getFunction(target);

            ImmutableSet <Measure> expectedMeasures = ImmutableSet.of(BUCKETED_PV01, CASH_FLOWS, PAR_RATE, PRESENT_VALUE_MULTI_CCY);

            assertThat(function.supportedMeasures()).isEqualTo(expectedMeasures);
        }