1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.tree

File AbstractCompositeTree.java

 

Coverage histogram

../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

10
13
4
1
80
41
10
0.77
3.25
4
2.5

Classes

Class Line # Actions
AbstractCompositeTree 38 13 0% 10 5
0.814814881.5%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.tree;
21   
22    import java.util.HashMap;
23    import java.util.List;
24    import java.util.Map;
25   
26    import org.apache.commons.lang3.StringUtils;
27    import org.xwiki.stability.Unstable;
28   
29    /**
30    * Base class for representing a composite tree, where each type of node is handled by a separate component. The node
31    * identifiers are prefixed with the node type.
32    *
33    * @version $Id: 4ec796912f9b7c951a036e1a1e043ed7e3a532c0 $
34    * @since 8.3M2
35    * @since 7.4.5
36    */
37    @Unstable
 
38    public abstract class AbstractCompositeTree extends AbstractTree
39    {
40    protected final Map<String, TreeNode> treeNodeByNodeType = new HashMap<String, TreeNode>();
41   
 
42  13 toggle @Override
43    public List<String> getChildren(String nodeId, int offset, int limit)
44    {
45  13 TreeNode treeNode = getTreeNode(nodeId);
46  13 return treeNode != null ? treeNode.getChildren(nodeId, offset, limit) : null;
47    }
48   
 
49  70 toggle @Override
50    public int getChildCount(String nodeId)
51    {
52  70 TreeNode treeNode = getTreeNode(nodeId);
53  70 return treeNode != null ? treeNode.getChildCount(nodeId) : 0;
54    }
55   
 
56  5 toggle @Override
57    public String getParent(String nodeId)
58    {
59  5 TreeNode treeNode = getTreeNode(nodeId);
60  5 return treeNode != null ? treeNode.getParent(nodeId) : null;
61    }
62   
63    /**
64    * @param nodeId the node identifier
65    * @return the {@link TreeNode} component that handles the specified node type
66    */
 
67  88 toggle protected TreeNode getTreeNode(String nodeId)
68    {
69  88 TreeNode treeNode = null;
70  88 String[] parts = StringUtils.split(nodeId, ":", 2);
71  88 if (parts != null && parts.length == 2) {
72  88 treeNode = this.treeNodeByNodeType.get(parts[0]);
73  88 if (treeNode != null) {
74    // Update the node properties.
75  88 treeNode.getProperties().putAll(getProperties());
76    }
77    }
78  88 return treeNode;
79    }
80    }