[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gnu.xml.dom.DomText implements Text and NodeList.
From: |
Chris Burdess |
Subject: |
Re: gnu.xml.dom.DomText implements Text and NodeList. |
Date: |
Tue, 10 Jan 2006 08:50:58 +0000 |
User-agent: |
Mutt/1.3.28i |
Pedro Izecksohn wrote:
> >And maybe we can share one instance of the EmptyNodeList
> >for the whole dom tree so if a tree contains lots of empty node list we
> >only allocate one.
>
> I was thinking on this issue.
>
> >The cast in getChildNode() isn't necessary since
> >EmptyNodeList already is a NodeList.
>
> I wrongly typed that.
>
> Add to gnu.xml.dom.DomCharacterData.java:
>
> import org.w3c.dom.NodeList;
>
> /**
> * Returns an EmptyNodeList.
> */
> public NodeList getChildNodes()
> {
> return EmptyNodeList.getInstance();
> }
>
> Add to gnu/xml/dom: EmptyNodeList.java:
>
> package gnu.xml.dom;
>
> import org.w3c.dom.Node;
> import org.w3c.dom.NodeList;
>
> public final class EmptyNodeList implements NodeList
> {
>
> private static EmptyNodeList instance = new EmptyNodeList();
> public static final EmptyNodeList getInstance() {return instance;}
>
> public EmptyNodeList () {}
>
> public final int getLength () {return 0;}
>
> public final Node item (int index) {return null;}
>
> }
I would prefer:
final class EmptyNodeList implements NodeList
{
static final EmptyNodeList instance = new EmptyNodeList();
public final int getLength() {return 0;}
public final Node item(int index) {return null;}
}
That way:
1. you avoid the unnecessary overhead of a method call (getInstance).
2. that which has no need to be public is not public.
--
Chris Burdess
pgp0h41G4fXxV.pgp
Description: PGP signature