ToStringHelper

Posted by Lucio Benfante Fri, 11 Nov 2005 18:49:00 GMT

One of the traits I personally appreciate most in a good programmer is what I call the “constructive laziness”. It is the attitude to build software solutions for avoiding boring activities.

One of the most frequent and boring activities happening in the writing of a Java class is the implementation of the toString method, especially if the class contains lot of attributes and if it is frequently updated.

Last summer, in a mood of constructive laziness than surely doesn’t make me a good programmer, I wrote a small class library that tries to solve this problem. Using such library you can write a toString method as simple as the following:

public String toString() { ToStringHelper.toString(this); }

Furthermore the ToStringHelper class is configurabile, allowing the choice of various strategies for producing its output, even without the need of recompiling the application. The default configuration builds the output reflecting on the object attributes. You can modify it:

  • at startup, setting the system property com.benfante.utils.string.ToStringHelper.defaultWorker with the name of your worker class. For example, passing to the JVM the parameter -Dcom.benfante.utils.string.ToStringHelper.defaultWorker = com.benfante.utils.string.ObjectToStringWorker, the ToStringHelper class will produce its output like the toString method of the java.lang.Object class. Of course you can write your own worker class, implementing the ToStringWorker interface. Your worker must have a no-parameter constructor.
  • at run-time, calling the ToStringHelper.setWorker(ToStringWorker) static method.

The library is freely usable, released under the Apache License v. 2.0. You can download it from here.

Posted in  | 38 comments

