StringUtil { public static String dump(Map<?, ?> map) { if (map == null) { return null; } StringBuilder sb = new StringBuilder(); sb.append(LINE_SEP); sb.append("Map{"); sb.append(LINE_SEP); for (Map.Entry<?, ?> ent : map.entrySet()) { String appendKey = null; if (ent.getKey() == null) { appendKey = "null"; } else { appendKey = ent.getKey().toString(); } sb.append(appendKey); sb.append('='); Object valueObj = ent.getValue(); if (valueObj == null) { sb.append("null"); } else if (valueObj.getClass().isArray()) { sb.append(getArraysStr((Object[]) valueObj)); } else { sb.append(valueObj.toString()); } sb.append(LINE_SEP); } sb.append("}"); return sb.toString(); }  static boolean isWhitespace(char c); static boolean isZenHankakuSpace(char c); static String rtrim(String str); static String ltrim(String str); static String trim(String str); static String rtrimZ(String str); static String ltrimZ(String str); static String trimZ(String str); static String toShortClassName(String longClassName); static String getExtension(String name); static String toHexString(byte[] byteArray, String delim); static String capitalizeInitial(String str); static String[] parseCSV(String csvString); static String[] parseCSV(String csvString, String escapeString); static String dump(Map<?, ?> map); static String getArraysStr(Object[] arrayObj); static String hankakuToZenkaku(String value); static String zenkakuToHankaku(String value); static String filter(String str); static String toLikeCondition(String condition); static int getByteLength(String value, String encoding); static final String LINE_SEP; static final String LIKE_ESC_CHAR; }
@Test public void testDump01() throws Exception { final String num = "1"; final String area = "東京"; Map<String, String> map = new LinkedHashMap<String, String>(); map.put(num, area); String result = StringUtil.dump(map); String str = LINE_SEP + "Map{" + LINE_SEP + "1=東京" + LINE_SEP + "}"; assertEquals(str, result); }
@Test public void testDump02() throws Exception { final String[] num = { "1", "2", "3" }; final String[] area = { "東京", "京都", "兵庫" }; Map<String, String> map = new LinkedHashMap<String, String>(); for (int i = 0; i < num.length; i++) { map.put(num[i], area[i]); } String result = StringUtil.dump(map); String str = LINE_SEP + "Map{" + LINE_SEP + "1=東京" + LINE_SEP + "2=京都" + LINE_SEP + "3=兵庫" + LINE_SEP + "}"; assertEquals(str, result); }
@Test public void testDump03() throws Exception { @SuppressWarnings("rawtypes") Map<?, ?> map = new LinkedHashMap(); String result = StringUtil.dump(map); String str = LINE_SEP+"Map{"+LINE_SEP+"}"; assertEquals(str, result); }
@Test public void testDump04() throws Exception { final String[] num = { "1", "2", "3" }; final String[] area = { "東京", null, "兵庫" }; Map<String, String> map = new LinkedHashMap<String, String>(); for (int i = 0; i < num.length; i++) { map.put(num[i], area[i]); } String result = StringUtil.dump(map); String str = LINE_SEP + "Map{" + LINE_SEP + "1=東京" + LINE_SEP + "2=null" + LINE_SEP + "3=兵庫" + LINE_SEP + "}"; assertEquals(str, result); }
@Test public void testDump05() throws Exception { final String num = null; final String area = "東京"; Map<String, String> map = new LinkedHashMap<String, String>(); map.put(num, area); String result = StringUtil.dump(map); String str = LINE_SEP + "Map{" + LINE_SEP + "null=東京" + LINE_SEP + "}"; assertEquals(str, result); }
@Test public void testDump06() throws Exception { final String num = "1"; final Vector<String> area = new Vector<String>(); area.add(0, "東京"); area.add(1, "大阪"); @SuppressWarnings("rawtypes") Map<String, Vector> map = new LinkedHashMap<String, Vector>(); map.put(num, area); String result = StringUtil.dump(map); assertEquals(LINE_SEP + "Map{" + LINE_SEP + "1=[東京, 大阪]" + LINE_SEP + "}", result); }
@Test public void testDump07() throws Exception { final String num1 = "1"; final String num2 = "2"; Vector<String> area = new Vector<String>(); Vector<String> tel = new Vector<String>(); area.add(0, "東京"); area.add(1, "大阪"); tel.add(0, "03"); tel.add(1, "06"); @SuppressWarnings("rawtypes") Map<String, Vector> map = new LinkedHashMap<String, Vector>(); map.put(num1, area); map.put(num2, tel); String result = StringUtil.dump(map); String str = LINE_SEP + "Map{" + LINE_SEP + "1=[東京, 大阪]" + LINE_SEP + "2=[03, 06]" + LINE_SEP + "}"; assertEquals(str, result); }
@Test public void testDump08() throws Exception { Map<?, ?> map = null; String result = StringUtil.dump(map); assertNull(result); }
@Test public void testDump9() throws Exception { final String num1 = "1"; final String num2 = "2"; Vector<String> area = new Vector<String>(); String tel[] = { "03", "06" }; area.add(0, "東京"); area.add(1, "大阪"); Map<String, Object> map = new LinkedHashMap<String, Object>(); map.put(num1, area); map.put(num2, tel); String result = StringUtil.dump(map); String str = LINE_SEP + "Map{" + LINE_SEP + "1=[東京, 大阪]" + LINE_SEP + "2={03,06}" + LINE_SEP + "}"; assertEquals(str, result); }