You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Jörg Herbst <el...@web.de> on 2004/12/11 11:56:37 UTC
Re: Iterator problems collections
Hi, as far as I could test the code, I get the results I expected
(calling .iterator gets me
an iterator containing user objects). The problem seems to be when calling
CollectionsUtils.filter(...), I don't know the details of the
CollectionUtils implementation
but the method seems to call some other behaviour than I expect.
My code works fine as long as I direct call my iterator() method
everything is fine,
but using CollectionUtils something gets wrong.
Thx for any ideas
Joerg
> I can't see anything wrong with what you've sent, but I don't have the
> complete code. I suggest you break your task down into parts and check
> whether you really are converting the objects, or whether perhaps you
> are converting them at the wrong time in your logic.
> Stephen
>
> To: <co...@jakarta.apache.org>
> Sent: Friday, December 10, 2004 6:05 PM
> Subject: Iterator problems collections
>
>
>> Hi folks,
>>
>> I've got a problem with the CollecionUtils.filter method and
>> the Iterator wrappers. I've written a custom Collections class
>> which stores a tree data structure (based on DefaultMutableTreenode).
>>
>> I want to hide the implementation (the usage of
>> DefaultMutableTreeNode) and provided an iterator() methods which
>> should return my user objects:
>>
>> /**
>> * Gets an iterator with all user objects
>> */
>> public Iterator iterator() {
>> Iterator it = new EnumerationIterator(
>> root.breadthFirstEnumeration(),this);
>> Iterator tranformedIt =
>> IteratorUtils.transformedIterator(it,
>> new TreeNodeToUserObjectTransformer());
>> return tranformedIt;
>> }
>>
>> /**
>> * Internal Transformer class for converting a TreeNode
>> * to it's user object
>> */
>> private class TreeNodeToUserObjectTransformer implements
>> Transformer {
>> public Object transform(Object o) {
>> DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;
>> return node.getUserObject();
>> }
>> }
>>
>> Now I'm calling CollectionUtils.filter(myCollection,myPredicate)
>> and suspected to get my user objects passed to the removed(Object o)
>> method. But instead of getting the userObjects, I get
>> DefaultMutableTreeNOdes. Can anybody tell me what I'm doing wrong?
>>
>> Thx
>> Joerg
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org