Posted By

m3rol666 on 08/24/11


Tagged

trim dynamic groovy


Versions (?)

Dinamically trim all object's string properties


 / Published in: Groovy
 

I used this because I had a legacy db table that all fields are char. the right spaces were a pita. The rightTrim function can be viewed in my profile

  1. static void trimObjectProperties(GroovyObject o,String wichSide)
  2. {
  3. o.getProperties().each{
  4.  
  5. if(wichSide.equals(RIGHT)) //you can add more trim types
  6. {
  7. if(it.value)
  8. if(it.value.class.equals(String.class))
  9. {
  10. o.setProperty(it.getKey(), rightTrim(it.value)) //call the trim method
  11. }
  12. }
  13. }
  14. }

Report this snippet  

You need to login to post a comment.