Search in sources :

Example 1 with NodePointer

use of org.apache.commons.jxpath.ri.model.NodePointer in project collect by openforis.

the class ModelRelationalExpression method getValue.

private Object getValue(Object object) {
    if (object instanceof Number || object instanceof NumericRange || object instanceof String) {
        return object;
    }
    if (object instanceof Boolean) {
        return ((Boolean) object).booleanValue() ? 0.0 : 1.0;
    } else if (object instanceof Value) {
        return AttributeValueUtils.extractMainFieldValue((Value) object, normalizeNumbers);
    }
    if (object instanceof NodePointer) {
        if (object instanceof VariablePointer && normalizeNumbers) {
            ModelNodePointer valuePointer = (ModelNodePointer) ((NodePointer) object).getValuePointer();
            valuePointer.setNormalizeNumbers(true);
        }
        return getValue(((NodePointer) object).getValue());
    }
    if (object instanceof EvalContext) {
        EvalContext ctx = (EvalContext) object;
        Pointer ptr = ctx.getSingleNodePointer();
        return ptr == null ? Double.NaN : getValue(ptr);
    }
    return null;
}
Also used : NumericRange(org.openforis.idm.model.NumericRange) VariablePointer(org.apache.commons.jxpath.ri.model.VariablePointer) Value(org.openforis.idm.model.Value) EvalContext(org.apache.commons.jxpath.ri.EvalContext) NodePointer(org.apache.commons.jxpath.ri.model.NodePointer) Pointer(org.apache.commons.jxpath.Pointer) VariablePointer(org.apache.commons.jxpath.ri.model.VariablePointer) NodePointer(org.apache.commons.jxpath.ri.model.NodePointer)

Example 2 with NodePointer

use of org.apache.commons.jxpath.ri.model.NodePointer in project collect by openforis.

the class ModelLocationPath method computeValue.

@Override
public Object computeValue(EvalContext context) {
    Object value = super.computeValue(context);
    if (value instanceof DynamicPropertyPointer) {
        NodePointer pointer = ((DynamicPropertyPointer) value).getValuePointer();
        Object object = pointer.getNode();
        if (object instanceof BooleanAttribute) {
            return pointer.getValue();
        }
    }
    return value;
}
Also used : BooleanAttribute(org.openforis.idm.model.BooleanAttribute) DynamicPropertyPointer(org.apache.commons.jxpath.ri.model.dynamic.DynamicPropertyPointer) NodePointer(org.apache.commons.jxpath.ri.model.NodePointer)

Example 3 with NodePointer

use of org.apache.commons.jxpath.ri.model.NodePointer in project collect by openforis.

the class ModelRelationalExpression method getDoubleValue.

private double getDoubleValue(Object object) {
    if (object instanceof Number) {
        return ((Number) object).doubleValue();
    }
    if (object instanceof Boolean) {
        return ((Boolean) object).booleanValue() ? 0.0 : 1.0;
    }
    if (object instanceof String) {
        if (StringUtils.isBlank((String) object)) {
            return 0.0;
        }
        try {
            return Double.parseDouble((String) object);
        } catch (NumberFormatException ex) {
            return Double.NaN;
        }
    }
    if (object instanceof NodePointer) {
        return getDoubleValue(((NodePointer) object).getValue());
    }
    if (object instanceof EvalContext) {
        EvalContext ctx = (EvalContext) object;
        Pointer ptr = ctx.getSingleNodePointer();
        return ptr == null ? Double.NaN : getDoubleValue(ptr);
    }
    throw new RuntimeException("Cannot convert " + object.toString() + " to a double value");
}
Also used : EvalContext(org.apache.commons.jxpath.ri.EvalContext) NodePointer(org.apache.commons.jxpath.ri.model.NodePointer) Pointer(org.apache.commons.jxpath.Pointer) VariablePointer(org.apache.commons.jxpath.ri.model.VariablePointer) NodePointer(org.apache.commons.jxpath.ri.model.NodePointer)

Aggregations

NodePointer (org.apache.commons.jxpath.ri.model.NodePointer)3 Pointer (org.apache.commons.jxpath.Pointer)2 EvalContext (org.apache.commons.jxpath.ri.EvalContext)2 VariablePointer (org.apache.commons.jxpath.ri.model.VariablePointer)2 DynamicPropertyPointer (org.apache.commons.jxpath.ri.model.dynamic.DynamicPropertyPointer)1 BooleanAttribute (org.openforis.idm.model.BooleanAttribute)1 NumericRange (org.openforis.idm.model.NumericRange)1 Value (org.openforis.idm.model.Value)1