/** * get previous sibling. * * @param current * @return previous sibling */ public static Node getPrecedingSibling(Node current) { Node node = null; if (current != null) { ParentNode parent = current.getParent(); if (parent != null) { int index = parent.indexOf(current); if (index > 0) { node = parent.getChild(index - 1); } } } return node; }
private ChildAxisIterator(XOMNodeWrapper start, boolean downwards, boolean forwards, NodeTest test) { this.forwards = forwards; if (test == AnyNodeTest.getInstance()) { test = null; } nodeTest = test; commonParent = downwards ? start : start.getParent(); par = (ParentNode) commonParent.node; if (downwards) { ix = (forwards ? 0 : par.getChildCount()); } else { // find the start node among the list of siblings ix = par.indexOf(start.node); if (forwards) ix++; } cursor = ix; if (!downwards && !forwards) ix--; }
private ChildAxisIterator(XOMNodeWrapper start, boolean downwards, boolean forwards, NodeTest test) { this.forwards = forwards; if (test == AnyNodeTest.getInstance()) { test = null; } nodeTest = test; commonParent = downwards ? start : start.getParent(); par = (ParentNode) commonParent.node; if (downwards) { ix = (forwards ? 0 : par.getChildCount()); } else { // find the start node among the list of siblings ix = par.indexOf(start.node); if (forwards) ix++; } cursor = ix; if (!downwards && !forwards) ix--; }
/** * Get the index position of this node among its siblings (starting from 0) */ public int getSiblingPosition() { // This method is used only to support generate-id() if (index != -1) return index; switch (nodeKind) { case Type.ATTRIBUTE: { Attribute att = (Attribute) node; Element p = (Element) att.getParent(); if (p == null) return 0; for (int i = p.getAttributeCount(); --i >= 0; ) { if (p.getAttribute(i) == att) { index = i; return i; } } throw new IllegalStateException("XOM node not linked to parent node"); } default: { ParentNode p = node.getParent(); int i = (p == null ? 0 : p.indexOf(node)); if (i == -1) throw new IllegalStateException("XOM node not linked to parent node"); index = i; return index; } } }
/** * Get the index position of this node among its siblings (starting from 0) */ public int getSiblingPosition() { // This method is used only to support generate-id() if (index != -1) return index; switch (nodeKind) { case Type.ATTRIBUTE: { Attribute att = (Attribute) node; Element p = (Element) att.getParent(); if (p == null) return 0; for (int i = p.getAttributeCount(); --i >= 0; ) { if (p.getAttribute(i) == att) { index = i; return i; } } throw new IllegalStateException("XOM node not linked to parent node"); } default: { ParentNode p = node.getParent(); int i = (p == null ? 0 : p.indexOf(node)); if (i == -1) throw new IllegalStateException("XOM node not linked to parent node"); index = i; return index; } } }
/** * Get the index position of this node among its siblings (starting from 0) */ public int getSiblingPosition() { // This method is used only to support generate-id() if (index != -1) return index; switch (nodeKind) { case Type.ATTRIBUTE: { Attribute att = (Attribute) node; Element p = (Element) att.getParent(); if (p == null) return 0; for (int i = p.getAttributeCount(); --i >= 0; ) { if (p.getAttribute(i) == att) { index = i; return i; } } throw new IllegalStateException("XOM node not linked to parent node"); } default: { ParentNode p = node.getParent(); int i = (p == null ? 0 : p.indexOf(node)); if (i == -1) throw new IllegalStateException("XOM node not linked to parent node"); index = i; return index; } } }
private ChildAxisIterator(XOMNodeWrapper start, boolean downwards, boolean forwards, NodeTest test) { this.start = start; this.downwards = downwards; this.forwards = forwards; if (test == AnyNodeTest.getInstance()) test = null; nodeTest = test; position = 0; commonParent = downwards ? start : (XOMNodeWrapper) start.getParent(); par = (ParentNode) commonParent.node; if (downwards) { ix = (forwards ? 0 : par.getChildCount()); } else { // find the start node among the list of siblings // ix = start.getSiblingPosition(); ix = par.indexOf(start.node); if (forwards) ix++; } cursor = ix; if (!downwards && !forwards) ix--; }
/** * get next sibling. * * @author Eliotte Rusty Harold * @param current * may be null * @return following sibling or null */ public static Node getFollowingSibling(Node current) { Node node = null; if (current != null) { ParentNode parent = current.getParent(); if (parent != null) { int index = parent.indexOf(current); if (index + 1 < parent.getChildCount()) { node = parent.getChild(index + 1); } } } return node; }
/** * gets the element that is previous or parent to the join, depending * on moleculeRefs2 * * @return */ public Element getParentOrPrevious() { if (getMoleculeRefs2Attribute().getValue().equals(PARENT_S + " " + CHILD_S)) { return (Element) getParent(); } else if (getMoleculeRefs2Attribute().getValue().equals(PREVIOUS_S + " " + NEXT_S)) { ParentNode parent = getParent(); int position = parent.indexOf(this); if (position == 0) return null; return (Element) parent.getChild(position - 1); } return null; }
public SteppingNode getPreviousSibling() { ParentNode parenti = node.getParent(); if (parenti == null) { return null; } if (index != -1) { if ((index - 1) > 0) { return makeWrapper(parenti.getChild(index - 1), docWrapper, parent, index - 1); } else { return null; } } index = parenti.indexOf(node); if (index - 1 > 0) { return makeWrapper(parenti.getChild(index - 1), docWrapper, parent, index - 1); } return null; }
public XOMNodeWrapper getPreviousSibling() { ParentNode parenti = node.getParent(); if (parenti == null) { return null; } if (index != -1) { if ((index - 1) > 0) { return makeWrapper(parenti.getChild(index - 1), docWrapper, parent, index - 1); } else { return null; } } index = parenti.indexOf(node); if (index - 1 > 0) { return makeWrapper(parenti.getChild(index - 1), docWrapper, parent, index - 1); } return null; }
public XOMNodeWrapper getPreviousSibling() { ParentNode parenti = node.getParent(); if (parenti == null) { return null; } if (index != -1) { if ((index - 1) > 0) { return makeWrapper(parenti.getChild(index - 1), docWrapper, parent, index - 1); } else { return null; } } index = parenti.indexOf(node); if (index - 1 > 0) { return makeWrapper(parenti.getChild(index - 1), docWrapper, parent, index - 1); } return null; }
/** * gets the element that is next or child to the join, depending * on moleculeRefs2 * * @return */ public CMLElement getChildOrNext() { if (getMoleculeRefs2Attribute().getValue().equals(PARENT_S + " " + CHILD_S)) { if (getChildCount() > 0) return (CMLElement) getChild(0); } else if (getMoleculeRefs2Attribute().getValue().equals(PREVIOUS_S + " " + NEXT_S)) { ParentNode parent = getParent(); int position = getParent().indexOf(this); if (position == parent.getChildCount() - 1) return null; return (CMLElement) parent.getChild(position + 1); } return null; }
public SteppingNode getNextSibling() { ParentNode parenti = node.getParent(); if (parenti == null) { return null; } int count = parenti.getChildCount(); if (index != -1) { if ((index + 1) < count) { return makeWrapper(parenti.getChild(index + 1), docWrapper, parent, index + 1); } else { return null; } } index = parenti.indexOf(node); if (index + 1 < count) { return makeWrapper(parenti.getChild(index + 1), docWrapper, parent, index + 1); } return null; }
/** * Get the following node in an iteration of descendants * * @param start the start node * @param anchor the node marking the root of the subtree within which navigation takes place (may be null) * @return the next node in document order after the start node, excluding attributes and namespaces */ private static Node getSuccessorNode(Node start, Node anchor) { if (start.getChildCount() > 0) { return start.getChild(0); } if (start == anchor) { return null; } Node p = start; while (true) { ParentNode q = p.getParent(); if (q == null) { return null; } int i = q.indexOf(p) + 1; if (i < q.getChildCount()) { return q.getChild(i); } if (q == anchor) { return null; } p = q; } }
/** * Get the following node in an iteration of descendants * * @param start the start node * @param anchor the node marking the root of the subtree within which navigation takes place (may be null) * @return the next node in document order after the start node, excluding attributes and namespaces */ private static Node getSuccessorNode(Node start, Node anchor) { if (start.getChildCount() > 0) { return start.getChild(0); } if (start == anchor) { return null; } Node p = start; while (true) { ParentNode q = p.getParent(); if (q == null) { return null; } int i = q.indexOf(p) + 1; if (i < q.getChildCount()) { return q.getChild(i); } if (q == anchor) { return null; } p = q; } }
public XOMNodeWrapper getNextSibling() { ParentNode parenti = node.getParent(); if (parenti == null) { return null; } int count = parenti.getChildCount(); if (index != -1) { if ((index + 1) < count) { return makeWrapper(parenti.getChild(index + 1), docWrapper, parent, index + 1); } else { return null; } } index = parenti.indexOf(node); if (index + 1 < count) { return makeWrapper(parenti.getChild(index + 1), docWrapper, parent, index + 1); } return null; }
public XOMNodeWrapper getNextSibling() { ParentNode parenti = node.getParent(); if (parenti == null) { return null; } int count = parenti.getChildCount(); if (index != -1) { if ((index + 1) < count) { return makeWrapper(parenti.getChild(index + 1), docWrapper, parent, index + 1); } else { return null; } } index = parenti.indexOf(node); if (index + 1 < count) { return makeWrapper(parenti.getChild(index + 1), docWrapper, parent, index + 1); } return null; }
/** * Get the following node in an iteration of descendants * * @param start the start node * @param anchor the node marking the root of the subtree within which navigation takes place (may be null) * @return the next node in document order after the start node, excluding attributes and namespaces */ private static Node getSuccessorNode(Node start, Node anchor) { if (start.getChildCount() > 0) { return start.getChild(0); } if (start == anchor) { return null; } Node p = start; while (true) { ParentNode q = p.getParent(); if (q == null) { return null; } int i = q.indexOf(p) + 1; // TODO: inefficient if a node has a large number of children if (i < q.getChildCount()) { return q.getChild(i); } if (q == anchor) { return null; } p = q; } }
i = currNode.getParent().indexOf(currNode) - 1;