Skip to content

Commit e8e17f8

Browse files
committed
simplify class tree
1 parent 089c784 commit e8e17f8

2 files changed

Lines changed: 33 additions & 69 deletions

File tree

src/main/java/org/htmlunit/xpath/xml/dtm/ref/DTMDefaultBaseIterators.java

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
/** This class implements the traversers for DTMDefaultBase. */
3333
public abstract class DTMDefaultBaseIterators extends DTMDefaultBaseTraversers {
3434

35+
/**
36+
* Current iteration location. Usually this is the last location returned (starting point for
37+
* the next() search); for single-node iterators it may instead be initialized to point to that
38+
* single node.
39+
*/
40+
protected int _currentNode;
41+
3542
/**
3643
* Construct a DTMDefaultBaseTraversers object from a DOM node.
3744
*
@@ -100,33 +107,8 @@ public DTMAxisIterator getAxisIterator(final int axis) {
100107
return iterator;
101108
}
102109

103-
/**
104-
* Abstract superclass defining behaviors shared by all DTMDefault's internal implementations of
105-
* DTMAxisIterator. Subclass this (and override, if necessary) to implement the specifics of an
106-
* individual axis iterator.
107-
*
108-
* <p>Currently there isn't a lot here
109-
*/
110-
public abstract static class InternalAxisIteratorBase extends DTMAxisIteratorBase {
111-
112-
// %REVIEW% We could opt to share _nodeType and setNodeType() as
113-
// well, and simply ignore them in iterators which don't use them.
114-
// But Scott's worried about the overhead involved in cloning
115-
// these, and wants them to have as few fields as possible. Note
116-
// that we can't create a TypedInternalAxisIteratorBase because
117-
// those are often based on the untyped versions and Java doesn't
118-
// support multiple inheritance. <sigh/>
119-
120-
/**
121-
* Current iteration location. Usually this is the last location returned (starting point for
122-
* the next() search); for single-node iterators it may instead be initialized to point to that
123-
* single node.
124-
*/
125-
protected int _currentNode;
126-
} // end of InternalAxisIteratorBase
127-
128110
/** Iterator that returns all immediate children of a given node */
129-
public final class ChildrenIterator extends InternalAxisIteratorBase {
111+
public final class ChildrenIterator extends DTMAxisIteratorBase {
130112

131113
/** {@inheritDoc} */
132114
@Override
@@ -160,7 +142,7 @@ public int next() {
160142
* Iterator that returns the parent of a given node. Note that this delivers only a single node;
161143
* if you want all the ancestors, see AncestorIterator.
162144
*/
163-
public final class ParentIterator extends InternalAxisIteratorBase {
145+
public final class ParentIterator extends DTMAxisIteratorBase {
164146

165147
/** {@inheritDoc} */
166148
@Override
@@ -193,7 +175,7 @@ public int next() {
193175
/**
194176
* Iterator that returns the namespace nodes as defined by the XPath data model for a given node.
195177
*/
196-
public class NamespaceIterator extends InternalAxisIteratorBase {
178+
public class NamespaceIterator extends DTMAxisIteratorBase {
197179

198180
/** Constructor NamespaceAttributeIterator */
199181
public NamespaceIterator() {
@@ -231,7 +213,7 @@ public int next() {
231213
} // end of NamespaceIterator
232214

233215
/** Iterator that returns the root node as defined by the XPath data model for a given node. */
234-
public class RootIterator extends InternalAxisIteratorBase {
216+
public class RootIterator extends DTMAxisIteratorBase {
235217

236218
/** Constructor RootIterator */
237219
public RootIterator() {
@@ -265,7 +247,7 @@ public int next() {
265247
} // end of RootIterator
266248

267249
/** Iterator that returns all siblings of a given node. */
268-
public class FollowingSiblingIterator extends InternalAxisIteratorBase {
250+
public class FollowingSiblingIterator extends DTMAxisIteratorBase {
269251

270252
/** {@inheritDoc} */
271253
@Override
@@ -291,7 +273,7 @@ public int next() {
291273
} // end of FollowingSiblingIterator
292274

293275
/** Iterator that returns attribute nodes (of what nodes?) */
294-
public final class AttributeIterator extends InternalAxisIteratorBase {
276+
public final class AttributeIterator extends DTMAxisIteratorBase {
295277

296278
// assumes caller will pass element nodes
297279

@@ -326,7 +308,7 @@ public int next() {
326308
} // end of AttributeIterator
327309

328310
/** Iterator that returns preceding siblings of a given node */
329-
public class PrecedingSiblingIterator extends InternalAxisIteratorBase {
311+
public class PrecedingSiblingIterator extends DTMAxisIteratorBase {
330312

331313
/** The node identity of _startNode for this iterator */
332314
protected int _startNodeID;
@@ -391,7 +373,7 @@ public int next() {
391373
* Iterator that returns preceding nodes of a given node. This includes the node set {root+1,
392374
* start-1}, but excludes all ancestors, attributes, and namespace nodes.
393375
*/
394-
public class PrecedingIterator extends InternalAxisIteratorBase {
376+
public class PrecedingIterator extends DTMAxisIteratorBase {
395377

396378
/** The max ancestors, but it can grow... */
397379
private final int _maxAncestors = 8;
@@ -504,7 +486,7 @@ public void reset() {
504486
} // end of PrecedingIterator
505487

506488
/** Iterator that returns following nodes of for a given node. */
507-
public class FollowingIterator extends InternalAxisIteratorBase {
489+
public class FollowingIterator extends DTMAxisIteratorBase {
508490
final DTMAxisTraverser m_traverser; // easier for now
509491

510492
public FollowingIterator() {
@@ -543,7 +525,7 @@ public int next() {
543525
* Iterator that returns the ancestors of a given node in document order. (NOTE! This was changed
544526
* from the XSLTC code!)
545527
*/
546-
public class AncestorIterator extends InternalAxisIteratorBase {
528+
public class AncestorIterator extends DTMAxisIteratorBase {
547529
final ArrayList<Integer> m_ancestors = new ArrayList<>();
548530

549531
int m_ancestorsPos;
@@ -631,7 +613,7 @@ public int next() {
631613
} // end of AncestorIterator
632614

633615
/** Iterator that returns the descendants of a given node. */
634-
public class DescendantIterator extends InternalAxisIteratorBase {
616+
public class DescendantIterator extends DTMAxisIteratorBase {
635617

636618
/** {@inheritDoc} */
637619
@Override
@@ -714,7 +696,7 @@ public void reset() {
714696
} // end of DescendantIterator
715697

716698
/** Class SingletonIterator. */
717-
public class SingletonIterator extends InternalAxisIteratorBase {
699+
public class SingletonIterator extends DTMAxisIteratorBase {
718700

719701
/** (not sure yet what this is. -sb) (sc & sb remove final to compile in JDK 1.1.8) */
720702
private final boolean _isConstant;

src/main/java/org/htmlunit/xpath/xml/dtm/ref/DTMDefaultBaseTraversers.java

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,9 @@ public int next(final int context, int current, final int expandedTypeID) {
339339
}
340340

341341
/**
342-
* Super class for derived classes that want a convenient way to access the indexing mechanism.
342+
* Implements traversal of the Ancestor access, in reverse document order.
343343
*/
344-
private abstract class IndexedDTMAxisTraverser extends DTMAxisTraverser {
345-
344+
private class DescendantTraverser extends DTMAxisTraverser {
346345
/**
347346
* Tell if the indexing is on and the given expanded type ID matches what is in the indexes.
348347
* Derived classes should call this before calling {@link #getNextIndexed(int, int, int)
@@ -356,26 +355,6 @@ protected final boolean isIndexed(final int expandedTypeID) {
356355
return m_indexing && ExpandedNameTable.ELEMENT == m_expandedNameTable.getType(expandedTypeID);
357356
}
358357

359-
/**
360-
* Tell if a node is outside the axis being traversed. This method must be implemented by
361-
* derived classes, and must be robust enough to handle any node that occurs after the axis
362-
* root.
363-
*
364-
* @param axisRoot The root identity of the axis.
365-
* @param identity The node in question.
366-
* @return true if the given node falls outside the axis being traversed.
367-
*/
368-
protected abstract boolean isAfterAxis(int axisRoot, int identity);
369-
370-
/**
371-
* Tell if the axis has been fully processed to tell if the wait for an arriving node should
372-
* terminate. This method must be implemented be a derived class.
373-
*
374-
* @param axisRoot The root identity of the axis.
375-
* @return true if the axis has been fully processed.
376-
*/
377-
protected abstract boolean axisHasBeenProcessed(int axisRoot);
378-
379358
/**
380359
* Get the next indexed node that matches the expanded type ID. Before calling this function,
381360
* one should first call {@link #isIndexed(int) isIndexed} to make sure that the index can
@@ -412,12 +391,7 @@ else if (axisHasBeenProcessed(axisRoot)) {
412391

413392
return DTM.NULL;
414393
}
415-
}
416394

417-
/**
418-
* Implements traversal of the Ancestor access, in reverse document order.
419-
*/
420-
private class DescendantTraverser extends IndexedDTMAxisTraverser {
421395
/**
422396
* Get the first potential identity that can be returned. This should be overridded by classes
423397
* that need to return the self node.
@@ -430,9 +404,12 @@ protected int getFirstPotential(final int identity) {
430404
}
431405

432406
/**
433-
* {@inheritDoc}
407+
* Tell if the axis has been fully processed to tell if the wait for an arriving node should
408+
* terminate. This method must be implemented be a derived class.
409+
*
410+
* @param axisRoot The root identity of the axis.
411+
* @return true if the axis has been fully processed.
434412
*/
435-
@Override
436413
protected boolean axisHasBeenProcessed(final int axisRoot) {
437414
return !(m_nextsib.elementAt(axisRoot) == NOTPROCESSED);
438415
}
@@ -464,9 +441,14 @@ protected boolean isDescendant(final int subtreeRootIdentity, final int identity
464441
}
465442

466443
/**
467-
* {@inheritDoc}
444+
* Tell if a node is outside the axis being traversed. This method must be implemented by
445+
* derived classes, and must be robust enough to handle any node that occurs after the axis
446+
* root.
447+
*
448+
* @param axisRoot The root identity of the axis.
449+
* @param identity The node in question.
450+
* @return true if the given node falls outside the axis being traversed.
468451
*/
469-
@Override
470452
protected boolean isAfterAxis(final int axisRoot, int identity) {
471453
// %REVIEW% Is there *any* cheaper way to do this?
472454
// Yes. In ID space, compare to axisRoot's successor

0 commit comments

Comments
 (0)