1 package com.sri.emo.dbobj.model_tree;
2
3 import java.util.Iterator;
4
5
6 /***
7 * Default implementation of the 'model' interface. Provides concrete
8 * implementations of access to the iterator() function and all
9 * other requirements of the <tt>Model</tt> interface. Most of the
10 * guts of the model, however, are stored in {@link com.sri.emo.dbobj.model_tree.DefaultModelNode}
11 *
12 * @author Michael Rimov
13 */
14 public class DefaultModel implements Model {
15
16
17 /***
18 * The root of the hierarchy.
19 */
20 private final ModelNode root;
21
22 /***
23 * Constructor that takes the
24 *
25 * @param modelRoot ModelCompositeNode
26 */
27 public DefaultModel(final ModelNode modelRoot) {
28 super();
29 root = modelRoot;
30 }
31
32 /***
33 * Allows for the client to visit the nodes one-by-one.
34 *
35 * @return Iterator
36 */
37 public Iterator iterator() {
38 return new ModelDepthFirstIterator(root);
39 }
40
41 /***
42 * Allows for client to visit nodes one by one as well as be notified
43 * whenever traversal in the internal composite tree occurs.
44 *
45 * @param traversallistener TreeTraversalListener
46 * @return Iterator
47 */
48 public Iterator iterator(final TreeTraversalListener traversallistener) {
49 return new ModelDepthFirstIterator(root, traversallistener);
50 }
51
52 /***
53 * Retrieves the root of the tree hierarchy to allow for manual
54 * manipulation if needed.
55 *
56 * @return ModelCompositeNode
57 */
58 public ModelNode getRoot() {
59 return root;
60 }
61 }