comparison src/treecms/memory/OnMemoryTree.java @ 6:12604eb6b615

added javadoc
author shoshi
date Mon, 14 Mar 2011 23:24:38 +0900
parents f5ed85be5640
children fc19e38b669b
comparison
equal deleted inserted replaced
5:87bba22e4fa2 6:12604eb6b615
49 public Node getNodeByUUID(String _uuid) 49 public Node getNodeByUUID(String _uuid)
50 { 50 {
51 return m_table.get(_uuid); 51 return m_table.get(_uuid);
52 } 52 }
53 53
54 @Override
55 public synchronized Node updateTree(Node _target,NodeData _newData)
56 {
57 LinkedList<OnMemoryNode> path = findAndClone(m_root,(OnMemoryNode)_target,_newData);
58
59 if(path == null)
60 {
61 //not found.
62 return null;
63 }
64
65 m_root = path.peekFirst();
66 return path.peekLast();
67 }
68
69 OnMemoryNode cloneNode(OnMemoryNode _target,NodeData _newData)
70 {
71 OnMemoryNode clone = m_forest.createNode(_target.getID().update(),_newData);
72 m_table.put(clone.getID().getUUID(),clone);
73 return clone;
74 }
75
76 LinkedList<OnMemoryNode> findAndClone(OnMemoryNode _parent,OnMemoryNode _target,NodeData _newData)
77 {
78 if(_parent.getID().isFamily(_target.getID())){
79 //find.
80 LinkedList<OnMemoryNode> path = new LinkedList<OnMemoryNode>();
81 OnMemoryNode clone = cloneNode((OnMemoryNode)_parent,_newData);
82 path.addFirst(clone);
83 return path;
84 }
85
86 for(Node child : _parent.getData().list()){
87 LinkedList<OnMemoryNode> path = findAndClone((OnMemoryNode)child,_target,_newData);
88 if(path != null){
89 OnMemoryNode clone = cloneNode((OnMemoryNode)_parent,null);
90 clone.getData().list().remove(child);
91 clone.getData().list().add(path.peekFirst());
92 path.addFirst(clone);
93 return path;
94 }
95 }
96
97 return null; //not found.
98 }
99
100 @Override
101 public Node getRoot()
102 {
103 return m_root;
104 }
105
106 } 54 }