001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.util;
016    
017    import java.util.ArrayList;
018    import java.util.List;
019    
020    /**
021     * @author Shuyang Zhou
022     */
023    public class ListTree<T extends Comparable<T>> {
024    
025            public ListTree() {
026                    this(null);
027            }
028    
029            public ListTree(T value) {
030                    _rootNode = new TreeNode<T>(value);
031            }
032    
033            public List<TreeNode<T>> getChildNodes(TreeNode<T> node) {
034                    List<TreeNode<T>> nodes = new ArrayList<TreeNode<T>>();
035    
036                    getChildNodes(node, nodes);
037    
038                    return nodes;
039            }
040    
041            public TreeNode<T> getRootNode() {
042                    return _rootNode;
043            }
044    
045            protected void getChildNodes(TreeNode<T> node, List<TreeNode<T>> nodes) {
046                    List<TreeNode<T>> childNodes = node.getChildNodes();
047    
048                    nodes.addAll(childNodes);
049    
050                    for (TreeNode<T> childNode : childNodes) {
051                            getChildNodes(childNode, nodes);
052                    }
053            }
054    
055            private final TreeNode<T> _rootNode;
056    
057    }