Example usage for org.apache.commons.jxpath.ri.model NodePointer getLength

List of usage examples for org.apache.commons.jxpath.ri.model NodePointer getLength

Introduction

In this page you can find the example usage for org.apache.commons.jxpath.ri.model NodePointer getLength.

Prototype

public abstract int getLength();

Source Link

Document

If the pointer represents a collection (or collection element), returns the length of the collection.

Usage

From source file:org.eclipse.e4.emf.internal.xpath.CollectionNodeIterator.java

/**
 * Prepare...//from www.  j  a  v a 2s .  c  om
 */
private void prepare() {
    collection = new ArrayList<>();
    NodePointer ptr = (NodePointer) pointer.clone();
    int length = ptr.getLength();
    for (int i = 0; i < length; i++) {
        ptr.setIndex(i);
        NodePointer elementPointer = ptr.getValuePointer();
        NodeIterator iter = getElementNodeIterator(elementPointer);

        for (int j = 1; iter.setPosition(j); j++) {
            NodePointer childPointer = iter.getNodePointer();
            if (reverse) {
                collection.add(0, childPointer);
            } else {
                collection.add(childPointer);
            }
        }
    }
    if (startWith != null) {
        int index = collection.indexOf(startWith);
        if (index == -1) {
            throw new JXPathException("Invalid starting pointer for iterator: " + startWith);
        }
        while (collection.size() > index) {
            if (!reverse) {
                collection.remove(collection.size() - 1);
            } else {
                collection.remove(0);
            }
        }
    }
}