Coverage Report - org.apache.tapestry.contrib.tree.simple.TreeNode
 
Classes in this File Line Coverage Branch Coverage Complexity
TreeNode
0%
0/29
0%
0/4
1.143
 
 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  
 
 31  
     private static final long serialVersionUID = 677919478017303186L;
 32  
 
 33  
     protected Set m_setChildren;
 34  
     protected IMutableTreeNode m_objParentNode;
 35  
 
 36  
     /**
 37  
      * Constructor for TreeNode.
 38  
      */
 39  
     public TreeNode()
 40  
     {
 41  0
         this(null);
 42  0
     }
 43  
 
 44  
     public TreeNode(IMutableTreeNode parentNode)
 45  
     {
 46  0
         super();
 47  0
         m_objParentNode = parentNode;
 48  0
         m_setChildren = new HashSet();
 49  0
     }
 50  
 
 51  
     public int getChildCount()
 52  
     {
 53  0
         return m_setChildren.size();
 54  
     }
 55  
 
 56  
     public ITreeNode getParent()
 57  
     {
 58  0
         return m_objParentNode;
 59  
     }
 60  
 
 61  
     public boolean getAllowsChildren()
 62  
     {
 63  0
         return true;
 64  
     }
 65  
 
 66  
     public boolean isLeaf()
 67  
     {
 68  0
         return m_setChildren.size() == 0 ? true : false;
 69  
     }
 70  
 
 71  
     public Collection children()
 72  
     {
 73  0
         return m_setChildren;
 74  
     }
 75  
 
 76  
     public void insert(IMutableTreeNode child)
 77  
     {
 78  0
         child.setParent(this);
 79  0
         m_setChildren.add(child);
 80  0
     }
 81  
 
 82  
     public void remove(IMutableTreeNode node)
 83  
     {
 84  0
         m_setChildren.remove(node);
 85  0
     }
 86  
 
 87  
     public void removeFromParent()
 88  
     {
 89  0
         m_objParentNode.remove(this);
 90  0
         m_objParentNode = null;
 91  0
     }
 92  
 
 93  
     public void setParent(IMutableTreeNode newParent)
 94  
     {
 95  0
         m_objParentNode = newParent;
 96  0
     }
 97  
 
 98  
     public void insert(Collection colChildren)
 99  
     {
 100  0
         for(Iterator iter = colChildren.iterator(); iter.hasNext();)
 101  
         {
 102  0
             IMutableTreeNode element = (IMutableTreeNode) iter.next();
 103  0
             element.setParent(this);
 104  0
             m_setChildren.add(element);
 105  0
         }
 106  0
     }
 107  
 
 108  
     /**
 109  
      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#containsChild(ITreeNode)
 110  
      */
 111  
     public boolean containsChild(ITreeNode node)
 112  
     {
 113  0
         return m_setChildren.contains(node);
 114  
     }
 115  
 
 116  
     /**
 117  
      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildren()
 118  
      */
 119  
     public Collection getChildren()
 120  
     {
 121  0
         return m_setChildren;
 122  
     }
 123  
 
 124  
 }