Comments

  1. Avatar symantec news blog said 522 days later:

    I searched a long time for such an great article. Thank you very much. You have to be patient with such material if you’re really interested in extracting some info off.

  2. Avatar nike air force ones said 2000 days later:

    Give thought to the U.S. nike air force ones ultimate intent – defending our national interests by warfare. Just about every member, like the noncombatant, is devoted to that intent.

  3. Avatar how to save your marriage said 2008 days later:

    The ideals which have lighted my way , and time after time have given me new courage to face life cheerfully 19 have been kindness , beauty and truth .

  4. Avatar silver wholesale jewelry said 2019 days later:

    You have to be patient with such material if you’re really interested in extracting some info off.

  5. Avatar barefoot running shoes said 2019 days later:

    Thank you for your good website. if you are looking for cheap but also with great quality shoes, then our http://barefoot-runningshoes.com will be your best choose.

  6. Avatar nike air ofrce ones said 2024 days later:

    In this subsequent release, the nike air force ones renders a clean and placid ambience using the one of the lowest profiled combinations, the medium grey/white. Clearly, the whole upper owns a medium grey leather construction with white hits present on the Swoosh, heel tab, and midsole. Because it really is much more on the neutral side, this colorway tends to be extra versatile in terms of searching for a matching outfit.

  7. Avatar Gucci Outlet said 2027 days later:

    For ages, a fabulous deadly disagreement is actually waged approximately a small number of fearless persons about reckoned and additionally renegade regarding the only team, and therefore the awesome not aware religious muscle mass fast relating to the other sorts of. This is actually fights approximately Knowledge and additionally Values. All the small number of experience become a huge hit to make sure you justification, to make sure you live up too, to make sure you regularions, to make sure you liberation, to noted, and also peace right on this planet. Numerous experience become a huge hit to make sure you bias, to make sure you terror, to make sure you secret, to make sure you captivity, to mystery, and also anguish hereafter. All the small number of experience talked about “Think” Numerous experience talked about “Believe! “

  8. Avatar canister vacuum cleaners said 2029 days later:

    The time of life is short ; to spend that shortness basely, it would be too long .

  9. Avatar Gucci Outlet said 2034 days later:

    You will find when you seem around the globe that all individual little development inside humane experience, each development inside the legal legislation, each stage in the direction of the particular diminution regarding conflict, each stage in the direction of far better therapy with the tinted contests, or perhaps each mitigation regarding slavery, each meaning development in which there is on earth, continues to be persistently in contrast from the arranged places of worship with the planet. My partner and i point out really purposely the Orlando religious beliefs, since arranged inside the places of worship, continues to be whilst still being could be the main foe regarding meaning development on earth.

  10. Avatar Ed Hardy 2011 said 2036 days later:

    Concerning a super easy doctrine: Pack what on earth is clean. Clean what on earth is 100 %. Scrape when them itches. Everyone loves everyday living for the reason that just what exactly extra could there be. I actually continue to obtain day after day very shorter for your opinions I want to assume, many of the strolling I want to bring, many of the courses I want to learn, plus many of the associates I want to find.

  11. Avatar Hancy said 2036 days later:

    Hello Friend,Whichever style of Fashion Shoes you’re looking for, classical, fashionable, lovely or the latest design, you can find your favorite designer shoes in www.dunkpage.com ,several days ago I bought one pair of shoes from there,It’s beautiful and very comfortable!

  12. Avatar Hancy said 2037 days later:

    It’s a lucky day!I get one pair of Nike Dunk women High from http://www.dunkpage.com/ ! It’s have beautiful appearance and very comfortable! Here’s your first look at the first Women’s Nike Dunk High that I have ever seen. I do believe this is the first time Nike has released a Women’s Nike in a high top form.

  13. Avatar Wealth Trigger Review said 2039 days later:

    It is no use doing what you like ; you have got to like what you do .http://www.wealthtriggerreview.org/

  14. Avatar New Air Max 2011 said 2046 days later:

    Tend not to obsess during the past, tend not to aspiration of the future, target mental performance for the found time. Never bypass expressing the globe owes which you existing. The globe owes anyone nothing at all. It turned out below 1st. Every single person is more preferable well when compared with useless, adult men along with moose along with pine bushes, along with they whom recognizes the idea aright will certainly alternatively maintain their lifestyle when compared with damage the idea. Every single gentleman dead. Not every gentleman genuinely existence. Anything have been established, apart from tips on how to are living.

  15. Avatar Tiffany & CO Outlet said 2048 days later:

    You can find billions which feel the particular Messiah provides appear. When this individual would, next it really is sadly the truth in which his / her daring compromise and also dying experienced simply no result in any respect around the extremely difficulty his / her on its way might have been anticipated to deal with, regarding historical past displays, over and above issue, that individuals Christians are already in the same way hazardous, singly and also en lot, since non-Christians.

  16. Avatar Tiffany Sale said 2049 days later:

    We can’t get pregnant of the Lord that benefits as well as punishes their animals, or even includes a may associated with the kind of that we’re mindful within ourself. A person that ought to endure their bodily passing away can also be past my personal understanding, neither will i desire this or else; this kind of thoughts tend to be for that worries or even ridiculous egoism associated with weak spirits.

  17. Avatar Tiffany Sale said 2049 days later:

    We can’t get pregnant of the Lord that benefits as well as punishes their animals, or even includes a may associated with the kind of that we’re mindful within ourself. A person that ought to endure their bodily passing away can also be past my personal understanding, neither will i desire this or else; this kind of thoughts tend to be for that worries or even ridiculous egoism associated with weak spirits.

  18. Avatar New Jordans said 2057 days later:

    The Bible has been interpreted to justify such evil practices as, for example, slavery, the slaughter of prisoners of war, the sadistic murders of women believed to be witches, capital punishment for hundreds of offenses, polygamy, and cruelty to animals. It has been used to encourage belief in the grossest superstition and to discourage the free teaching of scientific truths. We must never forget that both good and evil flow from the Bible. It is therefore not above criticism.

  19. Avatar Nike Zoom Kobe said 2060 days later:

    Now in its fourth year, the fair is using its momentum to connect new artists with wealthy Asian collectors.

  20. Avatar Ed Hardy Outlet said 2065 days later:

    That Type was translated to help you explain this type of satanic habits simply because, just like, captivity, that slaughter in criminals in fight, that sadistic murders in adult females thought to be witches, funding penalty designed for many hundreds of crimes, polygamy, and even rudeness to help you pets or animals. Experts agree it is would once support understanding with the grossest superstition so to decrease that 100 % free schooling in logical facts. Must always remember which will each of those decent and even satanic amount belonging to the Type. Hence, it is not even earlier complaint.

  21. Avatar Cheap Jordan J23 2009 said 2069 days later:

    The particular somebody instructs that girls delivered sin and also dying in to the planet, in which the lady precipitated late the particular contest, in which the lady has been arraigned ahead of the view couch regarding Paradise, experimented with, condemned and also sentenced. Matrimony on her behalf has been to become problem regarding bondage, expectant mothers an interval enduring and also suffering, and also in silence and also subjection, the lady has been to be able to enjoy the particular function of your influenced by guy’s bounty for many the girl substance would like, and also for the details the lady may well need… This can be a Somebody place regarding girl in brief summed upwards.

  22. Avatar Herve Leger Dress said 2081 days later:

    dads ended up being skeptics and also Deists; people mainly expected your high-end administration which has an “unbreachable wall” amongst religious plus think; people sometimes written on the treaty together with the Moslem usa with Tripoli an apparent report this, compared with European union, a “United Suggests will not be, in different sensation, your Melinda usa. inches (So certainly perceived appeared to be a guideline with parting with religious plus think at that time the fact that treaty surpassed Congress which has no issue for this terms, plus Lead designer Sara Adams ok’d them right away, which has no fearfulness not wearing running shoes could jeopardize her politics long run. )

  23. Avatar aroba.rashi@gmail.com said 2085 days later:

    One of the most common and annoying to write a Java class is the implementation of the toString method, especially if the class contains many attributes and if it is updated frequently.

    Business Listings

  24. Avatar http://www.plotw.org said 2085 days later:

    One of the most common and annoying to write a Java class is the implementation of the toString method, especially if the class contains many attributes and if it is updated frequently.

  25. Avatar mouth ulcers remedy said 2096 days later:

    Firstly, I want to thank you for the useful and informative entry. I am so glad that I have found this your post. The information which you have shared for us is really good explained and I will definitely use it in my work. Thanks a lot one more time for the useful and detailed post and I will be waiting for more such great articles like this one from you in the nearest future.

  26. Avatar Jordan Spizike said 2116 days later:

    I want to bring out the secrets of nature and apply them for the happiness of man . I don‘t know of any better service to offer for the short time we are in the world .

  27. Avatar cheap jordans said 2119 days later:

    Fashion publications frequently exhibit commercials for well known vogue and popular. This sort of fashion exhibits are often all those that happen to be held in great metropolitan areas like New york, but not continuously. The one disadvantage to attend a style clearly show awesome is always that they’re extremely popular, for this reason, could have to make reservations or buy your tickets in advance style. Moreover to figuring out about vogue through journals in print, you can also utilize the Word wide web to do similar. If you are searching for famous and popular option to visit demonstrates, the online world is a fantastic useful resource tool to suit your needs. You might want to get internet websites on the internet trend publications, because they typically have material on approaching vogue displays. Also, for everybody who is curious about attending a vogue exhibit held on a usual foundation, like every year, you may want to think about how you can execute a standard world wide web search.

  28. Avatar Air Jordan Spizike said 2120 days later:

    Thank you to let I was fortunate to enjoy such a good blog, specialized, the depth of the sexual expression let me feel the joy of harvest!

  29. Avatar Moncler Jackets UK said 2125 days later:

    These moncler jackets are receiving delightful hues like pink white, black and blue which give prominent get started looking to the way you look. In North Babylon, New york, providing you leave journey purple underlights. However, if for example the new type of designer’s ideas are too one town, beyond the people’s aesthetic standards, was all bizarre fashion show. There seems to be a couple lovely vests, one inch navy, together with the other in wide blue and white horizontally stripes, cut short within the Browne style.

  30. Avatar digital inverter generator said 2148 days later:

    There are some interesting points in time in this article. Good article , thanks and we want more!

  31. Avatar Cheap Air Jordans said 2161 days later:

    It’s the first performance Cheap Air Jordans to ever feature two interchangeable midsoles and allow the consumer to choose their desired cushioning system.

  32. Avatar custom essay said 2270 days later:

    “Constructive laziness” was actually me Dad’s favorite phrase!) He was telling me it every time I wanted to take a break from my work!

  33. Avatar Snapdeal Facebook Page said 2310 days later:

    this is nice and very informative article thanks i am waiting for next update

  34. Avatar Pretty wonderful publish even i may say that complete internet website is wonderful. I preserve knowing new things each and every solitary evening from publish like these. exceptional things! said 2341 days later:

    Pretty wonderful publish even i may say that complete internet website is wonderful. I preserve knowing new things each and every solitary evening from publish like these. exceptional things!

  35. Avatar cheap watches for sale said 2341 days later:

    Pretty wonderful publish even i may say that complete internet website is wonderful.

  36. Avatar skin tag removal said 2376 days later:

    Thanks for the post.Great information

  37. Avatar dreamwatches said 3469 days later:

    wonderful publish

  38. Avatar <a href="http://www.ukrolexwatchesforsale.co.uk">Rolex Replica</a> said 3874 days later:

    You can firstly acquirement the latest replica watches from http://www.ukwatchesreplica.org.uk that are accessible now.

(leave url/email »)

   Comment Markup Help Preview comment