[jdom-interest] Another suggestion for the Element class

Mark J Laird Markl at waterford.org
Mon Nov 13 10:58:02 PST 2000

Hi all,

I have a suggestion to make regarding the setText method.  Currently,
there is one method with the following signature:

    public Element setText(String text);

My application retrieves values from a database and then stores them in
XML format.  However, a large percentage of the data values are ints.
This requires me to create the XML as follows:

    int iResult = someDatabaseCall();
    Element someElement = new Element("foo");

Having to use String.valueOf repeatedly can be tedious (although it is
certainly workable).  My recommendation would be to add some convenience
methods to handle conversion of primitive types into Strings:

    public Element setText(int iTextValue);
    public Element setText(long lTextValue);

The method bodies would follow this format:
    public Element setText(int iTextValue) {
        return setText(String.valueOf(iTextValue));

This would allow quick conversion of primitive types without requiring
the programmer to do the String conversions manually every time.


More information about the jdom-interest mailing list