public StringableMap(String s) {
    super();
    if (s == null || s.isEmpty()) {
      return;
    }
    String[] parts = s.split(":", 2);
    // read that many chars
    int numElements = Integer.parseInt(parts[0]);
    s = parts[1];
    for (int i = 0; i < numElements; i++) {
      // Get the key String.
      parts = s.split(":", 2);
      int len = Integer.parseInt(parts[0]);
      String key = "";     // Default is now an empty string.

      if (len > 0) key = parts[1].substring(0, len);
        // Please check the toString() method of this class.
        // null has -1 as length and empty String has 0.
      else if (len < 0) {
        key = null;
        len = 0;         // Set 0 to 'len' for null-valued key
        // since only len exists for null-valued key from the given String "s".
      }

      // Get the value String for the key
      parts = parts[1].substring(len).split(":", 2);
      len = Integer.parseInt(parts[0]);
      String value = "";

      if (len > 0) value = parts[1].substring(0, len);
      else if (len < 0) {
        value = null;
        len = 0;        // Set 0 to 'len' since only len exists.
      }

      // Put the entry into the HashMap<String, String>.
      put(key, value);

      // Move to the next substring to process.
      s = parts[1].substring(len);
    }
  }
@Test
    public void stringableMap() throws Exception {
        // Empty map case
        StringableMap m = new StringableMap(new HashMap<String, String>());
        String s = m.toString();
        Assert.assertEquals("0:", s);
        m = new StringableMap(s);
        Assert.assertEquals(0, m.size());

        Map<String, String> base = new HashMap<String, String>();
        base.put("mary", "poppins");
        base.put("bert", null);
        base.put(null, "banks");
        m = new StringableMap(base);
        s = m.toString();
        m = new StringableMap(s);
        Assert.assertEquals(3, m.size());
        Map<String, Boolean> saw = new HashMap<String, Boolean>(3);
        saw.put("mary", false);
        saw.put("bert", false);
        saw.put(null, false);
        for (Map.Entry<String, String> e : m.entrySet()) {
            saw.put(e.getKey(), true);
            if ("mary".equals(e.getKey())) Assert.assertEquals("poppins", e.getValue());
            else if ("bert".equals(e.getKey())) Assert.assertNull(e.getValue());
            else if (null == e.getKey()) Assert.assertEquals("banks", e.getValue());
            else Assert.fail("Unexpected value " + e.getKey());
        }
        Assert.assertEquals(3, saw.size());
        Assert.assertTrue(saw.get("mary"));
        Assert.assertTrue(saw.get("bert"));
        Assert.assertTrue(saw.get(null));
    }