Class TreeNodeList

All Implemented Interfaces:
Serializable, Iterable<TreeTable.Node>, Collection<TreeTable.Node>, List<TreeTable.Node>, CheckedContainer<TreeTable.Node>
Direct Known Subclasses:
DefaultTreeTable.Node.Children

abstract class TreeNodeList extends AbstractList<TreeTable.Node> implements CheckedContainer<TreeTable.Node>, Serializable
A list of children in a TreeTable.Node. This list accepts only nodes that either have no parent at addition time, or already have the parent for which this list manages the children. The add and remove operations shall update the parent when needed.

This list does not support duplicated elements. Attempts to add a node which is already an element of another TreeNodeList will cause an IllegalArgumentException to be thrown.

Operations receiving a single TreeTable.Node argument are all or nothing operations: in case of failure, the list will be left in the same state as if no operation were attempted. If a failure occurs during a bulk operations, then the list may be left in a state where some elements where processed and others not.

Subclasses need to define the setParentOf(TreeTable.Node, int) method because the way to set the parent is specific to the node implementation:

Implementation note

We do not extend ArrayList because:
  • We want to use identity comparisons rather than Object.equals(Object).
  • We don't want this list to be cloneable, because it would complexify the management of references to the parent node.
  • Extending AbstractList reduce the number of methods to override, since ArrayList overrides bulk operations with optimized code which are not suitable to TreeNodeList (we need the slower path implemented in AbstractList).
Implementation note: Being serializable may seem contradictory with the non-cloneable requirement. But serializing TreeNodeList will also serialize the parent, thus creating new copy on deserialization. So the parents should not be mixed.
Since:
0.3
Version:
0.3