// calculates the result
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: private java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> calculate(com.opengamma.strata.data.scenario.ScenarioMarketData marketData, com.opengamma.strata.basics.ReferenceData refData)
        private IDictionary <Measure, Result <object> > calculate(ScenarioMarketData marketData, ReferenceData refData)
        {
            try
            {
                ISet <Measure> requestedMeasures = Measures;
                ISet <Measure> supportedMeasures = function.supportedMeasures();
                ISet <Measure> measures          = Sets.intersection(requestedMeasures, supportedMeasures);
//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<?>> map = com.google.common.collect.ImmutableMap.of();
                IDictionary <Measure, Result <object> > map = ImmutableMap.of();
                if (measures.Count > 0)
                {
                    map = function.calculate(target, measures, parameters, marketData, refData);
                }
                // check if result does not contain all requested measures
//JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the java.util.Collection 'containsAll' method:
                if (!map.Keys.containsAll(requestedMeasures))
                {
                    return(handleMissing(requestedMeasures, supportedMeasures, map));
                }
                return(map);
            }
            catch (Exception ex)
            {
                return(handleFailure(ex));
            }
        }
        /// <summary>
        /// Creates a new function which invokes the delegate function, passes the result to the derived function
        /// and returns the combined results.
        /// </summary>
        /// <param name="derivedFunction">  a function which calculates one measure using the measure values calculated by the other function </param>
        /// <param name="delegate">  a function which calculates multiple measures </param>
        internal DerivedCalculationFunctionWrapper(DerivedCalculationFunction <T, R> derivedFunction, CalculationFunction <T> @delegate)
        {
            this.derivedFunction = derivedFunction;
            this.@delegate       = @delegate;

            ISet <Measure> delegateMeasures = @delegate.supportedMeasures();

//JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the java.util.Collection 'containsAll' method:
            this.requiredMeasuresSupported = delegateMeasures.containsAll(derivedFunction.requiredMeasures());
            this.supportedMeasures_Renamed = requiredMeasuresSupported ? ImmutableSet.builder <Measure>().addAll(delegateMeasures).add(derivedFunction.measure()).build() : delegateMeasures;
        }
        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);
        }
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: private com.opengamma.strata.collect.result.Result<?> calculateMeasure(T target, java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> delegateResults, CalculationParameters parameters, com.opengamma.strata.data.scenario.ScenarioMarketData marketData, com.opengamma.strata.basics.ReferenceData refData)
        private Result <object> calculateMeasure <T1>(T target, IDictionary <T1> delegateResults, CalculationParameters parameters, ScenarioMarketData marketData, ReferenceData refData)
        {
            if (!requiredMeasuresSupported)
            {
                // Can't calculate the measure if the delegate can't calculate its inputs
                return(Result.failure(FailureReason.NOT_APPLICABLE, "The delegate function cannot calculate the required measures. Required measures: {}, " + "supported measures: {}, delegate {}", derivedFunction.requiredMeasures(), @delegate.supportedMeasures(), @delegate));
            }
//JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the java.util.Collection 'containsAll' method:
            if (!delegateResults.Keys.containsAll(derivedFunction.requiredMeasures()))
            {
                // There's a bug in the delegate function - it claims to support the required measures but didn't return
                // a result for all of them.
                return(Result.failure(FailureReason.CALCULATION_FAILED, "Delegate did not return the expected measures. Required {}, actual {}, delegate {}", derivedFunction.requiredMeasures(), delegateResults.Keys, @delegate));
            }
            // Check whether all the required measures were successfully calculated
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.List<com.opengamma.strata.collect.result.Result<?>> failures = com.opengamma.strata.collect.MapStream.of(delegateResults).filterKeys(derivedFunction.requiredMeasures()::contains).map(entry -> entry.getValue()).filter(result -> result.isFailure()).collect(toList());
            IList <Result <object> > failures = MapStream.of(delegateResults).filterKeys(derivedFunction.requiredMeasures().contains).map(entry => entry.Value).filter(result => result.Failure).collect(toList());

            if (failures.Count > 0)
            {
                return(Result.failure(failures));
            }
            // Unwrap the results before passing them to the function
            IDictionary <Measure, object> resultValues = MapStream.of(delegateResults).filterKeys(derivedFunction.requiredMeasures().contains).mapValues(result => (object)result.Value).toMap();

            return(Result.of(() => derivedFunction.calculate(target, resultValues, parameters, marketData, refData)));
        }