Java: Swing: JTree and TreeModel: MapTreeModel
This example uses a structure that is often used for storing tree structures. The main data structure is a Map. Each node is mapped to a List of its children. If the node isn't contained in the Map, it is regarded as a leaf. Nodes that have no children, but should not be leaf, are mapped to an empty List.
The actual tree structure is static. The model constructor takes a Map argument, which it assumes (like the contained List) to never become modified. An additional argument that should be the root of the TreeModel is taken.
The concept of using a Map to map nodes to their child nodes (or a richer information structure) can often be used.
The test class is rather stupid.
Source files: MapTreeModel.java MapTreeModelTest.java
(C) 2001-2009 Christian Kaufhold (swing@chka.de)