Return-Path: Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 91738 invoked from network); 5 Aug 2003 17:01:43 -0000 Received: from actinium.btinternet.com (194.73.73.66) by daedalus.apache.org with SMTP; 5 Aug 2003 17:01:43 -0000 Received: from fermium ([194.75.226.124]) by actinium.btinternet.com with esmtp (Exim 3.22 #8) id 19k5Bx-00028g-00 for commons-dev@jakarta.apache.org; Tue, 05 Aug 2003 18:01:45 +0100 Received: from 194.164.132.240 by fermium ([194.75.226.124]); Tue, 05 Aug 03 18:01:45 BST Message-ID: <4368762.1060102905841.JavaMail.root@127.0.0.1> Date: Tue, 5 Aug 2003 18:01:45 +0100 (BST) From: scolebourne@btopenworld.com To: commons-dev@jakarta.apache.org Subject: RE: [LANG] Do we have a safeToString() ? Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit X-MAILER: talk21.com WAS v2 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Because it adds extra functionality. String.valueOf(Object obj) does not allow you to choose the value returned in the case of null. Stephen > from: Arun Thomas > date: Tue, 05 Aug 2003 17:47:50 > to: commons-dev@jakarta.apache.org > subject: RE: [LANG] Do we have a safeToString() ? > > If so, WHY? Why not use String.valueOf(Object obj)? > > Not particularly more convenient is it? > > -AMT > > -----Original Message----- > From: scolebourne@btopenworld.com [mailto:scolebourne@btopenworld.com] > Sent: Tuesday, August 05, 2003 9:39 AM > To: commons-dev@jakarta.apache.org; hps@intermeta.de > Subject: Re: [LANG] Do we have a safeToString() ? > > > Nope. > > ObjectUtils.toString(Object obj) > null -> null, else obj.toString() > > ObjectUtils.toString(Object obj,String nullValue) > null -> nullValue, else obj.toString() > > Stephen > > > from: "Henning P. Schmiedehausen" > > scolebourne@btopenworld.com writes: > > >ObjectUtils.toString() > > > > What? This might return org.apache.commons.lang.ObjectUtils@somewhere > > in my memory. > > > > I want to call toString() on arbitrary objects and avoid the NPE when > > I do .toString(). > > > > Regards > > Henning > > > > > > > > >Stephen > > > > >> from: "Henning P. Schmiedehausen" > > >> as I was needing a method like this: > > >> > > >> /** > > >> * Returns the toString() value of the passed > > >> * object. If null is passed, return the String > > >> * "null". > > >> * > > >> * @param obj The object to print out. > > >> * @returns A String representation of the passed > > >> * object. > > >> */ > > >> public String safeToString(Object obj) { > > >> if (obj == null) { > > >> return "null"; > > >> } > > >> return obj.toString(); > > >> } > > >> > > >> for the gadzillionth time and we have > > >> > > >> public static String identityToString(Object object) { > > >> if (object == null) { > > >> return null; > > >> } > > >> return new StringBuffer() > > >> .append(object.getClass().getName()) > > >> .append('@') > > >> .append(Integer.toHexString(System.identityHashCode(object))) > > >> .toString(); > > >> } > > >> > > >> in ObjectUtils, wouldn't this safeToString() be a nice addition to > > >> the ObjectUtils? Or do we already have something like this in the > > >> lang somewhere? > > >> > > >> Regards > > >> Henning > > >> -- > > >> Dipl.-Inf. (Univ.) Henning P. Schmiedehausen INTERMETA GmbH > > >> hps@intermeta.de 49 9131 50 654 0 http://www.intermeta.de/ > > >> > > >> Java, perl, Solaris, Linux, xSP Consulting, Web Services > > >> freelance consultant -- Jakarta Turbine Development -- hero for hire > > >> > > >> "You are being far too rational for this discussion." > > >> --- Scott Robert Ladd in <3F1874B0.6030507@coyotegulch.com> > > >> > > >> ------------------------------------------------------------------- > > >> -- > > >> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org > > >> For additional commands, e-mail: commons-dev-help@jakarta.apache.org > > >> > > > > > > >--------------------------------------------------------------------- > > >To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org > > >For additional commands, e-mail: commons-dev-help@jakarta.apache.org > > > > -- > > Dipl.-Inf. (Univ.) Henning P. Schmiedehausen INTERMETA GmbH > > hps@intermeta.de 49 9131 50 654 0 http://www.intermeta.de/ > > > > Java, perl, Solaris, Linux, xSP Consulting, Web Services > > freelance consultant -- Jakarta Turbine Development -- hero for hire > > > > "You are being far too rational for this discussion." > > --- Scott Robert Ladd in <3F1874B0.6030507@coyotegulch.com> > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org > > For additional commands, e-mail: commons-dev-help@jakarta.apache.org > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org > For additional commands, e-mail: commons-dev-help@jakarta.apache.org > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org > For additional commands, e-mail: commons-dev-help@jakarta.apache.org >