[jdom-interest] no getChildTextNormalize() ?

Jason Hunter jhunter at apache.org
Thu Sep 27 13:25:38 PDT 2001


> I'm not sure how these methods are more convenient? Does it save keystrokes? I
> don't think it affects maintenance or readability of the application one way
> or the other. I guess there is a small negative affect on the library source.
> 
> In JBuilder and presumably jEdit, VAJava etc I can type
> 
>     getChild("c").getTextTrim(); in 20 keystrokes, and
> 
>     getChildTextTrim("c"); in 17.
> 
> Using a 5 letter template/abbreviation I can do either in 10, and typing it
> out straight is only 6 chars different.

getChild() may return null in which case your first example would throw
a NullPointerException.  getChildTextTrim() knows enough to not throw an
exception.  A fair comparison is:

  return e.getChildTextTrim("c");

  versus

  Element e = getChild("c");
  if (e != null) {
    return e.getTextTrim();
  }
  else {
    return "";
  }

-jh-



More information about the jdom-interest mailing list