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

Stephan Trebels stephan at ncube.de
Wed Sep 18 10:33:41 PDT 2002


I'd rather pass a Comparator, but apart from this it would be a possibility...
I personally would like to understand though, why this is needed, or whether this could be made a property of JDOM ala JDOMFeatures.setFeature(JDOMFeatures.WE_WANT_NO_DUPLICATE_CHILDREN, true);

On Wed, Sep 18, 2002 at 10:45:31AM -0400, Robertson, Jason wrote:
> Without getting into is it right or wrong to do the check, would it be that
> horrible to just turn it off temporarily for sorting since that seems to be
> the one place that it messes things up? Something like this on the Element
> object, perhaps:
> 
> public void sortChildren(Comparator c)
> {
>     content.setExistingParentCheck(false);
>     Collections.sort(getChildren(), c);
>     content.setExistingParentCheck(true);
> }
> 
> Jason
> 
> -----Original Message-----
> From: Stephan Trebels [mailto:stephan at ncube.de]
> Sent: Wednesday, September 18, 2002 2:56 AM
> To: JDOM Interest List
> Subject: [jdom-interest] Collections.sort and multiple parent-child
> relationships
> 
> 
> Hi,
> 
> 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();
> 	Arrays.sort(a);
> 	ListIterator i = list.listIterator();
> 	for (int j=0; j<a.length; j++) {
> 	    i.next();
> 	    i.set(a[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
> 
> -- 
> [------------ 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
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
> t.com
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com

-- 
[------------ 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