|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
TreeNode.java | 0% | 0% | 0% | 0% |
|
1 |
// Copyright 2004, 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
14 |
|
|
15 |
package org.apache.tapestry.contrib.tree.simple;
|
|
16 |
|
|
17 |
import java.util.Collection;
|
|
18 |
import java.util.HashSet;
|
|
19 |
import java.util.Iterator;
|
|
20 |
import java.util.Set;
|
|
21 |
|
|
22 |
import org.apache.tapestry.contrib.tree.model.IMutableTreeNode;
|
|
23 |
import org.apache.tapestry.contrib.tree.model.ITreeNode;
|
|
24 |
|
|
25 |
/**
|
|
26 |
* @author ceco
|
|
27 |
*/
|
|
28 |
public class TreeNode implements IMutableTreeNode { |
|
29 |
|
|
30 |
protected Set m_setChildren;
|
|
31 |
protected IMutableTreeNode m_objParentNode;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* Constructor for TreeNode.
|
|
35 |
*/
|
|
36 | 0 |
public TreeNode() {
|
37 | 0 |
this(null); |
38 |
} |
|
39 | 0 |
public TreeNode(IMutableTreeNode parentNode) {
|
40 | 0 |
super();
|
41 | 0 |
m_objParentNode = parentNode; |
42 | 0 |
m_setChildren = new HashSet();
|
43 |
} |
|
44 |
|
|
45 |
|
|
46 | 0 |
public int getChildCount() { |
47 | 0 |
return m_setChildren.size();
|
48 |
} |
|
49 |
|
|
50 | 0 |
public ITreeNode getParent() {
|
51 | 0 |
return m_objParentNode;
|
52 |
} |
|
53 |
|
|
54 | 0 |
public boolean getAllowsChildren() { |
55 | 0 |
return true; |
56 |
} |
|
57 |
|
|
58 | 0 |
public boolean isLeaf() { |
59 | 0 |
return m_setChildren.size() == 0 ? true:false; |
60 |
} |
|
61 |
|
|
62 | 0 |
public Collection children() {
|
63 | 0 |
return m_setChildren;
|
64 |
} |
|
65 |
|
|
66 |
|
|
67 | 0 |
public void insert(IMutableTreeNode child) { |
68 | 0 |
child.setParent(this);
|
69 | 0 |
m_setChildren.add(child); |
70 |
} |
|
71 |
|
|
72 | 0 |
public void remove(IMutableTreeNode node) { |
73 | 0 |
m_setChildren.remove(node); |
74 |
} |
|
75 |
|
|
76 | 0 |
public void removeFromParent() { |
77 | 0 |
m_objParentNode.remove(this);
|
78 | 0 |
m_objParentNode = null;
|
79 |
} |
|
80 |
|
|
81 | 0 |
public void setParent(IMutableTreeNode newParent) { |
82 | 0 |
m_objParentNode = newParent; |
83 |
} |
|
84 |
|
|
85 | 0 |
public void insert(Collection colChildren){ |
86 | 0 |
for (Iterator iter = colChildren.iterator(); iter.hasNext();) {
|
87 | 0 |
IMutableTreeNode element = (IMutableTreeNode) iter.next(); |
88 | 0 |
element.setParent(this);
|
89 | 0 |
m_setChildren.add(element); |
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
/**
|
|
94 |
* @see org.apache.tapestry.contrib.tree.model.ITreeNode#containsChild(ITreeNode)
|
|
95 |
*/
|
|
96 | 0 |
public boolean containsChild(ITreeNode node) { |
97 | 0 |
return m_setChildren.contains(node);
|
98 |
} |
|
99 |
|
|
100 |
/**
|
|
101 |
* @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildren()
|
|
102 |
*/
|
|
103 | 0 |
public Collection getChildren() {
|
104 | 0 |
return m_setChildren;
|
105 |
} |
|
106 |
|
|
107 |
} |
|
108 |
|
|