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 booleantrueif we have verified the value atnextInAccessorindex for non-null or non-empty element.private intThe value ofTreeNodeChildren.modCountat construction time or after the last change done by this iterator.private intIndex inTreeNodeChildren.accessorof the next element to be returned bynext(), orPropertyAccessor.count()if we have reached the end of the list.private ObjectThe value of the node to be returned by thenext()method.private intIndex inTreeNodeChildren.accessorof the element returned by the last call tonext(), or -1 if none.private intPosition of thenextValuein 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 voidThrowsConcurrentModificationExceptionif an unexpected change has been detected.booleanhasNext()Ensures thatnextInAccessoris valid.next()Returns the node for the metadata property at the currentnextInAccessor.voidremove()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, waitMethods inherited from interface java.util.Iterator
forEachRemaining
-
Field Details
-
nextInAccessor
private int nextInAccessorIndex inTreeNodeChildren.accessorof the next element to be returned bynext(), orPropertyAccessor.count()if we have reached the end of the list. -
previousInAccessor
private int previousInAccessorIndex inTreeNodeChildren.accessorof the element returned by the last call tonext(), or -1 if none. -
isNextVerified
private boolean isNextVerifiedtrueif we have verified the value atnextInAccessorindex 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.cachedValuefield. -
subIterator
-
subIndex
private int subIndexPosition of thenextValuein thesubIterator, or -1 if the sub-iterator is null. -
modCountCheck
private int modCountCheckThe value ofTreeNodeChildren.modCountat 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()ThrowsConcurrentModificationExceptionif an unexpected change has been detected. -
hasNext
public boolean hasNext()Ensures thatnextInAccessoris valid. If the index has not been validated, then this method moves the iterator to the next valid element, starting at the currentnextInAccessorvalue.- Specified by:
hasNextin interfaceIterator<TreeTable.Node>- Returns:
trueon success, orfalseif 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:
nextin 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_EMPTYpolicy, the effect is a removal.- Specified by:
removein interfaceIterator<TreeTable.Node>
-