//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: @Override public java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> calculate(T target, java.util.Set<com.opengamma.strata.calc.Measure> measures, CalculationParameters parameters, com.opengamma.strata.data.scenario.ScenarioMarketData marketData, com.opengamma.strata.basics.ReferenceData refData)
        public virtual IDictionary <Measure, Result <object> > calculate(T target, ISet <Measure> measures, CalculationParameters parameters, ScenarioMarketData marketData, ReferenceData refData)
        {
            // The caller didn't ask for the derived measure so just return the measures calculated by the delegate
            Measure derivedMeasure = derivedFunction.measure();

            if (!measures.Contains(derivedMeasure))
            {
                return(@delegate.calculate(target, measures, parameters, marketData, refData));
            }
            // Add the measures required to calculate the derived measure to the measures requested by the caller
            ISet <Measure> allRequiredMeasures = Sets.union(measures, derivedFunction.requiredMeasures());
            ISet <Measure> requiredMeasures    = Sets.difference(allRequiredMeasures, ImmutableSet.of(derivedMeasure));
//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 = delegate.calculate(target, requiredMeasures, parameters, marketData, refData);
            IDictionary <Measure, Result <object> > delegateResults = @delegate.calculate(target, requiredMeasures, parameters, marketData, refData);

            // Calculate the derived measure
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result = calculateMeasure(target, delegateResults, parameters, marketData, refData);
            Result <object> result = calculateMeasure(target, delegateResults, parameters, marketData, refData);

            // The results containing only the requested measures and not including extra measures that were inserted above
            // Also filter out any results for calculationFunction.measure(). There will be failures from functions below
            // that don't support that measure.
//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<?>> requestedResults = com.opengamma.strata.collect.MapStream.of(delegateResults).filterKeys(measures::contains).filterKeys(measure -> !measure.equals(derivedMeasure)).toMap();
            IDictionary <Measure, Result <object> > requestedResults = MapStream.of(delegateResults).filterKeys(measures.contains).filterKeys(measure => !measure.Equals(derivedMeasure)).toMap();

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: return com.google.common.collect.ImmutableMap.builder<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>>().put(derivedMeasure, result).putAll(requestedResults).build();
            return(ImmutableMap.builder <Measure, Result <object> >().put(derivedMeasure, result).putAll(requestedResults).build());
        }
        // 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));
            }
        }