GetterUtil.java 887 B

123456789101112131415161718192021222324252627282930
  1. package com.steerinfo.util;
  2. public class GetterUtil {
  3. /**
  4. * Get getter method name by field name
  5. * @param fieldname
  6. * @return
  7. */
  8. public static String toGetter(String fieldname) {
  9. if (fieldname == null || fieldname.length() == 0) {
  10. return null;
  11. }
  12. /* If the second char is upper, make 'get' + field name as getter name. For example, eBlog -> geteBlog */
  13. if (fieldname.length() > 2) {
  14. String second = fieldname.substring(1, 2);
  15. if (second.equals(second.toUpperCase())) {
  16. return new StringBuffer("get").append(fieldname).toString();
  17. }
  18. }
  19. /* Common situation */
  20. fieldname = new StringBuffer("get").append(fieldname.substring(0, 1).toUpperCase())
  21. .append(fieldname.substring(1)).toString();
  22. return fieldname;
  23. }
  24. }