Java Code Examples for org.apache.commons.jxpath.ri.model.NodePointer#isActual()

The following examples show how to use org.apache.commons.jxpath.ri.model.NodePointer#isActual() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimplePathInterpreter.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
/**
 * A path that starts with a property owner. The method evaluates
 * the first predicate in a special way and then forwards to
 * a general predicate processing method.
 * @param context evaluation context
 * @param parentPointer parent pointer
 * @param steps path steps
 * @param currentStep step number
 * @return NodePointer
 */
private static NodePointer doStepPredicatesPropertyOwner(
        EvalContext context, PropertyOwnerPointer parentPointer,
        Step[] steps, int currentStep) {
    Step step = steps[currentStep];
    Expression[] predicates = step.getPredicates();

    NodePointer childPointer =
        createChildPointerForStep(parentPointer, step);
    if (!childPointer.isActual()) {
        // Property does not exist - return a null pointer
        return createNullPointer(
            context,
            parentPointer,
            steps,
            currentStep);
    }

    // Evaluate predicates
    return doPredicate(
        context,
        childPointer,
        steps,
        currentStep,
        predicates,
        0);
}
 
Example 2
Source File: SimplePathInterpreter.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
/**
 * For a pointer that matches an actual node, returns 0.
 * For a pointer that does not match an actual node, but whose
 * parent pointer does returns -1, etc.
 * @param pointer input pointer
 * @return int match quality code
 */
private static int computeQuality(NodePointer pointer) {
    int quality = PERFECT_MATCH;
    while (pointer != null && !pointer.isActual()) {
        quality--;
        pointer = pointer.getImmediateParentPointer();
    }
    return quality;
}
 
Example 3
Source File: SimplePathInterpreter.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the pointer is a collection and the index is
 * withing the bounds of the collection.
 * @param pointer input pointer
 * @param index to check
 * @return boolean
 */
private static boolean isCollectionElement(
    NodePointer pointer,
    int index) {
    return pointer.isActual()
        && (index == 0
            || (pointer.isCollection()
                && index >= 0
                && index < pointer.getLength()));
}
 
Example 4
Source File: InfoSetUtil.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the supplied object to boolean.
 * @param object to convert
 * @return boolean
 */
public static boolean booleanValue(Object object) {
    if (object instanceof Number) {
        double value = ((Number) object).doubleValue();
        final int negZero = -0;
        return value != 0 && value != negZero && !Double.isNaN(value);
    }
    if (object instanceof Boolean) {
        return ((Boolean) object).booleanValue();
    }
    if (object instanceof EvalContext) {
        EvalContext ctx = (EvalContext) object;
        Pointer ptr = ctx.getSingleNodePointer();
        return ptr == null ? false : booleanValue(ptr);
    }
    if (object instanceof String) {
        return ((String) object).length() != 0;
    }
    if (object instanceof NodePointer) {
        NodePointer pointer = (NodePointer) object;
        if (pointer instanceof VariablePointer) {
            return booleanValue(pointer.getNode());
        }
        pointer = pointer.getValuePointer();
        return pointer.isActual();
    }
    return object != null;
}