Java Utililty Methods Map Print

List of utility methods to do Map Print

Description

The list of methods to do Map Print are organized into topic(s).

Method

voidprintMap(String mapLabel, Map map)
Debugging support -- Print contents of a map (HashMap, TreeMap, etc.).
if (map == null) {
    System.out.println(mapLabel + " is null.");
} else if (map.size() == 0) {
    System.out.println(mapLabel + " is empty.");
} else {
    System.out.println(mapLabel);
    Iterator iterator = map.keySet().iterator();
    int i = 0;
...
voidprintMapGeneral(Map map)
print Map General
if (map == null || map.size() == 0) {
    System.out.println("**NO ITEM !!");
    return;
int max = 0;
Iterator<String> itr;
itr = map.keySet().iterator();
while (itr.hasNext()) {
...
voidprintMapObject(Map mapobject)
print Map Object
Iterator<?> iter = mapobject.keySet().iterator();
while (iter.hasNext()) {
    Object keyobj = iter.next();
    Object valobj = mapobject.get(keyobj);
    System.out.println(keyobj + ": " + valobj);
StringprintMapStrings(Map> map, String mapDescription)
print Map Strings
StringBuilder sb = new StringBuilder();
if (map == null) {
    return "Map " + mapDescription + " is NULL";
sb.append("\nMAP_SUMMARY of " + mapDescription + " with key count:" + map.size()).append(" :\n[");
for (String key : map.keySet()) {
    sb.append(key).append("\t");
sb.append("]\n");
sb.append("\nMAP_START of " + mapDescription + " with key count:" + map.size()).append("\n");
for (Entry<String, List<String>> entry : map.entrySet()) {
    String key = entry.getKey();
    List<String> list = entry.getValue();
    sb.append("\nLIST_START of " + mapDescription + "[" + key + "] count:" + list.size()).append("\n[\n");
    for (String s : list) {
        sb.append(s).append("\n");
    sb.append("]\nLIST_END: List of " + mapDescription + "[" + key + "] count:" + list.size()).append("\n");
sb.append("MAP_END of " + mapDescription + " with key count:" + map.size()).append("\n");
return sb.toString();
StringprintMapToString(Map map)
print Map To String
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, String> entry : map.entrySet()) {
    sb.append(entry.getKey());
    sb.append("=");
    sb.append(entry.getValue());
    sb.append(";");
return sb.toString();
...
voidprintNERScore(Map scores)
print NER Score
System.out.printf("%4s\t%6s\t%6s\t%6s\n", "NER", "P", "R", "F1");
for (Map.Entry<String, double[]> entry : scores.entrySet()) {
    String type = entry.getKey();
    double[] s = entry.getValue();
    System.out.printf("%4s\t%6.2f\t%6.2f\t%6.2f\n", type, s[0], s[1], s[2]);
StringprintOptions(Map options)
print Options
if (options.isEmpty()) {
    return "";
} else {
    StringBuffer sb = new StringBuffer();
    sb.append('?');
    for (String key : options.keySet()) {
        sb.append(key);
        sb.append("='");
...
voidprintStringMap(Map hsMap, String sDel)
print String Map
int i = 1;
for (Map.Entry<String, String> entry : hsMap.entrySet()) {
    String sKey = entry.getKey();
    String sValue = entry.getValue();
    System.out.println(i + ": " + sKey + "=" + sValue);
    i++;
voidprintTokenStream(CommonTokenStream tokens, Map tokenToName)
print Token Stream
TokenSource source = tokens.getTokenSource();
Token curr;
do {
    curr = source.nextToken();
    System.out.println(curr.getText() + " [" + tokenToName.get(String.valueOf(curr.getType())) + "]");
} while (-1 != curr.getType()); 
voidprintVarTable(HashMap map)
print Var Table
int max = 0;
Iterator<String> itr;
itr = map.keySet().iterator();
while (itr.hasNext()) {
    int x = itr.next().length();
    if (x > max)
        max = x;
max += 3;
itr = map.keySet().iterator();
while (itr.hasNext()) {
    String aKey = itr.next();
    String aVal = map.get(aKey).toString();
    int len = aKey.length();
    int gap = max - len;
    System.out.print("  - " + aKey);
    for (int j = 0; j < gap; j++)
        System.out.print(" ");
    System.out.println(": " + aVal);