package edu.grinnell.callaway;

import java.util.HashMap;
import java.util.Vector;

// This needs to be moved to the other class at some point...
public class ToString
{
  // /http://stackoverflow.com/questions/10462819/get-keys-from-hashmap-in-java
  @SuppressWarnings("unchecked")
  public static String toStr(HashMap<String, Object> hash)
  {
    String str = "{";
    for (String key : hash.keySet())
      {
        Object val = hash.get(key);
        str += "\"" + key + "\":";

        if (val == null)
          str += val + ",";
        else if (val.getClass().equals(HashMap.class))
          str += toStr((HashMap<String, Object>) val) + ",";
        else if (val.getClass().equals(String.class))
          str += "\"" + val + "\",";
        else if (val.getClass().equals(Vector.class))
          str += vecToString((Vector<?>) val) + ",";
        else
          str += val + ",";
      } // for (key)
    str = str.substring(0, str.length() - 1) + "}";
    return str;
  } // toStr(HashMap)

  @SuppressWarnings("unchecked")
  public static String vecToString(Vector<?> vec)
  {
    String str = "[";

    for (int i = 0; i < vec.size(); i++)
      {
        Object val = vec.get(i);

        if (val == null)
          str += val + ",";
        else if (val.getClass().equals(Vector.class))
          str += vecToString((Vector<?>) val) + ",";
        else if (val.getClass().equals(HashMap.class))
          str += toStr((HashMap<String, Object>) val) + ",";
        else if (val.getClass().equals(String.class))
          str += "\"" + val + "\",";
        else
          str += val + ",";
      } // for (i)
    str = str.substring(0, str.length() - 1) + "]";
    return str;
  } // vecToString(Vector)

  public static void main(String args[])
  {
    HashMap<String, Object> htable = new HashMap<String, Object>(8);
    
    Vector vector = new Vector(3);
    vector.add(1);
    vector.add(2);

    Vector vector2 = new Vector(3);
    vector2.add(vector);
    vector2.add(2);

    HashMap<String, Object> htab = new HashMap<String, Object>(3);

    htab.put("x", "it");
    htab.put("y", 2.7e-4);

    vector.add(htab);

    htable.put("a", true);
    htable.put("b", 2.7e-4);
    htable.put("c", "The");
    htable.put("j", vector2);
    htable.put("d", vector);
    htable.put("e", null);
    htable.put("f", htab);

    System.out.println(toStr(htable));
  } // main
} // class ToString

@@ -25,16 +25,45 @@
 laway;%0A%0A
+import java.io.Serializable;%0A
 import j
@@ -192,16 +192,363 @@
 tring%0A%7B%0A
+%0A  @SuppressWarnings(%22unchecked%22)%0A  public String toStr(Object obj)%0A  %7B%0A    if (obj.getClass().equals(HashMap.class))%0A      %7B%0A        return objToString((HashMap%3CString, Object%3E) obj);%0A      %7D%0A    else if (obj.getClass().equals(Vector.class))%0A      %7B%0A        return vecToString((Vector%3C?%3E) obj);%0A      %7D%0A    else%0A      return obj.toString();%0A  %7D%0A%0A
   // /ht
@@ -665,27 +665,26 @@
 lic 
-static 
 String 
-t
+objT
 oStr
+ing
 (Has
@@ -710,24 +710,93 @@
 %3E hash)%0A  %7B%0A
+    // HashMap%3CString, Object%3E hash = (HashMap%3CString, Object%3E) obj;%0A
     String s
@@ -1039,37 +1039,43 @@
          str += 
-t
+objT
 oStr
+ing
 ((HashMap%3CString
@@ -1490,23 +1490,16 @@
  public 
-static 
 String v
@@ -1866,21 +1866,27 @@
  str += 
-t
+objT
 oStr
+ing
 ((HashMa
@@ -2277,20 +2277,16 @@
 ct%3E(8);%0A
-    
 %0A    Vec
@@ -2284,24 +2284,38 @@
 %0A%0A    Vector
+%3CSerializable%3E
  vector = ne
@@ -2314,32 +2314,46 @@
 tor = new Vector
+%3CSerializable%3E
 (3);%0A    vector.
@@ -2390,16 +2390,30 @@
   Vector
+%3CSerializable%3E
  vector2
@@ -2425,16 +2425,30 @@
 w Vector
+%3CSerializable%3E
 (3);%0A   
@@ -2828,24 +2828,64 @@
 f%22, htab);%0A%0A
+    ToString str = new ToString();%0A    %0A
     System.o
@@ -2895,22 +2895,35 @@
 println(
+str.
 toStr(
+(Object) 
 htable))

change toStr to take an object (vs HashMap)