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

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

Introduction

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

Prototype

public int getIndex() 

Source Link

Document

If the pointer represents a collection, the index identifies an element of that collection.

Usage

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

@Override
public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2) {
    return pointer1.getIndex() - pointer2.getIndex();
}

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

@Override
public String asPath() {
    StringBuffer buffer = new StringBuffer();
    NodePointer parent = getImmediateParentPointer();
    if (parent != null) {
        buffer.append(parent.asPath());// w  w w. j ava 2s .  co m
        if (index != WHOLE_COLLECTION) {
            // Address the list[1][2] case
            if (parent.getIndex() != WHOLE_COLLECTION) {
                buffer.append("/.");
            }
            buffer.append("[").append(index + 1).append(']');
        }
    } else {
        if (index != WHOLE_COLLECTION) {
            buffer.append("/.[").append(index + 1).append(']');
        } else {
            buffer.append("/");
        }
    }
    return buffer.toString();
}

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

/**
 * Create a new PropertyIterator.//from   w ww.  j  a  v a  2  s  . com
 * @param pointer owning pointer
 * @param name property name
 * @param reverse iteration order
 * @param startWith beginning pointer
 */
public EStructuralFeatureIterator(EStructuralFeatureOwnerPointer pointer, String name, boolean reverse,
        NodePointer startWith) {
    propertyNodePointer = (EStructuralFeaturePointer) pointer.getPropertyPointer().clone();
    this.name = name;
    this.reverse = reverse;
    this.includeStart = true;
    if (reverse) {
        this.startPropertyIndex = EStructuralFeaturePointer.UNSPECIFIED_PROPERTY;
        this.startIndex = -1;
    }
    if (startWith != null) {
        while (startWith != null && startWith.getImmediateParentPointer() != pointer) {
            startWith = startWith.getImmediateParentPointer();
        }
        if (startWith == null) {
            throw new JXPathException(
                    "PropertyIerator startWith parameter is " + "not a child of the supplied parent");
        }
        this.startPropertyIndex = ((EStructuralFeaturePointer) startWith).getPropertyIndex();
        this.startIndex = startWith.getIndex();
        if (this.startIndex == NodePointer.WHOLE_COLLECTION) {
            this.startIndex = 0;
        }
        this.includeStart = false;
        if (reverse && startIndex == -1) {
            this.includeStart = true;
        }
    }
}

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

@Override
public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2) {
    int r = pointer1.getName().toString().compareTo(pointer2.getName().toString());
    return r == 0 ? pointer1.getIndex() - pointer2.getIndex() : r;
}

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

@Override
public String asPath() {
    StringBuffer buffer = new StringBuffer();
    NodePointer parent = getImmediateParentPointer();
    if (parent != null) {
        buffer.append(parent.asPath());//ww w.j  a  v  a  2 s .  c o  m
    }
    if (index != WHOLE_COLLECTION) {
        // Address the list[1][2] case
        if (parent != null && parent.getIndex() != WHOLE_COLLECTION) {
            buffer.append("/.");
        } else if (parent != null && parent.getImmediateParentPointer() != null
                && parent.getImmediateParentPointer().getIndex() != WHOLE_COLLECTION) {
            buffer.append("/.");
        }
        buffer.append("[").append(index + 1).append(']');
    }

    return buffer.toString();
}