public override EvaluationResult evaluate(Trade trade, CalculationFunctions functions, string firstToken, IList <string> remainingTokens) { MetaBean metaBean = MetaBean.of(trade.GetType()); // trade Optional <string> tradePropertyName = metaBean.metaPropertyMap().Keys.Where(p => p.equalsIgnoreCase(firstToken)).First(); if (tradePropertyName.Present) { object propertyValue = metaBean.metaProperty(tradePropertyName.get()).get((Bean)trade); if (propertyValue == null) { return(EvaluationResult.failure("Property '{}' not set", firstToken)); } return(EvaluationResult.success(propertyValue, remainingTokens)); } // trade info Optional <string> tradeInfoPropertyName = trade.Info.propertyNames().Where(p => p.equalsIgnoreCase(firstToken)).First(); if (tradeInfoPropertyName.Present) { object propertyValue = trade.Info.property(tradeInfoPropertyName.get()).get(); if (propertyValue == null) { return(EvaluationResult.failure("Property '{}' not set", firstToken)); } return(EvaluationResult.success(propertyValue, remainingTokens)); } return(invalidTokenFailure(trade, firstToken)); }
// produces a failure result private EvaluationResult tokenFailure(string reason, T @object, string token) { //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: IList <string> orderedValidTokens = tokens(@object).OrderBy(c => c).collect(toImmutableList()); //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: return(EvaluationResult.failure("{} field '{}' in type {}. Use one of: {}", reason, token, @object.GetType().FullName, orderedValidTokens)); }
// find the result starting from a measure private EvaluationResult evaluateMeasures(ResultsRow resultsRow, CalculationFunctions functions, IList <string> remainingTokens) { // if no measures, return list of valid measures if (remainingTokens.Count == 0 || Strings.nullToEmpty(remainingTokens[0]).Trim().Empty) { IList <string> measureNames = ResultsRow.measureNames(resultsRow.Target, functions); return(EvaluationResult.failure("No measure specified. Use one of: {}", measureNames)); } // evaluate the measure name string measureToken = remainingTokens[0]; return(EvaluationResult.of(resultsRow.getResult(measureToken), remainingTokens.subList(1, remainingTokens.Count))); }
public override EvaluationResult evaluate(Bean bean, CalculationFunctions functions, string firstToken, IList <string> remainingTokens) { Optional <string> propertyName = bean.propertyNames().Where(p => p.equalsIgnoreCase(firstToken)).First(); if (propertyName.Present) { object propertyValue = bean.property(propertyName.get()).get(); return(propertyValue != null?EvaluationResult.success(propertyValue, remainingTokens) : EvaluationResult.failure("No value available for property '{}'", firstToken)); } // The bean has a single property which doesn't match the token. // Return the property value without consuming any tokens. // This allows skipping over properties when the bean only has a single property. if (bean.propertyNames().size() == 1) { string singlePropertyName = Iterables.getOnlyElement(bean.propertyNames()); object propertyValue = bean.property(singlePropertyName).get(); IList <string> tokens = ImmutableList.builder <string>().add(firstToken).addAll(remainingTokens).build(); return(propertyValue != null?EvaluationResult.success(propertyValue, tokens) : EvaluationResult.failure("No value available for property '{}'", firstToken)); } return(invalidTokenFailure(bean, firstToken)); }
public override EvaluationResult evaluate(Security security, CalculationFunctions functions, string firstToken, IList <string> remainingTokens) { MetaBean metaBean = MetaBean.of(security.GetType()); // security Optional <string> securityPropertyName = metaBean.metaPropertyMap().Keys.Where(p => p.equalsIgnoreCase(firstToken)).First(); if (securityPropertyName.Present) { object propertyValue = metaBean.metaProperty(securityPropertyName.get()).get((Bean)security); return(propertyValue != null?EvaluationResult.success(propertyValue, remainingTokens) : EvaluationResult.failure("Property '{}' not set", firstToken)); } // security info Optional <string> securityInfoPropertyName = security.Info.propertyNames().Where(p => p.equalsIgnoreCase(firstToken)).First(); if (securityInfoPropertyName.Present) { object propertyValue = security.Info.property(securityInfoPropertyName.get()).get(); return(propertyValue != null?EvaluationResult.success(propertyValue, remainingTokens) : EvaluationResult.failure("Property '{}' not set", firstToken)); } // security price info Optional <string> securityPriceInfoPropertyName = security.Info.PriceInfo.propertyNames().Where(p => p.equalsIgnoreCase(firstToken)).First(); if (securityPriceInfoPropertyName.Present) { object propertyValue = security.Info.PriceInfo.property(securityPriceInfoPropertyName.get()).get(); return(propertyValue != null?EvaluationResult.success(propertyValue, remainingTokens) : EvaluationResult.failure("Property '{}' not set", firstToken)); } // not found return(invalidTokenFailure(security, firstToken)); }
public override EvaluationResult evaluate(Position position, CalculationFunctions functions, string firstToken, IList <string> remainingTokens) { MetaBean metaBean = MetaBean.of(position.GetType()); // position Optional <string> positionPropertyName = metaBean.metaPropertyMap().Keys.Where(p => p.equalsIgnoreCase(firstToken)).First(); if (positionPropertyName.Present) { object propertyValue = metaBean.metaProperty(positionPropertyName.get()).get((Bean)position); return(propertyValue != null?EvaluationResult.success(propertyValue, remainingTokens) : EvaluationResult.failure("Property '{}' not set", firstToken)); } // position info Optional <string> positionInfoPropertyName = position.Info.propertyNames().Where(p => p.equalsIgnoreCase(firstToken)).First(); if (positionInfoPropertyName.Present) { object propertyValue = position.Info.property(positionInfoPropertyName.get()).get(); return(propertyValue != null?EvaluationResult.success(propertyValue, remainingTokens) : EvaluationResult.failure("Property '{}' not set", firstToken)); } // not found return(invalidTokenFailure(position, firstToken)); }