[jdom-interest] Simpliyfing Filters

Bradley S. Huffman hip at a.cs.okstate.edu
Fri May 3 08:33:54 PDT 2002


I was thinking about org.jdom.filter.Filter last night and wondering if
the the canAdd() and canRemove() are worth the trouble, or should they
be removed and leave only matches().

For example if you get a List through Element.getContent(filter) you get
a view of the content where only visible nodes are ones that match our filter,
therefore the only nodes you can remove through the List interface are
ones that match our filter.  canRemove() adds a little more control in that
canRemove() must return true for the node to be removed.  Currently in all
filters canRemove() is just a call to matches(), if you can see it, you can
remove it. And honestly I cann't think of a case where one would want
to be able to see a node, but not want to remove it.

Read only nodes? I would think the removel (detaching) checking would be
more appropiate in the node, not the filter.

Currently the filter code restricts (in the List interface) adding only nodes
that match canAdd() in our filter, but do we really care? As long as the node
is legal content for a given situation, isn't that good enough (same logic as
ERH post on setChildren)?

Removing canAdd() and canRemove() would not have any effect on performance.
A live filtered List has rotten performance anyway since there is no way to
determine size() or the index of a node without scanning the list each
time (hence the suggestion to List.listIterator).

Thoughs?

Brad



More information about the jdom-interest mailing list