Package org.apache.sis.metadata
Class TreeNodeChildren.Iter
java.lang.Object
org.apache.sis.metadata.TreeNodeChildren.Iter
- All Implemented Interfaces:
Iterator<TreeTable.Node>
- Enclosing class:
- TreeNodeChildren
The iterator over the elements in the enclosing
TreeNodeChildren
collection.
Each element is identified by its index in the PropertyAccessor
, together with
its position in its sub-iterator when the metadata property is a collection.
Implementation note
It could be cheaper to not take an iterator for the properties that are collections, and instead just increment a "sub-index" from 0 to the collection size. It would be cheaper because we don't really need to extract the values of those collections (i.e. thenextValue
field is not really needed). Nevertheless we prefer (for now)
the iterator approach anyway because it makes easier to implement the remove()
method and has the desired side-effect to check for concurrent modifications. It also
keeps the nextValue
field up-to-date in case we would like to use it in a
future SIS version. We do that on the assumption that sub-iterators are cheap since
they are ArrayList
iterators in the majority of cases.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
true
if we have verified the value atnextInAccessor
index for non-null or non-empty element.private int
The value ofTreeNodeChildren.modCount
at construction time or after the last change done by this iterator.private int
Index inTreeNodeChildren.accessor
of the next element to be returned bynext()
, orPropertyAccessor.count()
if we have reached the end of the list.private Object
The value of the node to be returned by thenext()
method.private int
Index inTreeNodeChildren.accessor
of the element returned by the last call tonext()
, or -1 if none.private int
Position of thenextValue
in thesubIterator
, or -1 if the sub-iterator is null.private Iterator<?>
If the call tonext()
found a collection, the iterator over the elements in that collection. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) final void
ThrowsConcurrentModificationException
if an unexpected change has been detected.boolean
hasNext()
Ensures thatnextInAccessor
is valid.next()
Returns the node for the metadata property at the currentnextInAccessor
.void
remove()
Clears the element returned by the last call tonext()
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Iterator
forEachRemaining
-
Field Details
-
nextInAccessor
private int nextInAccessorIndex inTreeNodeChildren.accessor
of the next element to be returned bynext()
, orPropertyAccessor.count()
if we have reached the end of the list. -
previousInAccessor
private int previousInAccessorIndex inTreeNodeChildren.accessor
of the element returned by the last call tonext()
, or -1 if none. -
isNextVerified
private boolean isNextVerifiedtrue
if we have verified the value atnextInAccessor
index for non-null or non-empty element. -
nextValue
The value of the node to be returned by thenext()
method. This value is computed ahead of time byhasNext()
since we need that information in order to determine if the value needs to be skipped or not.Note: Actually we don't really need to keep this value, since it is not used outside thehasNext()
method. But we keep it for allowing thenext()
method to opportunistically update theTreeNode.cachedValue
field. -
subIterator
-
subIndex
private int subIndexPosition of thenextValue
in thesubIterator
, or -1 if the sub-iterator is null. -
modCountCheck
private int modCountCheckThe value ofTreeNodeChildren.modCount
at construction time or after the last change done by this iterator. Used for concurrent modification checks.Note: Actually this iterator should be robust to most concurrent modifications. But we check anyway in order to prevent concurrent modifications in user code, in case a future SIS version become more sensitive to such changes.
-
-
Constructor Details
-
Iter
Iter()Creates a new iterator.
-
-
Method Details
-
checkConcurrentModification
final void checkConcurrentModification()ThrowsConcurrentModificationException
if an unexpected change has been detected. -
hasNext
public boolean hasNext()Ensures thatnextInAccessor
is valid. If the index has not been validated, then this method moves the iterator to the next valid element, starting at the currentnextInAccessor
value.- Specified by:
hasNext
in interfaceIterator<TreeTable.Node>
- Returns:
true
on success, orfalse
if we reached the end of the iteration.
-
next
Returns the node for the metadata property at the currentnextInAccessor
. The value of this property is initiallynextValue
, but this may change at any time if the user modifies the underlying metadata object.- Specified by:
next
in interfaceIterator<TreeTable.Node>
-
remove
public void remove()Clears the element returned by the last call tonext()
. Whether the cleared element is considered removed or not depends on the value policy and on the element type. With the defaultNON_EMPTY
policy, the effect is a removal.- Specified by:
remove
in interfaceIterator<TreeTable.Node>
-