@Override public Set<String> tokens(Bean bean) { if (bean.propertyNames().size() == 1) { String singlePropertyName = Iterables.getOnlyElement(bean.propertyNames()); Object propertyValue = bean.property(singlePropertyName).get(); Set<String> valueTokens = ValuePathEvaluator.tokens(propertyValue); return ImmutableSet.<String>builder() .add(singlePropertyName) .addAll(valueTokens) .build(); } else { return bean.propertyNames(); } }
private Set<String> fieldValues(Object object) { if (!(object instanceof Bean)) { return ImmutableSet.of(); } Bean bean = (Bean) object; return bean.propertyNames().stream() .map(bean::property) .filter(p -> SUPPORTED_FIELD_TYPES.contains(p.metaProperty().propertyType())) .map(Property::get) .filter(v -> v != null) .map(Object::toString) .map(v -> v.toLowerCase(Locale.ENGLISH)) .collect(toImmutableSet()); }
@Override public EvaluationResult evaluate( Bean bean, CalculationFunctions functions, String firstToken, List<String> remainingTokens) { Optional<String> propertyName = bean.propertyNames().stream() .filter(p -> p.equalsIgnoreCase(firstToken)) .findFirst(); if (propertyName.isPresent()) { 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(); List<String> tokens = ImmutableList.<String>builder().add(firstToken).addAll(remainingTokens).build(); return propertyValue != null ? EvaluationResult.success(propertyValue, tokens) : EvaluationResult.failure("No value available for property '{}'", firstToken); } return invalidTokenFailure(bean, firstToken); }
Object propertyValue = trade.getInfo().property(tradeInfoPropertyName.get()).get(); if (propertyValue == null) { return EvaluationResult.failure("Property '{}' not set", firstToken);
@Override public EvaluationResult evaluate( Position position, CalculationFunctions functions, String firstToken, List<String> remainingTokens) { MetaBean metaBean = MetaBean.of(position.getClass()); // position Optional<String> positionPropertyName = metaBean.metaPropertyMap().keySet().stream() .filter(p -> p.equalsIgnoreCase(firstToken)) .findFirst(); if (positionPropertyName.isPresent()) { 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.getInfo().propertyNames().stream() .filter(p -> p.equalsIgnoreCase(firstToken)) .findFirst(); if (positionInfoPropertyName.isPresent()) { Object propertyValue = position.getInfo().property(positionInfoPropertyName.get()).get(); return propertyValue != null ? EvaluationResult.success(propertyValue, remainingTokens) : EvaluationResult.failure("Property '{}' not set", firstToken); } // not found return invalidTokenFailure(position, firstToken); }
.findFirst(); if (securityInfoPropertyName.isPresent()) { Object propertyValue = security.getInfo().property(securityInfoPropertyName.get()).get(); return propertyValue != null ? EvaluationResult.success(propertyValue, remainingTokens) : .findFirst(); if (securityPriceInfoPropertyName.isPresent()) { Object propertyValue = security.getInfo().getPriceInfo().property(securityPriceInfoPropertyName.get()).get(); return propertyValue != null ? EvaluationResult.success(propertyValue, remainingTokens) :
public void test_immutableDatesViaBeanGet() { LocalDateDoubleTimeSeries test = LocalDateDoubleTimeSeries.builder().putAll(DATES_2010_12, VALUES_10_12).build(); LocalDate[] array = (LocalDate[]) ((Bean) test).property("dates").get(); array[0] = DATE_2012_01_01; LocalDateDoublePoint[] points = test.stream().toArray(LocalDateDoublePoint[]::new); assertEquals(points[0], LocalDateDoublePoint.of(DATE_2010_01_01, 10d)); assertEquals(points[1], LocalDateDoublePoint.of(DATE_2011_01_01, 11d)); assertEquals(points[2], LocalDateDoublePoint.of(DATE_2012_01_01, 12d)); }
public void test_immutableValuesViaBeanGet() { LocalDateDoubleTimeSeries test = LocalDateDoubleTimeSeries.builder().putAll(DATES_2010_12, VALUES_10_12).build(); double[] array = (double[]) ((Bean) test).property("values").get(); array[0] = -1; LocalDateDoublePoint[] points = test.stream().toArray(LocalDateDoublePoint[]::new); assertEquals(points[0], LocalDateDoublePoint.of(DATE_2010_01_01, 10d)); assertEquals(points[1], LocalDateDoublePoint.of(DATE_2011_01_01, 11d)); assertEquals(points[2], LocalDateDoublePoint.of(DATE_2012_01_01, 12d)); }
public void test_immutableValuesViaBeanGet() { LocalDateDoubleTimeSeries test = LocalDateDoubleTimeSeries.builder().putAll(DATES_2015_1_WEEK, VALUES_1_WEEK).build(); double[] array = (double[]) ((Bean) test).property("points").get(); array[0] = -1; LocalDateDoublePoint[] points = test.stream().toArray(LocalDateDoublePoint[]::new); assertEquals(points[0], LocalDateDoublePoint.of(DATE_2015_01_05, 10d)); assertEquals(points[1], LocalDateDoublePoint.of(DATE_2015_01_06, 11d)); assertEquals(points[2], LocalDateDoublePoint.of(DATE_2015_01_07, 12d)); }