Class NodeSequence.IteratorCache
- Enclosing class:
NodeSequence
Note that multiple NodeSequence objects may hold a reference to the same cache, and also (and this is important) the same iterator. The iterator and its cache may be shared among many NodeSequence objects.
If one of the NodeSequence objects walks ahead of the others it fills in the cache. As the others NodeSequence objects catch up they get their values from the cache rather than the iterator itself, so the iterator is only ever walked once and everyone benefits from the cache.
At some point the cache may be complete due to walking to the end of one of the copies of the iterator, and the cache is then marked as "complete". and the cache will have no more nodes added to it.
Its use-count is the number of NodeSequence objects that use it.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
true if the associated iterator is exhausted and all nodes obtained from it are in the cache.private NodeVector
A list of nodes already obtained from the iterator. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate NodeVector
Get the cached list of nodes obtained from the iterator so far.private boolean
Returns true if no cache is complete and immutable.private void
setCacheComplete
(boolean b) Call this method with 'true' if the iterator is exhausted and the cached list is complete, or no longer growing.private void
setVector
(NodeVector nv) Sets the NodeVector that holds the growing list of nodes as they are appended to the cached list.
-
Field Details
-
m_vec2
A list of nodes already obtained from the iterator. As the iterator is walked the nodes obtained from it are appended to this list.Both an iterator and its corresponding cache can be shared by multiple NodeSequence objects.
For example, consider three NodeSequence objects ns1, ns2 and ns3 doing such sharing, and the nodes to be obtaind from the iterator being the sequence { 33, 11, 44, 22, 55 }.
If ns3.nextNode() is called 3 times the the underlying iterator will have walked through 33, 11, 55 and these three nodes will have been put in the cache.
If ns2.nextNode() is called 2 times it will return 33 and 11 from the cache, leaving the iterator alone.
If ns1.nextNode() is called 6 times it will return 33 and 11 from the cache, then get 44, 22, 55 from the iterator, and appending 44, 22, 55 to the cache. On the sixth call it is found that the iterator is exhausted and the cache is marked complete.
Should ns2 or ns3 have nextNode() called they will know that the cache is complete, and they will obtain all subsequent nodes from the cache.
Note that the underlying iterator, though shared is only ever walked once.
-
m_isComplete2
private boolean m_isComplete2true if the associated iterator is exhausted and all nodes obtained from it are in the cache.
-
-
Constructor Details
-
IteratorCache
IteratorCache()
-
-
Method Details
-
setVector
Sets the NodeVector that holds the growing list of nodes as they are appended to the cached list. -
getVector
Get the cached list of nodes obtained from the iterator so far. -
setCacheComplete
private void setCacheComplete(boolean b) Call this method with 'true' if the iterator is exhausted and the cached list is complete, or no longer growing. -
isComplete
private boolean isComplete()Returns true if no cache is complete and immutable.
-