public double expandFieldValue(int index, BigInteger bits) {
FieldDefinition fd = getField(index);
BigInteger raw = extractFieldValue(fd.getName(), bits);
String expression = fd.getOperands();
JEP expressionParser = new JEP();
if ( PropertiesUtil.isEmpty(expression) ) {
return raw.doubleValue();
}
if (expression.indexOf('[') != -1 ) {
// this is a look up expresion
double []vals = parseLookupTable(expression);
return vals[raw.intValue()];
}
List ids = parseIdentifiers(expression);
if ( ids.size() != 0 ) {
expression = removeIdentifiers(expression);
Iterator tor = ids.iterator();
while (tor.hasNext()) {
String idName = (String) tor.next();
FieldDefinition fieldDefinition = (FieldDefinition) getField(idName);
if ( fieldDefinition == null ) {
throw new IllegalArgumentException("unknown field: " + idName);
}
if ( fieldDefinition.getOffset() < fd.getOffset() ) {
throw new IllegalStateException("cannot access downstream field: " + idName);
}
expressionParser.addVariable(idName, expandFieldValue(fieldDefinition.getIndex(), bits));
}
}
expressionParser.addVariable("x", raw.floatValue());
expressionParser.addVariable("fieldWidth", fd.getWidth());
expressionParser.addVariable("maxValue", EncodingUtil.getMaxValue(fd.getWidth()).floatValue());
expressionParser.parseExpression(expression);
return expressionParser.getValue();
}