Return to Snippet

Revision: 19366
at October 22, 2009 09:26 by ff1959


Initial Code
public static <T> Map<String,Object> formatArg(String name,T value)
  {
    if(name == null || value == null)
    {
      throw new IllegalArgumentException("either name " + name + " or value " + value + " was null.");
    }
    Map<String,Object> m = newHashMap();
    m.put(Util.KEY_FORMAT_OBJECT_NAME,name);
    m.put(Util.KEY_FORMAT_OBJECT_VALUE,value);
    return m;
  }

 public static <T> String formatObjectToString(
          Class<T> clss,List<Map<String,Object>> maps)
  {

    StringBuilder buf = new StringBuilder();
    if(clss != null)
    {
      buf.append(clss.getName() + "\n");
      for(Map<String,Object> map:maps)
      {
        String name = (String)map.get(KEY_FORMAT_OBJECT_NAME);
        Object value = map.get(KEY_FORMAT_OBJECT_VALUE);
        String id = name + "(" + value.getClass().getName() + ")";
        buf.append(String.format("%1$-60s %2$s\n",id,value));
      }
    }
    return buf.toString();
  }

Initial URL

                                

Initial Description

                                

Initial Title
A convenient framework for toString()

Initial Tags
java

Initial Language
Java