1 /*
2 * Copyright (C) 2002 Carsten Krebs (Team-Konzept GmbH & Co.KG)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 package com.teamkonzept.dom4jb.saxon;
19
20 import com.icl.saxon.om.AxisEnumeration;
21 import com.icl.saxon.om.NodeInfo;
22 import org.w3c.dom.NodeList;
23
24 public class SiblingEnumeration implements AxisEnumeration {
25 private final NodeList children;
26 private final boolean forwards;
27 private int idx;
28 private NodeInfo nextNode;
29
30
31 public SiblingEnumeration( final AxisNode start, final boolean forwards ) {
32 this.children = start.getParentNode().getChildNodes();
33 this.forwards = forwards;
34 this.idx = ((com.teamkonzept.dom4jb.dom.Node)start).getChildIndex();
35 this.idx += forwards ? 1 : -1;
36 this.nextNode = null;
37 }
38
39 public int getLastPosition() {
40 return 1; // not used
41 }
42
43 public boolean hasMoreElements() {
44 if ( nextNode != null ) {
45 return true;
46 }
47 return (nextNode=(NodeInfo)children.item(idx)) != null;
48 }
49
50 public boolean isPeer() {
51 return true;
52 }
53
54 public boolean isReverseSorted() {
55 return !forwards;
56 }
57
58 public boolean isSorted() {
59 return forwards;
60 }
61
62 public NodeInfo nextElement() {
63 final NodeInfo node;
64 if ( nextNode != null ) {
65 node = nextNode;
66 nextNode = null;
67 } else {
68 node = (NodeInfo)children.item(idx);
69 }
70 idx += forwards ? 1 : -1;
71 return node;
72 }
73 }
This page was automatically generated by Maven