[jdom-interest] Optimized Lists

phil at triloggroup.com phil at triloggroup.com
Thu Jan 10 01:19:43 PST 2002


Here I attached 2 list implementation: ContentList (for element content management) & AttributeList (for attribute
management). They automatically take care of the parent/child relationship,preventing errors such as the one currently
in Element.setText().
Moreover, the getContent() & getAttributes() can now directlly and safetly return these lists, preventing the creation
of intermediate FilterList. And, as a side effect of the ArrayList implementation, getting both the count & an indexed
element is very fast => browsing the content of a Element is now faster than ever.

I just uploaded it to get your opinion about that.
The steps to integrate are really simples:

1. change the following methods in Element class:
    private List createContentList() {
        content = new ContentList(this,INITIAL_ARRAY_SIZE);
        return content;
    }
    private List createAttributeList() {
        attributes = new AttributeList(this,INITIAL_ARRAY_SIZE);
        return attributes;
    }

2. Change the global list accessors in Element class
    public List getContent() {
        if( content==null) {
            createContentList()
        }
        return content;
    }
    public List getAttributes() {
        if( attributes==null) {
            createAttributeList()
        }
        return attributes;
    }

3. Change all the parent assignement, in Element, Filter class
Rq: why does the can...() in the Filter classes also do the job of changing the parent? I think these function just have
to check if it is enabled, but no do the actual action.

4. May be optimize some code
For example, the Element.setContent() do not still need to check the datatype, since it is handled by the list itself.

Please, give me your feedback.

Phil.
(See attached file: ContentList.java)(See attached file: AttributeList.java)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ContentList.java
Type: application/octet-stream
Size: 6976 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20020110/807171e4/ContentList.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: AttributeList.java
Type: application/octet-stream
Size: 6103 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20020110/807171e4/AttributeList.obj


More information about the jdom-interest mailing list