com.liferay.portal.kernel.util.TreeNode Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of portal-service Show documentation
Show all versions of portal-service Show documentation
Contains interfaces for the portal services. Interfaces are only loaded by the global class loader and are shared by all plugins.
/**
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.kernel.util;
import java.util.ArrayList;
import java.util.List;
/**
* @author Shuyang Zhou
* @author Dennis Ju
* @author Brian Wing Shun Chan
*/
public class TreeNode> {
public TreeNode(T value) {
this(value, null);
}
public TreeNode(T value, TreeNode parentNode) {
this(value, parentNode, new ArrayList>());
}
public TreeNode(
T value, TreeNode parentNode, List> childNodes) {
_value = value;
_parentNode = parentNode;
_childNodes = childNodes;
}
public TreeNode addChildNode(T value) {
TreeNode childNode = new TreeNode(value, this);
_childNodes.add(childNode);
return childNode;
}
public List> getChildNodes() {
return _childNodes;
}
public List getChildValues() {
List values = new ArrayList(_childNodes.size());
for (TreeNode childNode : _childNodes) {
values.add(childNode.getValue());
}
return values;
}
public TreeNode getParentNode() {
return _parentNode;
}
public T getValue() {
return _value;
}
public boolean isRootNode() {
if (_parentNode == null) {
return true;
}
else {
return false;
}
}
private final List> _childNodes;
private final TreeNode _parentNode;
private final T _value;
}