[jdom-interest] Re arranging child nodes

Kesav Kumar kesavk at voquette.com
Thu Nov 30 09:43:56 PST 2000

I wanted to rearrange the childrens of a parent node i wrote code like this.

public void moveUp(Element node)
Element parent = node.getParent();
List children = parent.getChildren();
int index = children.indexOf(node);
if(inde > 0) //Ensuring this is not already first element
	//I want to swapt the positions of the children.
	Element tmpElement = children.get(index -1);
	children.set(index-1, node);
	children.set(inde, tmpElement);

I thought I will get my desired result but I didn't get expected result whin
I printed the childrens of the parent again.  I found few intersting lines
in PartialList.java set method

        Object old = get(index);
        int backingIndex = backingList.indexOf(old);
        if (backingIndex != -1) {
            backingList.set(backingIndex, current);

        if (old instanceof Element) {

First line is ok I didn't understand the logic behind getting the
backingIndex and setting the oldElement parent null. Since backingIndex will
give all the modfied incies I feel its not good to use backingindex on the
basis of backingList.indexOf(old).  Can anyone share their thoughts.


Kesav Kumar
Software Engineer
Voquette, Inc.
650 356 3740
mailto:kesavk at voquette.com

More information about the jdom-interest mailing list