ru.greatbit.utils.tree.nodes.BaseOriented Maven / Gradle / Ivy
package ru.greatbit.utils.tree.nodes;
import ru.greatbit.utils.tree.api.Oriented;
import java.util.LinkedList;
import java.util.List;
/**
* Created by azee on 5/8/14.
* A base class for all N-ary oriented trees
*/
public class BaseOriented extends Node implements Oriented {
private List leftChildren;
private List rightChildren;
@Override
public List getLeftChildren() {
if (leftChildren == null){
leftChildren = new LinkedList();
}
return leftChildren;
}
@Override
public List getRightChildren() {
if (rightChildren == null){
rightChildren = new LinkedList();
}
return rightChildren;
}
@Override
public List getChildren() {
List result = new LinkedList();
if (getLeftChildren().size() > 0){
result.addAll(getLeftChildren());
}
if (getRightChildren().size() > 0){
result.addAll(getRightChildren());
}
return result;
}
}