PDA

View Full Version : implement 'nextSibling()' method



mickey
17th July 2010, 18:04
Hello,
I'd like to obtain this under but I don't know what I must to use. I need to access to the father of an object; I give you the idea under here:


public class MyElemNode extends MyNode {
List<MyNode> child = new ArrayList<MyNode>();

public MyElemNode() { }
public MyNode getFirstChild() { return child.get(0); }
public MyNode getLastChild() { return child.get( child.size()-1 ); }
public MyNode nextSiblingNode() { //1
int i = getPositionOfThisObjectInFather.child();
return father.child(i+1);
}
}
//main
MyElemNode e = new MyElemNode();
e. add( new MyElemNode, new MyElemNode ......................);
MyElemNode ep = e.get(5); //assuming it exists
MyElemNode sib = ep.nextSibling(); // how to obtain this?

thanks

franz
18th July 2010, 07:47
Pass the parent (father) in the constructor or add a setParent() function to your node.