//package com.java2s;// Licensed under the Apache License, Version 2.0 (the "License");import java.util.Map;
publicclass Main {
/** Returns a String showing the type and first few elements of a map */publicstatic <A, B> String toString(Map<A, B> map) {if (map == null) {
return"null";
}/*fromwww.java2s.com*/StringBuilder sB = newStringBuilder();
sB.append(map.getClass().getSimpleName());
sB.append("(");
int i = 0;
for (Map.Entry<A, B> item : map.entrySet()) {
if (i > 4) {
sB.append(",...");
break;
} elseif (i > 0) {
sB.append(",");
}
sB.append("Entry(").append(String.valueOf(item.getKey())).append(",");
sB.append(String.valueOf(item.getValue())).append(")");
i++;
}
sB.append(")");
return sB.toString();
}
/** Returns a String showing the type and first few elements of an array */publicstaticString toString(Object[] as) {
if (as == null) {
return"null";
}
StringBuilder sB = newStringBuilder();
sB.append("Array");
if ((as.length > 0) && (as[0] != null)) {
sB.append("<");
sB.append(as[0].getClass().getSimpleName());
sB.append(">");
}
sB.append("(");
int i = 0;
for (Object item : as) {
if (i > 4) {
sB.append(",...");
break;
} elseif (i > 0) {
sB.append(",");
}
sB.append(String.valueOf(item));
i++;
}
sB.append(")");
return sB.toString();
}
}