[jdom-interest] Collections.sort and multiple parent-child relationships

Stephan Trebels stephan at ncube.de
Tue Sep 17 23:56:22 PDT 2002


we had the "Collections sort on the children list of an element" problem
a bunch of times.  This is Collections.sort in 1.4.0_01:

    public static void sort(List list) {
	Object a[] = list.toArray();
	ListIterator i = list.listIterator();
	for (int j=0; j<a.length; j++) {

IOW, the sorting is not the problem, it is the storing via the
ListIterator later.  JDOM will complain that an element can only be
the child of another element once.

What is the technical reason for this (except, that it looks cleaner)?
I do understand that we want a directed graph, but this is ensured by
parent attribute of the element already.  I don't see why a temporary
or even permanent state ala 

element1.GetChildren() == [ element2 element2 element2 ]

would hurt anything in current JDOM code.  We don't really do coloured
graph traversion or anything similar?

So, do we _really need_ the assertion, that a child is only contained
in a parent at most once?


[------------ Stephan Trebels <stephan at ncube.de>, Consultant -----------]
company: nCUBE Deutschland GmbH, Hanauer Str. 56, 80992 Munich, Germany
phone: cell:+49 172 8433111  office:+49 89 149893 0  fax:+49 89 149893 50

More information about the jdom-interest mailing list