@Test public void appendChildren() { ArrayList<Element> l = new ArrayList<Element>(); l.add(new Element("foo")); l.add(new Element("foo")); XPathContext ctx = new XPathContext(); ctx.setChildren(l); l = new ArrayList<Element>(); l.add(new Element("bar")); l.add(new Element("foo")); ctx.appendChildren(l); ctx.navigateToChild(0); assertEquals("/foo[1]", ctx.getXPath()); assertEquals("/", ctx.getParentXPath()); ctx.navigateToParent(); ctx.navigateToChild(1); assertEquals("/foo[2]", ctx.getXPath()); assertEquals("/", ctx.getParentXPath()); ctx.navigateToParent(); ctx.navigateToChild(2); assertEquals("/bar[1]", ctx.getXPath()); assertEquals("/", ctx.getParentXPath()); ctx.navigateToParent(); ctx.navigateToChild(3); assertEquals("/foo[3]", ctx.getXPath()); assertEquals("/", ctx.getParentXPath()); }
public void appendChildren(Iterable<? extends NodeInfo> children) { Level current = path.getLast(); int comments, pis, texts; comments = pis = texts = 0; Map<String, Integer> elements = new HashMap<String, Integer>(); for (Level l : current.children) { String childName = l.expression; if (childName.startsWith(COMMENT)) { comments++; } else if (childName.startsWith(PI)) { pis++; } else if (childName.startsWith(TEXT)) { texts++; } else { childName = childName.substring(0, childName.indexOf(OPEN)); add1OrIncrement(childName, elements); } } for (NodeInfo child : children) { Level l; switch (child.getType()) { case Node.COMMENT_NODE: l = new Level(COMMENT + OPEN + (++comments) + CLOSE); break; case Node.PROCESSING_INSTRUCTION_NODE: l = new Level(PI + OPEN + (++pis) + CLOSE); break; case Node.CDATA_SECTION_NODE: case Node.TEXT_NODE: l = new Level(TEXT + OPEN + (++texts) + CLOSE); break; case Node.ELEMENT_NODE: String name = getName(child.getName()); l = new Level(name + OPEN + add1OrIncrement(name, elements) + CLOSE); break; default: l = new Level(EMPTY); break; } current.children.add(l); } }
XPathContext implements Cloneable { public void appendChildren(Iterable<? extends NodeInfo> children) { Level current = path.getLast(); int comments, pis, texts; comments = pis = texts = 0; Map<String, Integer> elements = new HashMap<String, Integer>(); for (Level l : current.children) { String childName = l.expression; if (childName.startsWith(COMMENT)) { comments++; } else if (childName.startsWith(PI)) { pis++; } else if (childName.startsWith(TEXT)) { texts++; } else { childName = childName.substring(0, childName.indexOf(OPEN)); add1OrIncrement(childName, elements); } } for (NodeInfo child : children) { Level l; switch (child.getType()) { case Node.COMMENT_NODE: l = new Level(COMMENT + OPEN + (++comments) + CLOSE); break; case Node.PROCESSING_INSTRUCTION_NODE: l = new Level(PI + OPEN + (++pis) + CLOSE); break; case Node.CDATA_SECTION_NODE: case Node.TEXT_NODE: l = new Level(TEXT + OPEN + (++texts) + CLOSE); break; case Node.ELEMENT_NODE: String name = getName(child.getName()); l = new Level(name + OPEN + add1OrIncrement(name, elements) + CLOSE); break; default: l = new Level(EMPTY); break; } current.children.add(l); } } }
XPathContext implements Cloneable { public void appendChildren(Iterable<? extends NodeInfo> children) { Level current = path.getLast(); int comments, pis, texts; comments = pis = texts = 0; Map<String, Integer> elements = new HashMap<String, Integer>(); for (Level l : current.children) { String childName = l.expression; if (childName.startsWith(COMMENT)) { comments++; } else if (childName.startsWith(PI)) { pis++; } else if (childName.startsWith(TEXT)) { texts++; } else { childName = childName.substring(0, childName.indexOf(OPEN)); add1OrIncrement(childName, elements); } } for (NodeInfo child : children) { Level l; switch (child.getType()) { case Node.COMMENT_NODE: l = new Level(COMMENT + OPEN + (++comments) + CLOSE); break; case Node.PROCESSING_INSTRUCTION_NODE: l = new Level(PI + OPEN + (++pis) + CLOSE); break; case Node.CDATA_SECTION_NODE: case Node.TEXT_NODE: l = new Level(TEXT + OPEN + (++texts) + CLOSE); break; case Node.ELEMENT_NODE: String name = getName(child.getName()); l = new Level(name + OPEN + add1OrIncrement(name, elements) + CLOSE); break; default: l = new Level(EMPTY); break; } current.children.add(l); } } XPathContext();  XPathContext(Node root);  XPathContext(Map<String, String> prefix2uri);  XPathContext(Map<String, String> prefix2uri, Node root); }
XPathContext implements Cloneable { public void appendChildren(Iterable<? extends NodeInfo> children) { Level current = path.getLast(); int comments, pis, texts; comments = pis = texts = 0; Map<String, Integer> elements = new HashMap<String, Integer>(); for (Level l : current.children) { String childName = l.expression; if (childName.startsWith(COMMENT)) { comments++; } else if (childName.startsWith(PI)) { pis++; } else if (childName.startsWith(TEXT)) { texts++; } else { childName = childName.substring(0, childName.indexOf(OPEN)); add1OrIncrement(childName, elements); } } for (NodeInfo child : children) { Level l; switch (child.getType()) { case Node.COMMENT_NODE: l = new Level(COMMENT + OPEN + (++comments) + CLOSE); break; case Node.PROCESSING_INSTRUCTION_NODE: l = new Level(PI + OPEN + (++pis) + CLOSE); break; case Node.CDATA_SECTION_NODE: case Node.TEXT_NODE: l = new Level(TEXT + OPEN + (++texts) + CLOSE); break; case Node.ELEMENT_NODE: String name = getName(child.getName()); l = new Level(name + OPEN + add1OrIncrement(name, elements) + CLOSE); break; default: l = new Level(EMPTY); break; } current.children.add(l); } } XPathContext();  XPathContext(Node root);  XPathContext(Map<String, String> prefix2uri);  XPathContext(Map<String, String> prefix2uri, Node root); void navigateToChild(int index); void navigateToAttribute(QName attribute); void navigateToParent(); void addAttributes(Iterable<? extends QName> attributes); void addAttribute(QName attribute); void setChildren(Iterable<? extends NodeInfo> children); void appendChildren(Iterable<? extends NodeInfo> children); String getXPath(); String getParentXPath(); @Override XPathContext clone(); }
XPathContext implements Cloneable { public void appendChildren(Iterable<? extends NodeInfo> children) { Level current = path.getLast(); int comments, pis, texts; comments = pis = texts = 0; Map<String, Integer> elements = new HashMap<String, Integer>(); for (Level l : current.children) { String childName = l.expression; if (childName.startsWith(COMMENT)) { comments++; } else if (childName.startsWith(PI)) { pis++; } else if (childName.startsWith(TEXT)) { texts++; } else { childName = childName.substring(0, childName.indexOf(OPEN)); add1OrIncrement(childName, elements); } } for (NodeInfo child : children) { Level l; switch (child.getType()) { case Node.COMMENT_NODE: l = new Level(COMMENT + OPEN + (++comments) + CLOSE); break; case Node.PROCESSING_INSTRUCTION_NODE: l = new Level(PI + OPEN + (++pis) + CLOSE); break; case Node.CDATA_SECTION_NODE: case Node.TEXT_NODE: l = new Level(TEXT + OPEN + (++texts) + CLOSE); break; case Node.ELEMENT_NODE: String name = getName(child.getName()); l = new Level(name + OPEN + add1OrIncrement(name, elements) + CLOSE); break; default: l = new Level(EMPTY); break; } current.children.add(l); } } XPathContext();  XPathContext(Node root);  XPathContext(Map<String, String> prefix2uri);  XPathContext(Map<String, String> prefix2uri, Node root); void navigateToChild(int index); void navigateToAttribute(QName attribute); void navigateToParent(); void addAttributes(Iterable<? extends QName> attributes); void addAttribute(QName attribute); void setChildren(Iterable<? extends NodeInfo> children); void appendChildren(Iterable<? extends NodeInfo> children); String getXPath(); String getParentXPath(); @Override XPathContext clone();  }