/** * Expression that returns (only) the latest value computed * from a {@code SourceRateExpression}. * * @param <T> type being read * @param expression expression read at the source rate * @return a new expression */ public static <T> DesiredRateExpression<T> latestValueOf(SourceRateExpression<T> expression) { return new DesiredRateExpressionImpl<T>(expression, new LatestValueCollector<T>(), expression.getName()); }
/** * An expression that formats the given expression to a string using the * given format. * * @param expression the expression to format * @param valueFormat the format to use for the conversion * @return an expression with the string representation of the argument */ public static DesiredRateReadWriteExpression<VString, String> vStringOf(DesiredRateReadWriteExpression<? extends VType, ? extends Object> expression, ValueFormat valueFormat) { LatestValueCollector<VType> forward = new LatestValueCollector<>(); DesiredRateExpression<VString> readExp = new DesiredRateExpressionImpl<>(expression, new VStringOfFunction(expression.getFunction(), valueFormat, forward) , expression.getName()); @SuppressWarnings("unchecked") WriteFunction<Object> writeFunction = (WriteFunction<Object>) (WriteFunction) expression.getWriteFunction(); WriteExpression<String> writeExp = new WriteExpressionImpl<>(expression, new VStringOfWriteFunction(forward, valueFormat, writeFunction), expression.getName()); return new DesiredRateReadWriteExpressionImpl<>(readExp, writeExp); }